The execute-general-script command is ready for testing

27 views
Skip to first unread message

Edward K. Ream

unread,
Jun 1, 2021, 5:59:56 AM6/1/21
to leo-editor
The new code is in the ekr-execute-script branch.

#1715 and PR #1941 describe Leo's new execute-general-script command, which makes it much easier for people to run scripts (including external files) in languages other than python.

The general idea is simple: use subprocess.Popen to run the language processor for a language other than python. However, I have spent about a week handling the details, especially the details of handling clickable links to error messages.

Settings

The  @data exec-script-commands setting associates languages (values of @language) with the command needed to run the external language processor for that language.

The @data exec-script-patterns setting gives the regex required to get file names and line numbers from the error messages given by the language processor. Entries are optional: the command creates clickable links only if a regex is given.

Summary

The execute-general-script command calls an external language processor and creates clickable links from error messages. The details are tricky. In other words,  this command is a crucial missing feature of Leo.

Please test the command, either directly, via <Alt-x>execute-general-script, or indirectly, using the official helper, c.general_script_helper.

This command will be part of Leo 6.4. I'll merge this branch into devel in a few days.

Edward

Edward K. Ream

unread,
Jun 1, 2021, 6:05:10 AM6/1/21
to leo-editor
On Tuesday, June 1, 2021 at 4:59:56 AM UTC-5 Edward K. Ream wrote:

#1715 and PR #1941 describe Leo's new execute-general-script command, which makes it much easier for people to run scripts (including external files) in languages other than python.

At present, there are settings only for python and rust. Using the command for python provides no real benefit over Ctrl-B (execute-script). I used it mainly for testing.

Edward

Edward K. Ream

unread,
Jun 1, 2021, 6:07:05 AM6/1/21
to leo-editor
On Tuesday, June 1, 2021 at 5:05:10 AM UTC-5 Edward K. Ream wrote:

> At present, there are settings only for python and rust.

Please feel free to suggest settings for languages such as  go, typescript/js, java, c-sharp, Haskell, etc.

Edward

tbp1...@gmail.com

unread,
Jun 1, 2021, 10:58:40 AM6/1/21
to leo-editor
By coincidence, I have just been working on a script to run an external file (@file, @clean, etc) using an arbitrary program.  My script launches the executing program against the saved external file.  I'll look at your code later today.  I found three main things to work out:

1. How to specify the external programs.  Python is built into the script.  Otherwise processors are specified in an .ini file in the same directory as the program to be run.  This seems to work well.  It also lets you overrule Python with a different version.  I also put any command line arguments in the .ini file.  This approach let me avoid having to create new directives, specially formatted comments, or special headlines to specify processors and arguments.

2. Passing command line arguments in Windows if they need to be quoted (because of spaces) *and* the processor's path also has spaces.  The problem is there whether you use POpen(), subprocess.run(), or os.system().  That is, the problem occurs for me because I want stdout to go to a new console window instead of Leo's launching console. That takes care of the case when Leo is launched without a console window (so there would be nowhere visible for stdout to go).  You have to run a command something like this:

start cmd.exe /k "c:\Program Files\julia.exe" "arg one"  "arg two"

This fails with a message that c:\Program can't be run.  The remedy is to double the first quote character:

start cmd.exe /k ""c:\Program Files\ruby.exe" "arg one"  "arg two"

This is very obscure!  It took me a long time to get it sorted out. It turns out that quotation mark processing with cmd is not what you would think.  The first one turns off the usual special  processing for quote characters;  the double quote prevents this.

The reason for writing start com.exe is only to get a console window.  If you don't include start, then the cmd.exe will run in your current Leo launching console (if there is one), stdout will appear there, and when your program finishes, you will have to type exit to get back to Leo's launcher.  If you omit both start and cmd.exe, your output will also appear in Leo's launcher.

3. In Linux, launching a new console in such a way that stdout output can be seen turns out to be tricky, and there is no general solution because there are many different systems that use different terminal emulators, each of which uses a different set of command line parameters.  And if you try something like x-terminal-emulator, that can be linked to different programs and you don't a priori know how it will behave.
Reply all
Reply to author
Forward
0 new messages