Jump to content

Lua Script Shortcuts Setup


Recommended Posts

Hello,

As a new AutoIt Developer, I discovered SciTE and felt a lack of functionalities. So I researched if I could setup some shortcuts and figured that it was possible by using Lua scripts.

I found some resources like SciTe-ru where many tools are available. I also used ChatGPT to make a tool that should move code lines by pressing Ctrl+Shift+Up/Down. For example, here is my AutoIt3\SciTE\lua\moveSelectedLinesUp.lua

function moveSelectedLinesUp()
    editor:BeginUndoAction()
    local line = editor:LineFromPosition(editor.CurrentPos)
    if line > 0 then
        editor:LineTranspose(line - 1)
    end
    editor:EndUndoAction()
end

moveSelectedLinesUp()

I either tried to place those lines in SciTEUser.properties and SciTEGlobal.properties :

command.name.1.*=Move Line Up
command.1.*=dofile("Lua\\moveSelectedLinesUp.lua")
command.subsystem.1.*=1
command.mode.1.*=savebefore:no
command.shortcut.1.*=Ctrl+Shift+Up

command.name.2.*=Move Line Down
command.2.*=dofile("Lua\\moveSelectedLinesDown.lua")
command.subsystem.2.*=1
command.mode.2.*=savebefore:no
command.shortcut.2.*=Ctrl+Shift+Down

I am able to see the new commands in the SciTE "Tool" menu, but when i try to press the shortcut or clicking the option in the Tool menu, it says "File not found" (something like that, I'm translating from French to English).

 

I tried many things, but I can't get this thing to work. For example, I tried to move my scripts to my "Documents" folder, to avoid permission issue. I also tried to simplify the path of my files to avoid path errors, by placing my files in the root SciTE folder, but that did not change anything.

 

I've read a bit on

ext.lua.startup.script=$(SciteDefaultHome)\lua\startup.lua

And figured I don't have this file, but found "SciTEstartup.lua", so I tried to replace this line by :

ext.lua.startup.script=$(SciteDefaultHome)\lua\SciTEStartup.lua

But the file did not execute successfully, showing me errors in logs (so I assumed it was like a SciTE file that executes on SciTE startup ?)
 

I also installed Lua 5.1.4 to ensure no errors due to missing program.

 

I apologize if I am unclear, or if this post isn't in the good place. I searched for many solutions on the web and didn't find my answer so I wanted to ask and I did not see a better place for such a question.

 

Can you help me to set up these scripts ?

Thanks in advance,

Valentin

May the force be with you.

Open AutoIt Documentation within VS Code

Link to comment
Share on other sites

there is a PersonalTools.lua file in
C:\Users\ioa747\AppData\Local\AutoIt v3\SciTE\PersonalTools.lua
take a look inside, and then you can add in SciTEUser.properties like:

# 40 lua MoveSelectedLinesUp func
command.name.40.$(au3)=MoveSelectedLinesUp
command.mode.40.$(au3)=subsystem:lua,savebefore:no
command.shortcut.40.$(au3)=Ctrl+Shift+F
command.40.$(au3)=InvokeTool PersonalTools.MoveSelectedLinesUp

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

56 minutes ago, ioa747 said:

there is a PersonalTools.lua file in
C:\Users\ioa747\AppData\Local\AutoIt v3\SciTE\PersonalTools.lua
take a look inside, and then you can add in SciTEUser.properties like:

# 40 lua MoveSelectedLinesUp func
command.name.40.$(au3)=MoveSelectedLinesUp
command.mode.40.$(au3)=subsystem:lua,savebefore:no
command.shortcut.40.$(au3)=Ctrl+Shift+F
command.40.$(au3)=InvokeTool PersonalTools.MoveSelectedLinesUp

 

Hello ioa747, thanks for your fast answer.

As I did not have a \SciTE\ folder as a simple user on this machine, I made one in C:\Users\myusername\AppData\Local\AutoIt v3\ in which I added the "PersonalTools.lua" file I found in the Admin user AppData. Am I in the right way ? I followed this :

-- ==>LUA example file for personal LUA scripts.
-- ==>Copy this file to your %USERPROFILE% directory

Then, I added this to the file I created before :

function PersonalTools:MoveSelectedLinesUp()
    editor:BeginUndoAction()
    local line = editor:LineFromPosition(editor.CurrentPos)
    if line > 0 then
        editor:LineTranspose(line - 1)
    end
    editor:EndUndoAction()
end

And this to my SciTEUser.properties as you told me :

# 40 lua MoveSelectedLinesUp func
command.name.40.$(au3)=MoveSelectedLinesUp
command.mode.40.$(au3)=subsystem:lua,savebefore:no
command.shortcut.40.$(au3)=Ctrl+Shift+Up
command.40.$(au3)=InvokeTool PersonalTools.MoveSelectedLinesUp

 

The shortcut still isn't working. I even tried to let Ctrl+Shift+F but it does nothing except the "Find" menu that opens.

Did I miss something ?

EDIT :

I just saw this error coming :

Lua: error checking global scope for command 'InvokeTool PersonalTools.MoveSelectedLinesUp'

 

Edited by ValentinM

May the force be with you.

Open AutoIt Documentation within VS Code

Link to comment
Share on other sites

  • Developers
1 hour ago, ValentinM said:

As I did not have a \SciTE\ folder as a simple user on this machine, I made one in C:\Users\myusername\AppData\Local\AutoIt v3\ in which I added the "PersonalTools.lua" file I found in the Admin user AppData. Am I in the right way ?

It sounds to me your installation is not complete when that file is missing. When you install the Full SciTE4AutoIt3 package, it needs to be installed form the account you want to use it with. In case you don't do that, but install it with another account, you could copy the complete "C:\Users\installedusername\AppData\Local\AutoIt v3\" to "C:\Users\myusername\AppData\Local\AutoIt v3\" to get the proper complete set of files required.

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

22 minutes ago, Jos said:

It sounds to me your installation is not complete when that file is missing. When you install the Full SciTE4AutoIt3 package, it needs to be installed form the account you want to use it with. In case you don't do that, but install it with another account, you could copy the complete "C:\Users\installedusername\AppData\Local\AutoIt v3\" to "C:\Users\myusername\AppData\Local\AutoIt v3\" to get the proper complete set of files required.

Hello Jos,

That was the issue. The setup on my computer doesn't allow my account to be admin, so I have to manually connect as Admin when I want to install something.

So I copied "C:\Users\ADMIN_USER\AppData\Local\AutoIt v3\" into "C:\Users\myusername\AppData\Local\AutoIt v3\", made the changes I wanted to add my shortcut and it finally worked like a charm.

 

Thank you Jos for your help, and ioa747 for letting me know about PersonalTools, I didn't know this at all.

 

Have a great day and I hope this post will help people in the future.

EDIT : How can I mark this post as solved ? lol

Edited by ValentinM

May the force be with you.

Open AutoIt Documentation within VS Code

Link to comment
Share on other sites

  • Developers
17 minutes ago, ValentinM said:

How can I mark this post as solved ? lol

That is only possible in the Support forum. :) 

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