Macro : Load File Under Cursor

42 views
Skip to first unread message

Jose Adriano Baltieri

unread,
Feb 5, 2026, 5:06:02 AMFeb 5
to sem...@googlegroups.com
Hi !

A long time ago I did this simple macro to Load File Under Cursor. The idea is this : whenever you have a file path, you just press <Alt><Enter> (or ^KU) and it loads the file whose name is underneath. Say you are on a source code and there's an # include "std.lib" , or you're on a BATch file and there's a "REN" there, etc etc.. 

It's been so useful to me that I did some improvements recently and also generalized it to deal with URLs.

It's a very simple thing, I mean, I'm not "that" SAL developer. 

That's why I'm publishing it here ! Maybe someone more experienced (Carlo and others) can add suggestions, fixes, etc. 

Enjoy it !


--


Grato,
Jose Adriano Baltieri

LOADFILE_CURSOR.S

Carlo Hogeveen

unread,
Feb 5, 2026, 6:52:54 AMFeb 5
to sem...@googlegroups.com

I suggest changing
Set(WordSet,ChrSet("0-9A-Z_a-z\\/:.*?~-"))
to
Set(WordSet,ChrSet("0-9A-Z_a-z\\/:.*?~\d128-\d255-"))

From a previous post I remember that you had filenames with accented characters.
Allowing all upper 128 characters too would "internationalize" your macro! :-)

Carlo



Jose Adriano Baltieri

unread,
Feb 5, 2026, 7:32:18 AMFeb 5
to sem...@googlegroups.com
HI Carlo ! Thanks 4 for your support !

Actually I do use accented chars but NOT ON FILE NAMES ! That's a bad idea. Although it's perfectly possible, I don't like to use it altogether....

But I'll leave the macro with your new WordSet should someone else use them..

Meanwhile I've inspected my code again and it was pretty "dirty".  

Have uploaded a more organized, latest version.



BTW I'm so happy to be able to code in Sal again .. It's so wonderful when you build those "little toys" (macros) that simplify/automate a lot of our work !

 Also doing lots of AutoHotKey automations... While programming in AHK, I also built this AHK Docs Helper macro in Sal :

image.png

It's been very useful. Of course there are plenty of "fancy" editors out there to work with AHK but I so much prefer Tessie !


--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/semware/000d01dc9695%24f8fa77d0%24eaef6770%24%40ecarlo.nl.
LOADFILE_CURSOR.S

Knud van Eeden

unread,
Feb 5, 2026, 7:52:28 AMFeb 5
to sem...@googlegroups.com
Suggested to add these (because they can be part of (valid) URLs) characters (as illustrated below)

 ()#+&=%

in FRONT of the current wordset
(Note: putting it at the END of that wordset generated an error here for some unknown to me reason)

That extracted all random URLs I tested.

---

PROC Main()
 //
 // https://www.google.com
 //
 // https://www.semware.com
 //
 // c:\temp\ddd.s
 //
 // /mnt/c/temp/ddd.s
 //
 STRING s[255] = Set( WordSet, ChrSet( "()#+&=%0-9A-Z_a-z\\/:.*?~-" ) )
 //
 Warn( GetWord() )
 //
 Set( WordSet, s )
 //
END

---

with friendly greetings
Knud van Eeden

Jose Adriano Baltieri

unread,
Feb 5, 2026, 8:44:43 AMFeb 5
to sem...@googlegroups.com

Knud van Eeden

unread,
Feb 5, 2026, 8:57:22 AMFeb 5
to sem...@googlegroups.com
Suggestion is to remove all the (only) locally installed executables and not installed at the general user, like 

 tcc.exe, 
 winword, 
 7z, 
 ...

Instead using only 'StartPgm()',

This because 'StartPgm()' will automatically and out of the box take care of that and start the Microsoft Windows default associated executables for that file extension (e.g. pdf, xls, xlsx, doc, .zip, ...)

So this would be the new block to replace with:

