eltorro Posted June 27, 2006 Posted June 27, 2006 Some may find this a useful addition to SciTe Here is a Lua script that inserts a blank function header Place it in SciTEStartup.lua function InsertUDFHeader() editor:AddText([[ ;=============================================================================== ; ; Description: ; Parameter(s): ; ; Requirement: ; Return Value(s): ; User CallTip: ; Author(s): ; Note(s): ;=============================================================================== ]]) end Then add the following to SciTEUser.properties # 45 Insert AutoIt3 Function Header as per UDF guidlines command.name.45.*.au3=Insert UDF Header command.subsystem.45.*au3=3 command.45.*.au3=InsertUDFHeader command.save.before.45.*.au3=2 Restart SciTE The should now be an entry in the Tools menu near the bottom. Enjoy eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Developers Jos Posted June 27, 2006 Developers Posted June 27, 2006 You could also do this through an Abbreviation in stead of LUA. 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.
eltorro Posted June 27, 2006 Author Posted June 27, 2006 I have looked at abbreviations before and didn't remember seeing that. I guess it pays to look at the SciTE help file a little more often. eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Valik Posted June 28, 2006 Posted June 28, 2006 With Lua you can make it read the current line and parse out the function parameters and function name automatically. I have a Lua script which does similar for my own function comments format. I place the caret in a line with the Func keyword and hit a hotkey. A template is created with the correct function name and parameters. As a matter of fact, here is the script: expandcollapse popupfunction InsertFunctionHeader() local line, pos = editor:GetCurLine() local pos = editor.CurrentPos - pos local lineNum = editor:LineFromPosition(pos) -- "()([Ff][Uu][Nn][Cc][%s]*([%w_]*)%(.-%))([^\r\n]*)" -- local from, to, name = string.find(line, "Func ([%w_]*)") local from, to, name = string.find(line, "[Ff][Uu][Nn][Cc][%s]*([%w_]*)") if to ~= nil then -- local pfrom, pto, pname = string.find(line, "(%([%w%s\"_,$%=@-%.]*[%)_])") local pfrom, pto, pname = string.find(line, "(%(.-%))") local i = 0 while string.find(pname, "_%s*$") do -- Found an underscore, so need to get the next line, too i = i + 1 local tmp = editor:GetLine(lineNum+i) local wfrom = string.find(pname, "_%s*$") local nfrom = string.find(tmp, "[^%s]") pname = string.sub(pname, 1, wfrom-1) .. string.sub(tmp, nfrom, -1) pname = string.gsub(pname, "[\n\r]", "") end editor:Home() editor:AddText(_CreateFunctionHeader(name,pname)) else local ws = editor:WordStartPosition(editor.CurrentPos) local we = editor:WordEndPosition(editor.CurrentPos) local word = editor:textrange(ws, we) -- Must strip the new lines for this to work. line = string.gsub(line, "[\n\r]", "") word = string.gsub(word, "[\n\r]", "") if word == "" then editor:AddText(_CreateFunctionHeader("Name", "")) elseif word == line then editor:LineEnd() local lend = editor.CurrentPos editor:Home() local lstart = editor.CurrentPos editor:SetSel(lstart, lend) editor:ReplaceSel(_CreateFunctionHeader(word, "") .. "Func " .. word .. "()\r\nEndFunc; " .. word) end end end -- InsertFunctionheader() And here is the _CreateFunctionHeader() function I use: function _CreateFunctionHeader(s, p) local res = "; " .. string.rep("=", 67) .. "\r\n; " .. s .. p .. "\r\n;\r\n; Description.\r\n; Parameters:" local params = false for byref, parameter, optional in string.gfind(p, "(%w-)%s*($[%w_]+)%s*([=]?)") do if parameter ~= "" and parameter ~= nil then params = true if byref ~= "" and byref ~= nil then res = res .. "\r\n;\t" .. parameter .. " - IN/OUT - " elseif optional ~= "" and optional ~= nil then res = res .. "\r\n;\t" .. parameter .. " - IN/OPTIONAL - " else res = res .. "\r\n;\t" .. parameter .. " - IN - " end end end if params == false then res = res .. "\r\n;\tNone." end res = res .. "\r\n; Returns:\r\n;\tNone.\r\n" .. "; " .. string.rep("=", 67) .. "\r\n" return res end -- _CreateFunctionHeader()
MHz Posted June 28, 2006 Posted June 28, 2006 eltorro said: I have looked at abbreviations before and didn't remember seeing that. I guess it pays to look at the SciTE help file a little more often. eltorroType setupudf and then press the spacebar.
eltorro Posted June 30, 2006 Author Posted June 30, 2006 @Valik, Awsome.@MHz MHz said: Type setupudf and then press the spacebar.I knew that abbreviations(in general) were there, I just hadn't realized the breadth. I have alread added a couple of custom abbreviations. Now, to just get in the habit of using abbreviations. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
eltorro Posted July 6, 2006 Author Posted July 6, 2006 Valik, Thanks for posting your scipts. I modified the CreateFunctionHeader to produce output more inline with the standard UDF headers. I also added a right context menu entry in scite. I am updating some older scripts and the partial autocompletion by using your Lua script has made the task easier. Once Again, Thanks, Steve Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
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