Jump to content

Recommended Posts

  • Developers
Posted (edited)

I guess what needs to happen is that first all continuationlines are concatenated and then the funcname and variables are retrieved.

Checking to see how to change it.

Jos

Edited by Jos

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.
  :)

  • Replies 299
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Developers
Posted

I see we have all code in the LUA script already coded by Valik and assume it was used to build these new versions.

Anyway, that version seems to work nicely we only need to update the layout of the header.

Jos

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.
  :)

Posted

Has anyone used Snippet Holder (CSnippet)? Because I always get an error stating _GUIImageList_AddIcon:-1

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

  • Developers
Posted

k... need some more time to sort this out because the current code I have in AutoItTools.lua doesn't get the complete Parameters either when they contain an underscore.

e.g.

; #FUNCTION# ====================================================================================================================
; Name ..........: _func1
; Description ...: 
; Syntax ........: _func1( $doesnt , $param2  )
; Parameters ....: $doesnt              - A unknown value.
;                  $param2              - A pointer value.
; Return values .: None
; Author ........: Your Name
; Modified ......: 
; Remarks .......: 
; Related .......: 
; Link ..........: 
; Example .......: No
; ===============================================================================================================================
Func _func1($doesnt_like_underscores_in_param_names _
    , $param2)
    ;
EndFunc

Looks at it more tomorrow...

Jos

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.
  :)

Posted

Jos, this time it compiled without the error however when it asked if I wanted to update the version number, I clicked yes and it didn't change. I tried it again and the same thing.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted

Has anyone used Snippet Holder (CSnippet)? Because I always get an error stating _GUIImageList_AddIcon:-1

The original has been broken for a long time. Get in touch with me tomorrow and I'll send you a copy that I fixed.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted

Will do!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted (edited)

@Jos

Here's my fix for the problem, and I think it actually works! It's for use with Mat's functions, not Valik's. Replace with this:

function MyTools:InsertFunctionHeader()
    local line, pos = editor:GetCurLine()
    local pos = editor.CurrentPos - pos
    local lineNum = editor:LineFromPosition(pos)
    local from, to = line:find("[Ff][Uu][Nn][Cc][%s]*([%w%s_]*)")
    if to ~= nil then
        line = line:gsub("%s*;.*$", "")    -- remove comments
        local pfrom, pto = line:find("%(")    -- check for opening parenthesis
        local i = 0
        if pto ~= nil then
            while line:find("%s+_%s*$") do    -- found a line continuation
                line = line:gsub("%s+_%s*$", "")    -- remove it
                i = i + 1
                local tmp = editor:GetLine(lineNum+i)
                tmp = tmp:gsub("^%s*", "")    -- remove leading white space
                tmp = tmp:gsub("%s*;.*$", "")    -- remove comments
                line = line .. tmp
            end
            editor:Home()
            line = line:gsub("[\r\n]", "")    -- remove line breaks
            print(line)
            editor:AddText(self:CreateFunctionHeader(line))
        else
            print("Argument list not found, unable to insert header.")
        end
    else
        print("Function definition not found, unable to insert header.")
    end
end -- InsertFunctionHeader()
Edited by wraithdu
Posted

I updated the above a bit. I still don't like the regex to catch end-of-line comments though. It will fail and grab too much if you have an optional parameter value that is a string with a ; in it. Other than that, I think it works for all other cases.

Posted

I updated the above a bit. I still don't like the regex to catch end-of-line comments though. It will fail and grab too much if you have an optional parameter value that is a string with a ; in it. Other than that, I think it works for all other cases.

Regex can't really work with that unfortunately ;) I'll have to rewrite some of the functions we used for Au3Int into Lua. Ideally I'd like it to detect Global Const $tag* lines as well. I don't see any reason why not. I'll have to rewrite your line continuation though as struct definitions have lots of ;s in them :huh2:

What I'm using now (still putting it in AutoItTools.lua for the time being):