---
if  found
    fileext=Lower(SplitPath(testname,_EXT_))
    case fileext
        when ".cs", ".c", ".cc", ".cpp", ".h", ".hpp", ".js", ".ts", ".java", ".pl",
                  ".ahk", ".prg", ".ch", ".bat", ".btm", ".py", ".cob", ".rmk", ".lnk",
                  ".csv", ".json", ".xml", ".yaml", ".yml", ".md", ".ps1", ".ini", ".log",
                  ".txt", ".prj" , ".xpj", ".s", ".si", ".inc"
            // autoexec.bat
            EditFile(testname)
         otherwise
            // Message("Uknown Extension : " + testname + " (" + fileext + ").. Starting on Windows anyway..." )
            StartPgm("cmd.exe", "/C START " + testname,"")
    endcase
else
    if  not abandon
        Warn("Sorry but " + filename + fileext + " was not found anywhere...")
    endif
endif

---



--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 9:35:14 AMFeb 5
to sem...@googlegroups.com
Suggested to add e.g. 

".ui", ".pas", ".asm"

(otherwise they will be executed via StartPgm() which should in general not be so, as they should be loaded in TSE).

and optionally (as they could instead by executed instead of loaded):

 ".html", ".htm"

to the list of 'EditFile()' options.

Note: They are part of the Query( DefaultExt ) list of file extensions.

with friendly greetings
Knud van Eeden


if  found
    fileext=Lower(SplitPath(testname,_EXT_))
    case fileext
        when ".cs", ".c", ".cc", ".cpp", ".h", ".hpp", ".js", ".ts", ".java", ".pl",
                  ".ahk", ".prg", ".ch", ".bat", ".btm", ".py", ".cob", ".rmk", ".lnk",
                  ".csv", ".json", ".xml", ".yaml", ".yml", ".md", ".ps1", ".ini", ".log",
                  ".txt", ".prj" , ".xpj", ".s", ".si", ".inc",
                  ".ui", ".pas", ".asm",
                  ".html", ".htm"

            // autoexec.bat
            EditFile(testname)
         otherwise
            // Message("Uknown Extension : " + testname + " (" + fileext + ").. Starting on Windows anyway..." )
            StartPgm("cmd.exe", "/C START " + testname,"")
    endcase
else
    if  not abandon
        Warn("Sorry but " + filename + fileext + " was not found anywhere...")
    endif
endif
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 9:36:21 AMFeb 5
to sem...@googlegroups.com
FYIO:

Space:

Of course this program will not load or execute files with spaces in the filename.

with friendly greetings
Knud van Eeden
On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:

Knud van Eeden

unread,
Feb 5, 2026, 10:07:02 AMFeb 5
to sem...@googlegroups.com
Suggestion: 

Replacing that line

 StartPgm("cmd.exe", "/C START " + testname,"")
by
  StartPgm( testname )

Because otherwise a DOS box running this 'cmd.exe' will be opened, which one has to close manually again.

Not really necessary thus.


---

 if  found
    fileext=Lower(SplitPath(testname,_EXT_))
    case fileext
        when ".cs", ".c", ".cc", ".cpp", ".h", ".hpp", ".js", ".ts", ".java", ".pl",
                  ".ahk", ".prg", ".ch", ".bat", ".btm", ".py", ".cob", ".rmk", ".lnk",
                  ".csv", ".json", ".xml", ".yaml", ".yml", ".md", ".ps1", ".ini", ".log",
                  ".txt", ".prj" , ".xpj", ".s", ".si", ".inc",
                  ".ui", ".pas", ".asm",
                  ".html", ".htm"
            // autoexec.bat
            EditFile(testname)
         otherwise
            // Message("Uknown Extension : " + testname + " (" + fileext + ").. Starting on Windows anyway..." )
            // StartPgm("cmd.exe", "/C START " + testname,"")
            StartPgm( testname )

    endcase
else
    if  not abandon
        Warn("Sorry but " + filename + fileext + " was not found anywhere...")
    endif
endif

---
On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 10:20:14 AMFeb 5
to sem...@googlegroups.com
> you just press <Alt><Enter> (or ^KU) 

^KU was not implemented.



On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 10:24:43 AMFeb 5
to sem...@googlegroups.com
Regarding using Microsoft Windows 'PATH'.

Interesting idea to search in all the path directories in the Microsoft Windows PATH if the file is not found initially.

But as far as I can tell, in the current implementation it searches the PATH, but stops and loads the FIRST FOUND valid file.

But what if there are more than one files with that same filename in the PATH somewhere?

So it would be better to load *ALL* such files found in all paths in the Microsoft Windows PATH.

That will still have to be implemented.

On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:

Jose Adriano Baltieri

