Greenhorn Posted March 23, 2008 Share Posted March 23, 2008 (edited) Moin, I want to add a ''AutoCloseBraces.lua" to - who'll guess it - autoclose braces/brackets and qoutes. I've added the filename to the filelist in SciTEStartup.lua and copied it into the SciTE\LUA directory. But it doesn't work. Here's the code function OnChar(charAdded) -- trace(charAdded) local toClose = { ['('] = ')', ['{'] = '}', ['['] = ']', ['"'] = '"', ["'"] = "'" } if toClose[charAdded] ~= nil then local pos = editor.CurrentPos editor:ReplaceSel(toClose[charAdded]) editor:SetSel(pos, pos) end return false -- Let next handler to process event -- return true -- Don't let next handler to process event end -- http://osdir.com/ml/lib.scintilla.devel/2005-01/msg00046.html Could anybody give me a tip how to realize this, please ? Greetz Greenhorn Edited March 23, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
Greenhorn Posted March 23, 2008 Author Share Posted March 23, 2008 (edited) OK, I got it working !if somebody else is interested how to get it working, then add the following line to SciTEStartup.luaLoadLuaFile("AutoCloseBraces.lua")Now the SciTEStartup.lua should look like thisexpandcollapse popup-------------------------------------------------------------------------------- -- SciTE startup script. -------------------------------------------------------------------------------- -- A table listing all loaded files. LoadLuaFileList = { } -------------------------------------------------------------------------------- -- LoadLuaFile(file, directory) -- -- Helper function for easily loading Lua files. -- -- Parameters: -- file - The name of a Lua file to load. -- directory - If specified, file is looked for in that directory. By default, -- this directory is $(SciTEDefaultHome)\Lua. -------------------------------------------------------------------------------- function LoadLuaFile(file, directory) if directory == nil then directory = props["SciteDefaultHome"] .. "\\Lua\\" end table.insert(LoadLuaFileList, directory .. file) dofile(directory .. file) end -- LoadLuaFile() -- Load all the Lua files. LoadLuaFile("Class.lua") -- Always load first. LoadLuaFile("Common.lua") -- Always load second. LoadLuaFile("AutoItPixmap.lua") LoadLuaFile("AutoHScroll.lua") LoadLuaFile("AutoItAutoComplete.lua") LoadLuaFile("LoadSession.lua") LoadLuaFile("AutoItIndentFix.lua") LoadLuaFile("EdgeMode.lua") LoadLuaFile("SmartAutoCompleteHide.lua") LoadLuaFile("Tools.lua") LoadLuaFile("AutoItTools.lua") LoadLuaFile("AutoItGotoDefinition.lua") LoadLuaFile("AutoCloseBraces.lua") -- Our Lua file -- Start up the events (Calls onstartup()). EventClass:BeginEvents()At next copy the 'AutoCloseBraces.lua' into SciTE\LUA\AutoCloseBraces = EventClass:new(Common) -------------------------------------------------------------------------------- -- OnChar(charAdded) -- -- AutoComplete Braces and Qoutes. -- -- Parameters: -- charAdded - The character typed. -------------------------------------------------------------------------------- function AutoCloseBraces:OnChar(charAdded) -- trace(charAdded) local toClose = { ['('] = ')', ['{'] = '}', ['['] = ']', ['"'] = '"', ["'"] = "'" } if toClose[charAdded] ~= nil then local pos = editor.CurrentPos editor:ReplaceSel(toClose[charAdded]) editor:SetSel(pos, pos) end return false -- Let next handler to process event -- return true -- Don't let next handler to process event endthat's all, restart SciTE and now {, [, (, ' and " will be automtically closed and the cursor is set between.Have Fun with this nice feature ... GreetzGreenhorn Edited March 23, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2008 Developers Share Posted March 23, 2008 What Happens when I need this?: '"' SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
LIMITER Posted March 23, 2008 Share Posted March 23, 2008 Nice Link to comment Share on other sites More sharing options...
Greenhorn Posted March 23, 2008 Author Share Posted March 23, 2008 What Happens when I need this?: '"'Just type ' at next " and then Entf/Del ... It's quicker than all other variants, however, for me it is. Greetz Greenhorn Link to comment Share on other sites More sharing options...
Developers Jos Posted March 23, 2008 Developers Share Posted March 23, 2008 You could improve that type of behaviour by testing what type the lexer identified and not add the closing character when you are inside a String or Comment for example. This is an example used in the LUA functions: ls = editor.StyleAt[editor.CurrentPos] if ls ~= SCE_AU3_COMMENTBLOCK and ls ~= SCE_AU3_COMMENT and ls ~= SCE_AU3_STRING and ls ~= SCE_AU3_PREPROCESSOR and ls ~= SCE_AU3_SPECIAL then SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Greenhorn Posted March 23, 2008 Author Share Posted March 23, 2008 (edited) You could improve that type of behaviour by testing what type the lexer identified and not add the closing character when you are inside a String or Comment for example. This is an example used in the LUA functions: ls = editor.StyleAt[editor.CurrentPos] if ls ~= SCE_AU3_COMMENTBLOCK and ls ~= SCE_AU3_COMMENT and ls ~= SCE_AU3_STRING and ls ~= SCE_AU3_PREPROCESSOR and ls ~= SCE_AU3_SPECIAL then I'm new to Lua, more precisely I took today the first time a deeper look into Lua and I don't really understand the syntax. Maybe if I have more time I can try to learn Lua ... (C++ is in the moment in my brain and sucks it empty ) [wish] Oooor ... , maybe if you are bored for a while, you could add this to SciTE's menu as an optional feature ... [/wish] Greetz Greenhorn Edited March 23, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
Greenhorn Posted March 23, 2008 Author Share Posted March 23, 2008 This will disable the feature in strings ... -------------------------------------------------------------------------------- -- OnChar(charAdded) -- -- AutoComplete Braces and Qoutes. -- -- Parameters: -- charAdded - The character typed. -------------------------------------------------------------------------------- function AutoCloseBraces:OnChar(charAdded) -- trace(charAdded) local toClose = { ['('] = ')', ['{'] = '}', ['['] = ']', ['"'] = '"', ["'"] = "'" } local ls = editor.StyleAt[editor.CurrentPos] if ls ~= SCE_AU3_STRING then if toClose[charAdded] ~= nil then local pos = editor.CurrentPos editor:ReplaceSel(toClose[charAdded]) editor:SetSel(pos, pos) end end return false -- Let next handler to process event -- return true -- Don't let next handler to process event end Link to comment Share on other sites More sharing options...
zackrspv Posted March 24, 2008 Share Posted March 24, 2008 (edited) I really like this feature; however, maybe a suggestion: While inside of the ", ', (, [, groups, pressing enter would remove you from that. Having to constantly press the 'right' arrow key is quite frustrating. So, when, for example, we are typing like this: GuiCtrlCreateButton("this is a test" If we were to press 'enter' after typing 'test', it should move us right after the ", same applies if it's one of the other groups too, thus allowing quicker code insertion. Thanks Edited March 24, 2008 by zackrspv -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
zackrspv Posted March 24, 2008 Share Posted March 24, 2008 This will disable the feature in strings ... -------------------------------------------------------------------------------- -- OnChar(charAdded) -- -- AutoComplete Braces and Qoutes. -- -- Parameters: -- charAdded - The character typed. -------------------------------------------------------------------------------- function AutoCloseBraces:OnChar(charAdded) -- trace(charAdded) local toClose = { ['('] = ')', ['{'] = '}', ['['] = ']', ['"'] = '"', ["'"] = "'" } local ls = editor.StyleAt[editor.CurrentPos] if ls ~= SCE_AU3_STRING then if toClose[charAdded] ~= nil then local pos = editor.CurrentPos editor:ReplaceSel(toClose[charAdded]) editor:SetSel(pos, pos) end end return false -- Let next handler to process event -- return true -- Don't let next handler to process event end Yours produces an error on startup. -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now