--------------------------------------------------------------------------------
-- CreateFunctionHeader(s)
--
-- Creates the UDF function header from a function definition line.
--
-- Tool: For use by AutoItTools:InsertUDFHeader.
--------------------------------------------------------------------------------
function AutoItTools:CreateFunctionHeader(s)

    -- Change these <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />
    local defAuthor = "Matt Diesel (Mat)"    -- Initial Author value
    
    local defLineMax = 129                   -- Max length of line. AutoIt standard is 129.
    local defSplit = 21                      -- Default index for '-' after param.

    local nl = self:NewLineInUse()

    local outStart   = "FUNCTION"
    local outName    = ""
    local outDesc    = ""
    local outSyntax  = ""
    local outParams  = ""
    local outReturn  = "None"
    local outAuthor  = defAuthor
    local outModify  = ""
    local outRemarks = ""
    local outRelated = ""
    local outLink    = ""
    local outExample = "No"

    local f,t,name,params = s:find("^%s*[Ff][Uu][Nn][Cc]%s+(.+)%s*(%b())")

    outName = name
    if name:sub(0, 2) == "__" then
        outStart = "INTERNAL_USE_ONLY"
    end

    outSyntax = name .. "("

    local paramSynt = ""
    local iOptionals = 0
    local fBroken = false
    if params ~= "" and params ~= nil then
        for byref, parameter, optional in string.gfind(params, "(%w-)%s*($[%w_]+)%s*([=]?)") do
            if parameter ~= "" and parameter ~= nil then
                if outParams ~= "" then
                    outParams = outParams .. nl .. ";" .. string.rep(" ", 18)
                end

                outParams = outParams .. parameter .. string.rep(" ", defSplit - string.len(parameter)) .. "- "

                if optional ~= "" and optional ~= nil then
                    outParams = outParams .. "[optional] "

                    if paramSynt ~= "" then
                        paramSynt = paramSynt .. "[, "
                    else
                        paramSynt = paramSynt .. "[ "
                    end

                    iOptionals = iOptionals + 1
                else
                    if byref ~= "" and byref ~= nil then
                        outParams = outParams .. "[in/out] "
                    end

                    if paramSynt ~= "" then
                        paramSynt = paramSynt .. ", "
                    end
                end

                if fBroken then
                    if string.len(paramSynt) + string.len(parameter) + iOptionals + 2 + 19 > defLineMax then
                        outSyntax = outSyntax .. paramSynt .. nl .. ";" .. string.rep(" ", 18)
                        paramSynt = ""
                        fBroken = true
                    end
                else
                    if string.len(outSyntax) + string.len(paramSynt) + string.len(parameter) + iOptionals + 2 + 19 > defLineMax then
                        outSyntax = outSyntax .. paramSynt .. nl .. ";" .. string.rep(" ", 18)
                        paramSynt = ""
                        fBroken = true
                    end
                end
                paramSynt = paramSynt .. parameter

                local paramtype = parameter:sub(2, 2)
                local isarray = false
                if paramtype == "a" then
                    paramtype = parameter:sub(3, 3)
                    isarray = true
                end

                local sAdd
                if paramtype == "i" then
                    sAdd = "integer"
                elseif paramtype == "f" then
                    sAdd = "boolean"
                elseif paramtype == "b" then
                    sAdd = "binary"
                elseif paramtype == "n" then
                    sAdd = "floating point number"
                elseif paramtype == "s" then
                    sAdd = "string"
                elseif paramtype == "h" then
                    sAdd = "handle"
                elseif paramtype == "v" then
                    sAdd = "variant"
                elseif paramtype == "p" then
                    sAdd = "pointer"
                elseif paramtype == "t" then
                    sAdd = "dll struct"
                else
                    sAdd = "unknown"
                end

                if isarray then
                    outParams = outParams .. "An array of " .. sAdd .. "s."
                else
                    outParams = outParams .. "A " .. sAdd .. " value."
                end
            end
        end
    else
        outParams = "None"
    end

    outSyntax = outSyntax .. paramSynt .. string.rep("]", iOptionals) .. ")"

    local res = "; #" .. outStart .. "# " .. string.rep("=", defLineMax - 5 - outStart:len()) .. nl
    res = res .. "; Name ..........: " .. outName .. nl
    res = res .. "; Description ...: " .. outDesc .. nl
    res = res .. "; Syntax ........: " .. outSyntax .. nl
    res = res .. "; Parameters ....: " .. outParams .. nl
    res = res .. "; Return values .: " .. outReturn .. nl
    res = res .. "; Author(s) .....: " .. outAuthor .. nl
    res = res .. "; Modified ......: " .. outModify .. nl
    res = res .. "; Remarks .......: " .. outRemarks .. nl
    res = res .. "; Related .......: " .. outRelated .. nl
    res = res .. "; Link ..........: " .. outLink .. nl
    res = res .. "; Example .......: " .. outExample .. nl
    res = res .. "; " .. string.rep("=", defLineMax - 2) .. nl

    return res