unread,
Feb 5, 2026, 10:37:58 AMFeb 5
to sem...@googlegroups.com
Thanks Knud !

Got it. Fixed. 

Also used "COMPSEC" because it gets more "generalized"...




LOADFILE_CURSOR.S

knud van eeden

unread,
Feb 5, 2026, 10:59:11 AMFeb 5
to sem...@googlegroups.com
FYIO:

   StartPgm(GetEnvStr("COMSPEC"),"/C START " + testname,"")

would be a solution, but this 

   StartPgm( testname )

should thus be much more general, simpler
and having the same effect and also it will use the default defined
extensions in Microsoft Windows. So if you change that it will
take care of that outside and independent of TSE and without having to change configurations like COMSPEC
and without having to recompile anything in TSE later.




Jose Adriano Baltieri

unread,
Feb 5, 2026, 1:19:36 PMFeb 5
to sem...@googlegroups.com
Hi Knud !

Got it !

Another good addition would be to have some sort of "mailto" opening as well.

I mean, should I be "on top" of an email address, this macro would open the Mailing program on Windows.

Guess we'll need to use some sort of RegEx then...





LOADFILE_CURSOR.S

Knud van Eeden

unread,
Feb 5, 2026, 2:16:34 PMFeb 5
to sem...@googlegroups.com
In my opinion running this macro to its full intent is loading in theory far too much unrelated files and not meant to be loaded files.

It tests for all these extensions like .txt, .s, .si, ...
and then also in optionally the PATH (with very many directories), and via SearchPath also in the TSE search directories.

I would say that is all not asked for.

The user wants to load an (exact described) file under the cursor, basically that is it.

All those other files are not of interest I would say.

The current TSE macro is more the answer to: "I want to find all files with a same filename and or with a different file extension in about all relevant paths (like PATH, TSEDir(), ...)".

See attached:

So here would be my approach: It must the full path filename searching for and or only the filename+exact file extension, not more than that.

So not search in PATH and also not appending all kinds of file extensions to the filename and searching for that.



On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 4:43:21 PMFeb 5
to sem...@googlegroups.com
Here a simplest version which extracts and runs or loads:
 
 * filename (looks first in current TSE directory, then complete full path else gives up)
 * (all) URLs and runs it in your default browser
 * emails in your email client (implemented in browser for Yahoo, GMail, Microsoft Office, default email client)

See attachment version loadfile_cursor.s version 1.0.0.1



On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 4:48:57 PMFeb 5
to sem...@googlegroups.com
Update:

Here a simplest version which extracts and runs or loads:
 
 * filename (looks first in current TSE directory, then complete full path else gives up)
 * (all) URLs and runs it in your default browser
 * emails in your email client (implemented in browser for Yahoo, GMail, Microsoft Office, default email client)

See attachment version loadfile_cursor.s version 1.0.0.2

On Thu, Feb 5, 2026 at 11:06 AM Jose Adriano Baltieri <jaba...@gmail.com> wrote:
loadfile_cursor.s

Knud van Eeden

unread,
Feb 5, 2026, 8:04:51 PMFeb 5
to sem...@googlegroups.com
Would it be possible to share that AutoHotkey TSE program?

Thanks
with friendly greetings
Knud van Eeden

zhong zhao

unread,
Feb 5, 2026, 8:20:50 PMFeb 5
to SemWare TSE Pro text editor
//My solution:(in ui\tse.ui)

string proc TrimTail(string cf)
    integer i,n,L
    string tt[255]

    tt=cf
    L=Length(cf)
    if cf[1]=='"'
        i=StrFind('"',cf,"i",2) //Find the second occurrence position of " in cf
        if i>0
            tt=SubStr(cf,2,i-2) //The first character is ", and there is another " after it. Ignore the content after the "
        else
            tt=SubStr(cf,2,255) //The first character is ", and there is no " after it. Remove the first "
        endif
    else
        n=StrCount(".",cf)
        if n>0
            i=StrFind('.',cf,"i",n) //Return to the nth occurrence, which is the last occurrence . in cf position
            i=i+1
            while (1)
                if i>L break endif
                if cf[i]=='\' return(tt) endif//When encountering a file name in the format of .1235\……\ followed by a file extension, return the entire cf
                if not isAlpha(cf[i]) and not isDigit(cf[i]) break endif//End the loop until it is no longer a letter or number
                i=i+1
            endwhile
            tt=SubStr(cf,1,i-1)//Return the full path filename from the beginning to the last occurrence of a ".alphanumeric extension"
        endif
    endif
    return(tt)
