Jump to content

SciTE and my script version


Recommended Posts

Is it possible that SciTE editor will add version number like:

;Version: 1.001

MyFunc()

Func MyFunc()
    MsgBox(0,0,"Hello World!")
EndFunc

and increase that number every time I edit/save the script?

Sometimes I need to compare my backup script file with current version and I want to know how many times it was changed.

Link to comment
Share on other sites

30 minutes ago, maniootek said:

and increase that number every time I edit/save the script?

Sometimes I need to compare my backup script file with current version and I want to know how many times it was changed.

My suggestion is to use a version control system like Git instead of creating a backup file. So you could jump back and forth between your commits (versions) and alway could see the different changes which were made. Then you also can use Git TAGs with proper SemVer versions names.
Only a suggestion to avoid manual version handling.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Developers
Posted (edited)
58 minutes ago, maniootek said:

thank you but I do not compile scripts. I "run" them, any idea?

So what exactly would be the trigger to update the variable? ...  Save is an option, but that will increment the version very fast.
... and the simple way obviously is to write a small script and update the existing variable, similar to autoit3wrapper.au3 and connect that to a Shortcut so SciTE can run that for any script. 
... or write your own LUA function for that in SciTE.

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

Link to comment
Share on other sites

  • Developers
Posted (edited)

So just for the heck of it: the full SciTE4AutoIt3 comes with a PersonalTools.lua in the %localappdata%\AutoIt v3\SciTE, so this is an example LUA function how you could update the version on each save, when it is found in the source file:

-- Update version of line with this format:
-- ;Version: 1.001
-- on each save
function PersonalTools:OnBeforeSave(path)
    if editor.Lexer == SCLEX_AU3 and path ~= "" then
        local spos, epos = editor:findtext('^\\s*;Version:\\s*[\\d\\.]*', SCFIND_REGEXP, 0)
        if spos then
            local dline = editor:textrange(spos, epos)
            local curversion = dline:match('Version:%s*([%d%.]*)')
            newversion = curversion + 0.001
            editor:SetSel(spos, epos)
            editor:ReplaceSel(";Version: " .. string.format("%.3f", newversion))
        end
    end
end

Over to you to modify it to your wishes. :) 

Edited by Jos
fixed path

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

Posted (edited)
16 hours ago, Jos said:

So just for the heck of it: the full SciTE4AutoIt3 comes with a PersonalTools.lua in the %localuserdata%\AutoIt v3\SciTE, so this is an example LUA function how you could update the version on each save, when it is found in the source file:

-- Update version of line with this format:
-- ;Version: 1.001
-- on each save
function PersonalTools:OnBeforeSave(path)
    if editor.Lexer == SCLEX_AU3 and path ~= "" then
        local spos, epos = editor:findtext('^\\s*;Version:\\s*[\\d\\.]*', SCFIND_REGEXP, 0)
        if spos then
            local dline = editor:textrange(spos, epos)
            local curversion = dline:match('Version:%s*([%d%.]*)')
            newversion = curversion + 0.001
            editor:SetSel(spos, epos)
            editor:ReplaceSel(";Version: " .. string.format("%.3f", newversion))
        end
    end
end

Over to you to modify it to your wishes. :) 

thank you @Jos for taking the time to help me, I just love you 😍 It works !

by the way, this is the path to that file in my computer (%localuserdata% seems to be not valid environment variable)

Quote

%localAppData%\AutoIt v3\SciTE\PersonalTools.lua

 

Edited by maniootek
Link to comment
Share on other sites

I have one issue with this feature. Now when I run script from SciTE then my cursor jump to the beginning of the code to change the Version number. Is it possible that cursor stay in the place or jump back?

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/Lua/SciTE%20Pane%20API.htm

My first .lua commands :)

-- Update version of line with this format:
-- ;Version: 1.001
-- on each save
function PersonalTools:OnBeforeSave(path)
    if editor.Lexer == SCLEX_AU3 and path ~= "" then
        local spos, epos = editor:findtext('^\\s*;Version:\\s*[\\d\\.]*', SCFIND_REGEXP, 0)
        if spos then
            local dline = editor:textrange(spos, epos)
            local curversion = dline:match('Version:%s*([%d%.]*)')
            local cpos = editor.CurrentPos -- Sets the position of the caret.
            newversion = curversion + 0.001
            editor:SetSel(spos, epos)
            editor:ReplaceSel(";Version: " .. string.format("%.3f", newversion))
            editor:GotoPos(cpos) -- Set caret to a position and ensure it is visible.
        end
    end
end

 

I know that I know nothing

Link to comment
Share on other sites

  • Developers
2 hours ago, maniootek said:

I have one issue with this feature.

This is not a feature, but rather an example for you to play with. So change the script so it does exactly what you want it to do. 
The documentation about the SciTE LUA functions are in the Helpfle. ;) 

... and as you can see by the last reply: Even somebody that never used LUA scripts before can do it when you put your mind to it and do a little bit of searching!

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

27 minutes ago, Jos said:

This is not a feature, but rather an example for you to play with. So change the script so it does exactly what you want it to do. 
The documentation about the SciTE LUA functions are in the Helpfle. ;) 

... and as you can see by the last reply: Even somebody that never used LUA scripts before can do it when you put your mind to it and do a little bit of searching!

Yes. Now I have speficication and example I can work on.

Anyway, I don't understand the specification fully (even if I translate it to my language). Lua syntax is also something new for me.

Now I tried to fix one more issue with that code. Now my script version is increasing every save and cursor stays in the line I was working on but my code jump as the page is scrolled. I tried to fix it by finding some function which can read the current scroll position and then set that position.

local curscrollpos = editor.XOffset
editor:LineScroll(curscrollpos, 0)

but it does not work

Link to comment
Share on other sites

  • Developers
Posted (edited)

What about this version:

-- Perform before each save
function PersonalTools:OnBeforeSave(path)
    local VersionPrefix = ";Version:"                -- define the prefix for version line. needs to be the first string on a line
    if editor.Lexer == SCLEX_AU3 and path ~= "" then
        -- find version prefix in sourcecode
        local spos, epos = editor:findtext('^\\s*' .. VersionPrefix .. '\\s*[\\d\\.]*', SCFIND_REGEXP, 0)
        -- Update when found
        if spos then
            local dline = editor:textrange(spos, epos) -- get the text found
            local curversion = dline:match(VersionPrefix .. '%s*([%d%.]*)') -- retrive portion containing the number
            local orgpos = editor.CurrentPos           -- save current pos
            local firstvisible = editor.FirstVisibleLine -- save first visible line of script
            olen = epos - spos                         -- calculate length of found version string
            local newversion = VersionPrefix .. string.format(" %.3f", curversion + 0.001)
            nlen = newversion:len()                    -- calculate length of new version string
            editor:SetSel(spos, epos)                  -- Set text to replace
            editor:ReplaceSel(newversion)              -- replace old version string with new
            if epos <= editor.CurrentPos then
                editor:GotoPos(orgpos)                 -- set caret back to saved pos when we were before the xhanged text
            else
                editor:GotoPos(orgpos + nlen - olen)   -- set caret back to saved pos when we were after the changed text
            end
            editor.FirstVisibleLine = firstvisible     -- reset first visible line of script
        end
    end
end

 

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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