end -- CreateFunctionHeader()

--------------------------------------------------------------------------------
-- InsertUDFHeader
--
-- Inserts a UDF header for the line the cursor is currently on.
--
-- Tool: AutoItTools:InsertUDFHeader $(au3) Alt+U Make header
--------------------------------------------------------------------------------
function AutoItTools:InsertUDFHeader()
    local line, pos = editor:GetCurLine()
    local pos = editor.CurrentPos - pos
    local lineNum = editor:LineFromPosition(pos)
    local from, to = line:find("[Ff][Uu][Nn][Cc][%s]*([%w%s_]*)")
    if to ~= nil then
        line = line:gsub("%s*;.*$", "")    -- remove comments
        local pfrom, pto = line:find("%(")    -- check for opening parenthesis
        local i = 0
        if pto ~= nil then
            while line:find("%s+_%s*$") do    -- found a line continuation
                line = line:gsub("%s+_%s*$", "")    -- remove it
                i = i + 1
                local tmp = editor:GetLine(lineNum+i)
                tmp = tmp:gsub("^%s*", "")    -- remove leading white space
                tmp = tmp:gsub("%s*;.*$", "")    -- remove comments
                line = line .. tmp
            end
            editor:Home()
            line = line:gsub("[\r\n]", "")    -- remove line breaks
            editor:AddText(self:CreateFunctionHeader(line))
        else
            print("Argument list not found, unable to insert header.")
        end
    else
        from, to = line:find("[Gg][Ll][Oo][Bb][Aa][Ll]%s+[Cc][Oo][Nn][Ss][Tt]%s+$[Tt][Aa][Gg](%w+)%s*=%s*\"(.+)\"")
        if to ~= nil then
            -- It's a structure
            print("Not implemented: Structures")
        else
            print("Function or struct definition not found, unable to insert header.")
        end
    end
end -- InsertFunctionHeader()
  • Developers
Posted (edited)

I updated the above a bit. I still don't like the regex to catch end-of-line comments though. It will fail and grab too much if you have an optional parameter value that is a string with a ; in it. Other than that, I think it works for all other cases.

Thanks... I have taken this and put that into the existing AutoItTools.lua functions and added some logic to tackle the semicolons in a literal string parameter.

Using the Lexer information, you can test for the Lexertype being a Comment:

-- remove comments file the line
        from, to =  line:find(";")
        while from ~= nil do
            if editor.StyleAt[pos+from] == SCE_AU3_COMMENT then
                line = string.sub (line, 1 , from-1)   -- remove comment
                from = nil                             -- exit loop
            else
                from, to =  line:find(";",from+1)      -- find next ; as this one is not a comment
            end
        end

Tested with these scenario's:

Func _func1($doesnt_like_underscores_in_param_names)
    ;
EndFunc
Func _func2($doesnt_like_underscores_in_param_names, $param2)
    ;
EndFunc
Func _func3($doesnt_like_underscores_in_param_names _
    , $param2)
    ;
EndFunc
Func _func4($doesnt_like_underscores_in_param_names, _
     $param2)
    ;
EndFunc
Func _func5($doesnt_like_underscores_in_param_names, _
     $param2, _
     $param3)
    ;
EndFunc
; **************************************************
;  *** Including comments
; **************************************************
Func _func1a($doesnt_like_underscores_in_param_names)  ; test comment
    ;
