Adding backslash escapes to find.command

46 views
Skip to first unread message

Chris Angelico

unread,
May 9, 2025, 7:21:39 AMMay 9
to scite-interest
I have search-across-files done with this:

find.command=git -C "$(find.directory)" grep -n "$(find.what)" -- "$(find.files)"

This works for everything that doesn't include a double quote. Is there a way to request that find.what be backslash escaped before incorporating it into the command?

ChrisA / Rosuav

scintillaDotOrg

unread,
May 9, 2025, 7:25:40 PMMay 9
to scite-interest

I have search-across-files done with this:

find.command=git -C "$(find.directory)" grep -n "$(find.what)" -- "$(find.files)"

There is a  

This works for everything that doesn't include a double quote. Is there a way to request that find.what be backslash escaped before incorporating it into the command?

While there is a $(escape ...) function, it isn't applied to find.command and it isn't well tested.

This is an area that is platform dependent so it helps to reveal your OS.

Neil

Chris Angelico

unread,
May 9, 2025, 7:30:19 PMMay 9
to scite-interest
On Saturday, 10 May 2025 at 09:25:40 UTC+10 scintillaDotOrg wrote:

This is an area that is platform dependent so it helps to reveal your OS.


I'm on Linux (GTK). It's probably not relevant to this question, but I'm using a patched version of gtk+.

ChrisA

scintillaDotOrg

unread,
May 10, 2025, 9:05:54 PMMay 10
to scite-interest
ChrisA,

While it looks like there is a single form of variable expansion in SciTE, there are actually two with separate implementations: variables that depend on a file name and variables that don't. This is most obvious when there is an explicit wild card before the '=' in the properties file like
command.go.*.vala=./$(FileName)
but it also occurs indirectly when a variable used in a definition is file name dependent. File-name-dependent variables do not process calls like "escape" which are processed for other variables.

For file-name-dependent variables, "props.GetNewExpandString" is commonly called but for other variables, different methods are called like "props.GetExpandedString".

You could try changing the implementation of "find.command" in gtk/SciTEGTK.cxx to allow calling "escape" by switching calls although this may have unexpected consequences. Then set find.command to something like

find.command=git -C "$(find.directory)" grep -n "$(escape find.what)" -- "$(find.files)"

Neil

Chris Angelico

unread,
May 10, 2025, 9:43:25 PMMay 10
to scite-i...@googlegroups.com
On Sun, 11 May 2025 at 11:05, scintillaDotOrg <scintil...@gmail.com> wrote:
>
> ChrisA,
>
> While it looks like there is a single form of variable expansion in SciTE, there are actually two with separate implementations: variables that depend on a file name and variables that don't. This is most obvious when there is an explicit wild card before the '=' in the properties file like
> command.go.*.vala=./$(FileName)
> but it also occurs indirectly when a variable used in a definition is file name dependent. File-name-dependent variables do not process calls like "escape" which are processed for other variables.
>
> For file-name-dependent variables, "props.GetNewExpandString" is commonly called but for other variables, different methods are called like "props.GetExpandedString".
>

Interesting. I'm not sure if the difference matters here, as the part
I'm looking at is the non-file-dependent one, right?

> You could try changing the implementation of "find.command" in gtk/SciTEGTK.cxx to allow calling "escape" by switching calls although this may have unexpected consequences. Then set find.command to something like
>
> find.command=git -C "$(find.directory)" grep -n "$(escape find.what)" -- "$(find.files)"
>

I had a look at this previously; this is SciTEGTK::FindInFilesCmd in
SciTEGTK.cxx. If the find command is blank, a command is constructed
that calls on the SciTE executable in grep mode, and notably, it
appends Slash(props.GetString("find.what"), true) to get the search
string. Is that the same as what $(escape ...) would do?

ChrisA

scintillaDotOrg

unread,
May 11, 2025, 6:54:47 PMMay 11
to scite-interest
ChrisA:

I'm looking at is the non-file-dependent one, right?

No, find.command for GTK is currently implemented with GetNewExpandString. It's likely this was done as it is a command and most commands can be differentiated by file type although find.command does not currently allow a pattern like find.command.*.c.

I had a look at this previously; this is SciTEGTK::FindInFilesCmd in
SciTEGTK.cxx. If the find command is blank, a command is constructed
that calls on the SciTE executable in grep mode, and notably, it
appends Slash(props.GetString("find.what"), true) to get the search
string. Is that the same as what $(escape ...) would do?

Its similar but $(escape ...) uses ShellEscape, not Slash which is more oriented towards making control characters visible and less towards avoiding shell features. A difficulty here is that a different set of escapes is needed based on context, such as the OS; the command language being executed; and whether the value is inside quotes.

Neil

Chris Angelico

unread,
May 11, 2025, 6:59:47 PMMay 11
to scite-i...@googlegroups.com
Ah. Confusing.

To be completely honest, what I *actually* want here is a way to
specify an array of arguments, rather than a shell-like command line.
But that probably wouldn't be easy, so for the moment, I'm happy with
escaping the quotes properly :)

Is there prior art anywhere? A place where user data gets added to a
command, and has to remain as a single argument?

ChrisA

scintillaDotOrg

unread,
May 13, 2025, 2:05:27 AMMay 13
to scite-interest
ChrisA:

Is there prior art anywhere? A place where user data gets added to a
command, and has to remain as a single argument?

The FindInFilesCmd code you found is likely the closest example but it is incorrect as discussed in

Neil
Reply all
Reply to author
Forward
0 new messages