young-developer/nppNavigateTo

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

  1. foo\boo\quacked.txt
  2. foo\boo\quacked.cpp
  3. foozuack.txb
  4. bar.baz
  5. baz.bar
  6. fgh\bar.baz (fgh is forbidden if the glob is being matched, but not if bar baz is being matched)

Non-matches

  1. foo\boo\duacked.txt (the d in duacked is in the character class c-p, which was negated)
  2. foozuack.xml (the xml extension does not match tx?)
  3. foo.baz (does not match the fancy glob, and it doesn't contain both bar and baz)
  4. foo\boo\quacked.txto (txto does not match tx? because globs are always anchored at the end and txto has an o after the matching portion)
  5. foo\fgh\quacked.txt (contains the forbidden search term fgh)
  6. foo\boo\quacked\bad.txt (uack* matches any characters after uack 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