EndFunc
Func _func2a($doesnt_like_underscores_in_param_names, $param2) ; test comment
    ;
EndFunc
Func _func3a($doesnt_like_underscores_in_param_names _ ; test comment
    , $param2)                                          ; test comment
    ;
EndFunc
Func _func4a($doesnt_like_underscores_in_param_names, _ ; test comment
     $param2)                                           ; test comment
    ;
EndFunc
Func _func5a($doesnt_like_underscores_in_param_names, _ ; test comment
     $param2, _                                         ; test comment
     $param3)                                           ; test comment
    ;
EndFunc

Func _func6a($doesnt_like_underscores_in_param_names, $a="testje", _ ; test comment
     $param2, _                                         ; test comment
     $param3)                                           ; test comment
    ;
EndFunc

Func _func6a($doesnt_like_underscores_in_param_names, $a="test;je", _ ; test comment ; test
     $param2, _                                         ; test comment
     $param3)                                           ; test comment
    ;
EndFunc

Func _func6a($doesnt_like_underscores_in_param_names, $a="test _ je", _ ; test comment _
     $param2, _                                         ; test comment
     $param3)                                           ; test comment
    ;
EndFunc

Func _funcok($seethisisok)
    ;
EndFunc

See if that also works for you

Edited by Jos

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.
  :)

Posted

That works great Jos :huh2: _func6a is not valid, as you can't have an optional parameter followed by non-optionals... And that messes up the syntax field... But if the code won't even run then you can't blame the header maker for getting it wrong.

Syntax field is now completely as it should be:

--------------------------------------------------------------------------------
-- CreateFunctionHeader(s)
--
-- Creates the UDF function header from a function definition line.
--
-- Tool: For use by AutoItTools:InsertUDFHeader.
--------------------------------------------------------------------------------
function AutoItTools:CreateFunctionHeader(s)

    -- Change these <img src='http://www.autoitscript.com/forum/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />
    local defAuthor = "Matt Diesel (Mat)"    -- Initial Author value

    local defLineMax = 129                   -- Max length of line. AutoIt standard is 129.
    local defSplit = 21                      -- Default index for '-' after param.

    local nl = self:NewLineInUse()

    local outStart   = "FUNCTION"
    local outName    = ""
    local outDesc    = ""
    local outSyntax  = ""
    local outParams  = ""
    local outReturn  = "None"
    local outAuthor  = defAuthor
    local outModify  = ""
    local outRemarks = ""
    local outRelated = ""
    local outLink    = ""
    local outExample = "No"

    local f,t,name,params = s:find("^%s*[Ff][Uu][Nn][Cc]%s+(.+)%s*(%b())")

    outName = name
    if name:sub(0, 2) == "__" then
        outStart = "INTERNAL_USE_ONLY"
    end

    outSyntax = name .. "("

    local paramSynt = ""
    local iOptionals = 0
    local fBroken = false
    if params ~= "" and params ~= nil then
        for byref, parameter, optional in string.gfind(params, "(%w-)%s*($[%w_]+)%s*([=]?)") do
            if parameter ~= "" and parameter ~= nil then
                if outParams ~= "" then
                    outParams = outParams .. nl .. ";" .. string.rep(" ", 18)
                end

                outParams = outParams .. parameter .. string.rep(" ", defSplit - string.len(parameter)) .. "- "

                if optional ~= "" and optional ~= nil then
                    outParams = outParams .. "[optional] "

                    if paramSynt ~= "" then
                        paramSynt = paramSynt .. "[, "
                    else
                        paramSynt = paramSynt .. "["
                    end

                    iOptionals = iOptionals + 1
                else
                    if byref ~= "" and byref ~= nil then
                        outParams = outParams .. "[in/out] "
                    end

                    if paramSynt ~= "" then
                        paramSynt = paramSynt .. ", "
                    end
                end

                if fBroken then
                    if string.len(paramSynt) + string.len(parameter) + iOptionals + 2 + 19 > defLineMax then
                        outSyntax = outSyntax .. paramSynt .. nl .. ";" .. string.rep(" ", 18)
                        paramSynt = ""
                        fBroken = true
                    end
                else
                    if string.len(outSyntax) + string.len(paramSynt) + string.len(parameter) + iOptionals + 2 + 19 > defLineMax then
                        outSyntax = outSyntax .. paramSynt .. nl .. ";" .. string.rep(" ", 18)
                        paramSynt = ""
                        fBroken = true
                    end
                end
                paramSynt = paramSynt .. parameter

                local paramtype = parameter:sub(2, 2)
                local isarray = false
                if paramtype == "a" then
                    paramtype = parameter:sub(3, 3)
                    isarray = true
                end

                local sAdd
                if paramtype == "i" then
                    sAdd = "integer"
                elseif paramtype == "f" then
                    sAdd = "boolean"
                elseif paramtype == "b" then
                    sAdd = "binary"
                elseif paramtype == "n" then
                    sAdd = "floating point number"
                elseif paramtype == "s" then
                    sAdd = "string"
                elseif paramtype == "h" then
                    sAdd = "handle"
                elseif paramtype == "v" then
                    sAdd = "variant"
                elseif paramtype == "p" then
                    sAdd = "pointer"
                elseif paramtype == "t" then
                    sAdd = "dll struct"
                else
                    sAdd = "unknown"
                end

                if isarray then
                    outParams = outParams .. "An array of " .. sAdd .. "s."
                else
                    outParams = outParams .. "A " .. sAdd .. " value."
                end
            end
        end
    else
        outParams = "None"
    end

    outSyntax = outSyntax .. paramSynt .. string.rep("]", iOptionals) .. ")"

    local res = "; #" .. outStart .. "# " .. string.rep("=", defLineMax - 5 - outStart:len()) .. nl
    res = res .. "; Name ..........: " .. outName .. nl
    res = res .. "; Description ...: " .. outDesc .. nl
    res = res .. "; Syntax ........: " .. outSyntax .. nl
    res = res .. "; Parameters ....: " .. outParams .. nl
    res = res .. "; Return values .: " .. outReturn .. nl
    res = res .. "; Author(s) .....: " .. outAuthor .. nl
    res = res .. "; Modified ......: " .. outModify .. nl
    res = res .. "; Remarks .......: " .. outRemarks .. nl
    res = res .. "; Related .......: " .. outRelated .. nl
    res = res .. "; Link ..........: " .. outLink .. nl
    res = res .. "; Example .......: " .. outExample .. nl
    res = res .. "; " .. string.rep("=", defLineMax - 2) .. nl

    return res
