Benjamin Fisher a écrit :
I need to be able to open executables and (arbitrary) webpages from
within a lua script in Scite. So far, every approach I take is not
right. I am on Windows XP.
Lua's os.execute shows a big ugly command prompt. Also, giving it "start
http://www.google.com"; makes it crash.

Once upon a time, I believed it would be cool to open a file just by putting the caret on its path and hitting Ctrl+Shift+O.
So I implemented it...
It seems having very little documentation in SciTEDoc.html, so some cool side effects might be unknown by most people, except those reading the SciTEBase::OpenSelected() in SciTEIO.cxx.

Here are an excerpt of the comments, they should highlight these features:

// We are in a properties file and try to open a file without extension,
// we suppose we want to open an imported .properties file
// So we append the correct extension to open the included file.
// Maybe we should check if the filename is preceded by "import"...

// Check if we have a line number (error message or grep result)
// A bit of duplicate work with DecodeMessage, but we don't know
// here the format of the line, so we do guess work.
// Can't do much for space separated line numbers anyway...

// Visual Studio error message: F:\scite\src\SciTEBase.h(312):  bool Exists(
// grep -n line, perhaps gcc too: F:\scite\src\SciTEBase.h:312: bool Exists(

#if PLAT_WIN
if (strncmp(selectedFilename, "http:", 5) == 0 ||
                strncmp(selectedFilename, "https:", 6) == 0 ||
                strncmp(selectedFilename, "ftp:", 4) == 0 ||
                strncmp(selectedFilename, "ftps:", 5) == 0 ||
                strncmp(selectedFilename, "news:";, 5) == 0 ||
                strncmp(selectedFilename, "mailto:";, 7) == 0) {
        SString cmd = selectedFilename;
        AddCommand(cmd, "", jobShell);
        return false;   // Job is done
}
#endif

// Support the ctags format

// Don't load the path of the current file if the selected
// filename is an absolute pathname

// If not there [current directory], look in openpath

In other words:
- if you are in a .properties file and put the caret in the file name after an import directive (eg. import lua), it will open lua.properties. I did that before the list of active properties files was in a menu... - If the file name is followed by a number, after opening the file, we jump to the number. - If you are in a file generated by (Exuberant) Ctags, you can jump to the relevant file/line. - It is smart enough to check if we have an absolute path. If not, it looks in the current directory (I think), and if not found, it uses the openpath property to search the file. The open.suffix property can be used also (historically, the .properties suffix is hard-coded...). - And last but not least, I though cool to be able to load URLs as well (on Windows), hence the bunch of prefix checks.

In other words, just put your caret on the URL and hit Ctrl+Shift+O, it should open in your favorite browser. The function uses some heuristic to get the full path, it might fail on some URLs, eg. with form data (?t=1565&p=54545, etc.). In this case, you can just select the URL manually then hit Ctrl+Shift+O.

HTH.

PS.: Neil, perhaps some of the above could go in the doc?

PPS.: For exes, I can't do much, but you can use a command with this:
"If the text of a command starts with '*' then the Parameters dialog is displayed to prompt for parameters before executing the command."

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --

_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest

Reply via email to