Feature proposal: add logical OR, negation of search result, glob syntax
molsonkiko opened this issue · 1 comments
I propose to add the following syntax to NavigateTo. This would be backwards-compatible with the default search method where every search result must contain all of the space-separated search terms.
Logical OR
Searches can find either or both of the search terms separated by the |
(pipe) character. Thus foo | bar
would match foo.txt
and bar.txt
, where the present syntax does not have a good way to restrict searches to both of those.
Since the |
character is not a legal character in Windows paths, this does not conflict with the matching of paths in any way.
Logical negation
Use the !
character before a search term to NOT match things matching that search term. Thus foo !bar
would match foo.txt
but not foobar.txt
The !
character is legal in Windows paths, so this is not free. However, my proposed glob syntax below would allow the matching of !
in character classes or by using the unicode escape \x21
.
Grouping of character classes
With the added capacity for logical OR and negation, it becomes advantageous to group search terms (e.g., match (foo AND bar) OR baz). This would be achieved using the <
and >
characters to open and close groups. Thus baz | <foo bar
would match foobar.txt
and baz.txt
, but not foo.txt
or bar.txt
.
Note that <
could be used without a matching >
. Forcing the matching of parentheses is an unnecessary formality, and error handling could slow down parsing and make the app less responsive.
I could use (
and )
for this purpose, but those are legal characters in Windows paths, and <
and >
are not, so it is free to use them for that purpose.
glob syntax
As described in this Wikipedia article. The portions of this syntax that I propose to incorporate are all the standard components, the "Unix-like" components, and "globstar" (**
), and alternation (e.g., *.{cpp,h}
matches foo.cpp
and foo.h
)
full example foo**[!c-p]uack*.{tx?,cpp} !fgh | <bar baz
Matches
foo\boo\quacked.txt
foo\boo\quacked.cpp
foozuack.txb
bar.baz
baz.bar
fgh\bar.baz
(fgh
is forbidden if the glob is being matched, but not ifbar baz
is being matched)
Non-matches
foo\boo\duacked.txt
(thed
induacked
is in the character classc-p
, which was negated)foozuack.xml
(thexml
extension does not matchtx?
)foo.baz
(does not match the fancy glob, and it doesn't contain bothbar
andbaz
)foo\boo\quacked.txto
(txto
does not matchtx?
because globs are always anchored at the end andtxto
has ano
after the matching portion)foo\fgh\quacked.txt
(contains the forbidden search termfgh
)foo\boo\quacked\bad.txt
(uack*
matches any characters afteruack
other than\
)
@molsonkiko When you have a minute please update documentation for this new search feature: https://github.com/young-developer/nppNavigateTo/tree/master/documentation