end -- CreateFunctionHeader()

--------------------------------------------------------------------------------
-- InsertUDFHeader
--
-- Inserts a UDF header for the line the cursor is currently on.
--
-- Tool: AutoItTools:InsertUDFHeader $(au3) Alt+U Make header
--------------------------------------------------------------------------------
function AutoItTools:InsertUDFHeader()
    local line, pos = editor:GetCurLine()
    local pos = editor.CurrentPos - pos
    local lineNum = editor:LineFromPosition(pos)
    local from, to = line:find("[Ff][Uu][Nn][Cc][%s]*([%w%s_]*)")
    if to ~= nil then
        -- remove comments
        from, to =  line:find(";")
        while from ~= nil do
            if editor.StyleAt[pos+from] == SCE_AU3_COMMENT then
                line = string.sub (line, 1 , from-1)   -- remove comment
                from = nil                             -- exit loop
            else
                from, to =  line:find(";",from+1)      -- find next ; as this one is not a comment
            end
        end

        local pfrom, pto = line:find("%(")    -- check for opening parenthesis
        local i = 0
        if pto ~= nil then
            while line:find("%s+_%s*$") do    -- found a line continuation
                line = line:gsub("%s+_%s*$", "")    -- remove it
                i = i + 1
                local tmp = editor:GetLine(lineNum+i)
                tmp = tmp:gsub("^%s*", "")    -- remove leading white space
                tmp = tmp:gsub("%s*;.*$", "")    -- remove comments
                line = line .. tmp
            end
            editor:Home()
            line = line:gsub("[\r\n]", "")    -- remove line breaks
            editor:AddText(self:CreateFunctionHeader(line))
        else
            print("Argument list not found, unable to insert header.")
        end
    else
        from, to = line:find("[Gg][Ll][Oo][Bb][Aa][Ll]%s+[Cc][Oo][Nn][Ss][Tt]%s+$[Tt][Aa][Gg](%w+)%s*=%s*\"(.+)\"")
        if to ~= nil then
            -- It's a structure
            print("Not implemented: Structures")
        else
            print("Function or struct definition not found, unable to insert header.")
        end
    end