end

proc mEditfile()
    string cf[255]
    if isBlockMarked()<>0 and isCursorInBlock() and Query(BlockBegLine)==Query(BlockEndLine)//The marker block has only one line
        cf=GetMarkedText()
        if (isAlpha(cf[1]) and cf[2]==':' and cf[3]=='\') or (cf[1]=='"' and isAlpha(cf[2]) and cf[3]==':' and cf[4]=='\')//It is the full path of the file
            if EditFile(cf) return() endif
        endif
    endif
    cf=GetText(1,255) //The current line is the full path of the file
    if (isAlpha(cf[1]) and cf[2]==':' and cf[3]=='\') or (cf[1]=='"' and isAlpha(cf[2]) and cf[3]==':' and cf[4]=='\')
        cf=TrimTail(cf)
        if EditFile(cf) return() endif
    endif
    cf=GetText(CurrPos(),255) //The current cursor position is on or before the drive character
    if (isAlpha(cf[1]) and cf[2]==':' and cf[3]=='\') or (cf[1]=='"' and isAlpha(cf[2]) and cf[3]==':' and cf[4]=='\')
        if isAlpha(cf[1]) and '"'==GetText(CurrPos()-1,1) //The current cursor position is on the drive character and the character to its left is "
            cf=GetText(CurrPos()-1,255)
        endif
        cf=TrimTail(cf)
        if EditFile(cf) return() endif
    endif
    EditFile()
end

<ctrl k><u> mEditfile()

knud van eeden

unread,
Feb 5, 2026, 9:16:41 PMFeb 5
to SemWare TSE Pro text editor
Not sure.

1. I saved this TSE program as 

 loadfile_cursor_zhongzhao.s

2. Then put the cursor on this filename

foobar.txt

3. That file is for sure present in the current TSE working directory

4. Then compile and run the program

5. Result: nothing happens

6. But expected was it will load that file.

7. I then asked Anthropic Claude AI:

8. > Can you describe in a very short explanation what this The Semware Professional Editor TSE SAL program is supposed to do?

9. The AI answer was:

This TSE SAL program provides an enhanced "Edit File" command that intelligently extracts Windows file paths from the current cursor position or marked text and opens them in the editor.

Key features:

  • Detects full Windows paths (like C:\path\file.txt) from three locations:

    1. Marked/selected text (single line)
    2. Current line from beginning
    3. Current cursor position forward
  • Handles paths with or without quotes ("C:\path\file.txt")

  • Uses TrimTail() to clean up paths by removing trailing garbage text after the actual filename extension

  • Falls back to TSE's standard file prompt if no valid path is found

  • Bound to Ctrl+K, U for quick access

Use case: When you see a file path in text (like in compiler errors, logs, or documentation), position your cursor on it and press Ctrl+K, U to instantly open that file, without manually copying/pasting the path.


10. My current conclusion: 

The program loadfile_cursorzhongzhao.s does not behave similar 
to loadfile_cursor.s.

It does not load the simple foobar.txt file example.

11. Remember that this is a VERY SHORT and VERY POWERFUL and very powerful TSE notation to extract succesfully filenames, URLs, 
emails, ...

One does not need regular expressions explicitly, TSE takes care of that internally.


PROC Main()
 //
 // examples: just put your cursor below on that line and word and it will successfully extract all of these. No your regular expressions
 // or your parsers necessary thus.
 //
 // foobar.txt
 // c:\temp\foobar.txt
 //
 Set( WordSet, ChrSet( "@#+&=%0-9A-Z_a-z\\/:.*?~-" ) )
 Warn( GetWord() )
END

Just put your cursor on any of the above example lines (e.g. foobar.txt) and it will successfully extract the involved text.

12. But what your program does I assume at this moment is extracting filenames with spaces in it but between e.g. double quotes "" or single quotes ''. Maybe adding a double quote amd or ' single quote to the ChrSet() above might be an option to consider now. But not sure, that will probably extract too much. We shall see.

with friendly greetings
Knud van Eeden
 

Guy Rouillier

unread,
Feb 6, 2026, 3:04:39 AMFeb 6
to sem...@googlegroups.com
I got a mEditFileAtCursor macro probably 20 years ago, and I have no idea where I got it from.  It works, so I continue to use it.  It has the ChrSet set as this:

ChrSet("A-Za-z0-9_!#$%&`()./\\@{}~:^'-")
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.

Jose Adriano Baltieri

unread,
Feb 6, 2026, 6:26:04 AMFeb 6
to sem...@googlegroups.com
I understand your point. 

I've removed the search across PATH tokens because : 1st) it's not working anyway (empty) ... 2nd) Should I really DO IT, I'd need to cross all possible extensions versus all possible PATH TOKENS. That would be waaaay complex and possibly unnecessary.

I just removed the PATH stuff. However kept adding extensions, should the file name not contain one..

And I agree with that mostly , at least in my case, the file name under cursor is either a full path name or one located on the current folder. Easy to find right away.

For me the macro is concluded !  Should anyone find it useful, it's here !

Let's move on ! 

Thanks again !

LOADFILE_CURSOR.S

knud van eeden

unread,
Feb 6, 2026, 9:49:50 AM (14 days ago) Feb 6
to sem...@googlegroups.com
There were thus some very interesting constructs present in the original source code of loadfile_cursor.s.

Simple: First and for all ChrSet() and GetWord() to extract filenames, URL, email addresses, ...
Very short notation.
I earlier had to use and still use complicated regular expressions and or searching for spaces left and right or begin line and end line to extract the e.g. URL.
This is a very simple solution thus.

SearchPath(): Further the use of TSE SearchPath(), e.g. with the goal to find INCLUDE or IMPORT files somewhere.
This is actually very applicable in computer languages like C, C++, Python, ...), where IMPORT and INCLUDE files or directories are often used and might be hidden along the PATH for example. So how to find those easily.
So this might become a very useful TSE program on its own some time.
In Java similar but there searching along the GetEnvStr( "CLASSPATH" ).

Missing extension: Regarding loading all possible files if the extension is missing. E.g. I have a lot of files starting with 'ddd.' but with different extensions. So many files should be loaded.
Better would it be to enforce that the extension is always included. E.g. by you adding the extension manually.

TSE for Linux: Currently it is still not TSE Linux compatible.
That could be implemented.
I plan to look into it and publish a TSE version, it should be very simple using ChrSet() I guess.

Choosen keys: Further using the keys <Alt Enter> in WSL Linux had side-effects here as it minimized and maximized the TSE window. 

Mouse: Actually in my already used for many years version of a similar functioning program, it uses the simple and quick to use mouse left button click:

1. Clicking with the mouse on any URL in a TSE text opens it automatically in a browser.

2. Clicking on a filename first asks if I want to run it. Then asks if I want to load it. 

I have thus always 2 options and or run and or load. 

For example .html files you might want to AND RUN in a browser AND LOAD into your TSE. Not only OR thus.

3. Clicking on a TSE ExecMacro name asks if I want to jump to the implementation of that TSE macro.

4. Clicking on record links jumps to the record where it is implemented.

So implementing similar to this mouse functionality also.

Mouse: But in the current version TSE for Linux mouse functionality is not really present out of the box.

Space in filename: Also filenames with spaces. Maybe ChrSet() and BeginWordLeft() checking for double or single quote character and similar at the right. But that requires thus explicit single or double quotes around the filename being present in the text.
Or demanding that one manually marks the whole filename first. 












Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

On Fri, Feb 6, 2026 at 12:26, Jose Adriano Baltieri

zhong zhao

unread,
Feb 8, 2026, 8:14:45 PM (11 days ago) Feb 8
to SemWare TSE Pro text editor
My solution above is used only for full path like "D:\foldersname\filename.ext" and cursor at driver letter.

knud van eeden

unread,
Feb 10, 2026, 6:53:07 PM (9 days ago) Feb 10
to sem...@googlegroups.com
Would it be possible to share that AutoHotkey TSE program? 

That would be interesting.

Thanks
with friendly greetings
Knud van Eeden

 Also doing lots of AutoHotKey automations... While programming in AHK, I also built this AHK Docs Helper macro in Sal :

image.png

It's been very useful. Of course there are plenty of "fancy" editors out there to work with AHK but I so much prefer Tessie !


Grato,
Jose Adriano Baltieri

Reply all
Reply to author
Forward
0 new messages