end -- InsertFunctionHeader()

Thanks Wraithdu and Jos, I'll update my page now (although I think I will be moving it to the AutoIt wiki).

Posted

@Mat,

Lets update the LUA func in the au3tools.lua and only maintain one version ... agree?

I will take care of the distribution.

Thanks,

Jos :huh2:

I agree completely. That saves me a fair bit of effort (I have done some work on implementing an installer using wraithdu's idea for distributing).
  • Developers
Posted (edited)

Ok, so I have updated AutoItTools.lua with a few changes you made in the header layout.

The approach will be to put the author used in the header in SciTEuser.properties (this default is put into au3.properties) to avoid people having to change LUA files:

# *** Specify here the name you want to use of the UDF header creator  ***
UDFCreator=Your Name

I changed the shortcut back to what valik used already in his version: Ctrl+Alt+H.

The updated files can be found here: au3.properties , AutoItTools.lua

What is left that requires you building an installer for?

Jos

Edited by Jos

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.
  :)

Posted (edited)

@Jos

Nice trick using the lexer. I think you still have to update the comment detection / removal in the second loop in the function, the one that concats the line continuations. It's still using my old code.

Edited by wraithdu
Posted (edited)

Here's my go at it... turned out to be a bit more complex since I had to figure out how to get the new line position... one line, but a lot of Googling!

function AutoItTools:InsertFunctionHeader()
    local line, pos = editor:GetCurLine()
    local pos = editor.CurrentPos - pos
    local lineNum = editor:LineFromPosition(pos)
    local from, to, name = line:find("[Ff][Uu][Nn][Cc][%s]*([%w%s_]*)")
    if to ~= nil then
        -- remove comments from the line
        from, to =  line:find(";")
        while from ~= nil do
            -- print(pos+from .. " type:" .. editor.StyleAt[pos+from])
            if editor.StyleAt[pos+from] == SCE_AU3_COMMENT then
                line = string.sub (line, 1 , from-1)   -- remove comment
                from = nil                             -- exit loop
            else
                from, to =  line:find(";",from+1)      -- find next ; as this one is not a comment
            end
        end
        -- print(" line:" .. line)
        local pfrom, pto = line:find("%(")    -- check for opening parenthesis
        if pto ~= nil then
            local i = 0
            local tmp
            while line:find("%s+_%s*$") do    -- found a line continuation
                line = line:gsub("%s+_%s*$", "")    -- remove it
                i = i + 1
                pos = editor:PositionFromLine(lineNum+i)    -- set new position
                tmp = editor:GetLine(lineNum+i)
                -- remove comments from the line
                from, to =  tmp:find(";")
                while from ~= nil do
                    -- print(pos+from .. " type:" .. editor.StyleAt[pos+from])
                    if editor.StyleAt[pos+from] == SCE_AU3_COMMENT then
                        tmp = string.sub (tmp, 1 , from-1)   -- remove comment
                        from = nil                             -- exit loop
                    else
                        from, to =  tmp:find(";",from+1)      -- find next ; as this one is not a comment
                    end
                end
                tmp = tmp:gsub("^%s*", "")    -- remove leading white space
                line = line .. tmp
            end
            editor:Home()
            line = line:gsub("[\r\n]", "")    -- remove line breaks
            editor:AddText(self:CreateFunctionHeader(name,line))
        else
            print("Argument list not found, unable to insert header.")
        end
    else
        print("Function definition not found, unable to insert header.")
    end
end -- InsertFunctionHeader()
Edited by wraithdu
Posted

@Mat

I also think you should try to include any optional parameter values in the header creation. It doesn't do that currently.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...