Skip to content

Commit fb93656

Browse files
Merge pull request #52 from molsonkiko/glob_syntax_add_docs
Add docs for new glob syntax, fix minor glob bug
2 parents f3c1347 + 9293f7b commit fb93656

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

NppNavigateTo/Glob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public Regex Glob2Regex(string inp)
105105
sb.Append("\\\\");
106106
break;
107107
case '*':
108+
uses_metacharacters = true;
108109
if (is_char_class)
109110
{
110111
sb.Append("\\*"); // "[*]" matches literal * character
@@ -114,7 +115,6 @@ public Regex Glob2Regex(string inp)
114115
break; // since globs are only anchored at the end,
115116
// leading * in globs should not influence the matching behavior.
116117
// For example, the globs "*foo.txt" and "foo.txt" should match the same things.
117-
uses_metacharacters = true;
118118
next_c = Peek(inp);
119119
if (next_c == '*')
120120
{

NppNavigateTo/Tests/GlobTester.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ public static void Test()
6262
("baz.txt", true),
6363
("foo.baz", true),
6464
}),
65-
("foo**[!c-p]uack*.{tx?,cpp} !fgh | <bar baz", new[]
65+
("foo**[!c-p]u\\u0434ck*.{tx?,cpp} !fgh | <ba\\x72 baz", new[]
6666
{
67-
("foo\\boo\\quacked.txt", true),
68-
("foo\\boo\\quacked.cpp", true),
69-
("foozuack.txb", true),
67+
("foo\\boo\\quдcked.txt", true),
68+
("foo\\boo\\quдcked.cpp", true),
69+
("foozuдck.txb", true),
7070
("bar.baz", true),
7171
("baz.bar", true),
7272
("fgh\\bar.baz", true),
73-
("foo\\boo\\duacked.txt", false),
74-
("foo\\boo\\uacked.txt", false),
75-
("foozuack.xml", false),
73+
("foo\\boo\\duдcked.txt", false),
74+
("foo\\boo\\uдcked.txt", false),
75+
("foozuдck.xml", false),
7676
("foo.baz", false),
77-
("foo\\boo\\quacked.txto", false),
78-
("foo\\fgh\\quacked.txt", false),
79-
("foo\\fgh\\quacked.cpp", false),
80-
("foo\\boo\\quacked\\bad.txt", false),
77+
("foo\\boo\\quдcked.txto", false),
78+
("foo\\fgh\\quдcked.txt", false),
79+
("foo\\fgh\\quдcked.cpp", false),
80+
("foo\\boo\\quдcked\\bad.txt", false),
8181
}),
8282
("foo[ !]*.*", new[]
8383
{
@@ -160,6 +160,13 @@ public static void Test()
160160
("aд.txt", false),
161161
("д.md", false),
162162
}),
163+
("**.txt | *.json", new[]
164+
{
165+
("Z:\\foo.json", true),
166+
("c:\\goon\\guk.txt", true),
167+
("foo.jsonl", false),
168+
("c:\\bar.txto", false),
169+
}),
163170
};
164171
var glob = new Glob();
165172
foreach ((string query, var examples) in testcases)

documentation/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,54 @@
1515
Examples:
1616
![NavigateTo_With_Fuzzy](https://github.com/young-developer/nppNavigateTo/blob/master/documentation/Without_fuzzy.png)
1717

18+
### Multi-glob syntax
19+
20+
Multi-glob syntax lets the user search space-separated words or [globs](https://en.wikipedia.org/wiki/Glob_(programming)). __This syntax is case-insensitive.__ The rules are as follows:
21+
22+
1. `foo bar txt` matches anything that contains the words `foo`, `bar`, and `txt`, for example `foobar.txt` *but not `bar.txt` or `foo.bar`*
23+
* __Note that this is the same as the old behavior of NavigateTo before the introduction of glob syntax, so the old search behavior is retained.__
24+
2. `foo | bar` matches anything that contains *`foo` OR `bar`*, for example `foo.txt` and `bar.txt`
25+
3. `foo | <bar baz>` matches *`foo` OR (`bar` AND `baz`)*, like `foo.txt` and `bar.baz` but not `bar.txt`. That is, `<>` are grouping parentheses, although *`<` does not require a closing `>`*.
26+
4. `foo !bar` matches *`foo` AND NOT `bar`*, that is, `!` before a search term represents logical negation. So `foo !bar` matches `foo.txt` but not `foo.bar`
27+
5. `*.foo` uses *glob syntax* and matches anything that has the `.foo` extension.
28+
* __Note that anything using the `*`, `[]`, and `{}` characters is considered a glob, and the end of the glob must match the end of the search target.__
29+
* For example, while `foo` matches `foo.txt` or `txt.foo`, __`*.foo` matches `txt.foo` *but not `foo.txt`*__
30+
6. `*` matches any number of characters (including zero) *other than the path separator `\`.* Thus `r.c*` matches `bar.c` and `gor.cpp` *but not `jir.c\foo.bar`*
31+
7. `?` matches *any one character* other than the path separator `\`. Thus `foo.?` matches `foo.h` and `foo.c` but not `foo.cpzp` or `foo.h\bar.py`
32+
8. `[chars]` matches any one character inside the square brackets. It also matches *character ranges*, specifically `a-z`, `A-Z`, and `0-9` or any subset thereof.
33+
* `*.a[0-2]` matches `foo.a0`, `foo.a1`, and `foo.a1`
34+
* `*.[x-y1][7-8]` matches `foo.x7`, `foo.x8`, `foo.y7`, `foo.y8`, `foo.17`, and `foo.18`
35+
* `big[ _]dog.txt` matches `big dog.txt` and `big_dog.txt`
36+
9. `[!chars]` matches *any one character __not__ inside the square brackets other than `\`.* Just as with `[chars]`, character groups can be negated.
37+
* `*.[!1-2]` matches `foo.a` and `foo.g` and `foo.3` *but not `foo.1` or `foo.2` or `foo.\bar.txt`*
38+
10. `\xNN` matches a unicode character at codepoint `NN`. For example, `\x21` matches the exclamation point `!`.
39+
* `\xNN` escapes can be used in character classes. For example, `[\x61-\x6a]` matches the letters `a-z`.
40+
11. `\uNNNN` matches a unicode character at codepoint `NNNN`
41+
* `\u0021` also matches `!`
42+
* `\u0434` matches the Cyrillic character `д`
43+
* `\uNNNN` escapes can be used in character classes. For example, `[\u03B1-\u03C9]` matches the lower-case Greek letters `α` through `ω`.
44+
12. `*.{foo,bar,baz}` matches `a.foo`, `a.bar`, and `a.baz`. That is, `{OPTION1,OPTION2,...,OPTIONN}` matches each comma-separated option within the `{}`
45+
* You can use multiple `{}` alternations within the same glob. For example, `{foo,bar}.{txt,md}` matches `foo.txt`, `foo.md`, `bar.txt`, and `bar.md`
46+
47+
#### Glob syntax "kitchen sink" example, `foo**[!c-p]u\u0434ck*.{tx?,cpp} !fgh | <ba\x72 baz`
48+
49+
##### Matches
50+
1. `foo\boo\quдcked.txt` (recall that `\u0434` is `д`)
51+
2. `foo\boo\quдcked.cpp`
52+
3. `foozuдck.txb`
53+
4. `bar.baz` (note that `\x72` is `r`)
54+
5. `baz.bar`
55+
6. `fgh\bar.baz` (`fgh` is forbidden if the glob is being matched, but not if `bar baz` is being matched)
56+
57+
##### Non-matches
58+
1. `foo\boo\duдcked.txt` (the `d` in `duдcked` is in the character class `c-p`, which was negated)
59+
2. `foozuдck.xml` (the `xml` extension does not match `tx?`)
60+
3. `foo.baz` (does not match the fancy glob, and it doesn't contain both `bar` and `baz`)
61+
4. `foo\boo\quдcked.txto` (`txto` does not match `tx?` __because globs are always anchored at the end__ and `txto` has an `o` after the matching portion)
62+
7. `foo\fgh\quдcked.txt` (contains the forbidden search term `fgh`)
63+
8. `foo\boo\quдcked\bad.txt` (`uдck*` matches *any characters after* `uдck` *other than `\`*)
64+
65+
1866
### Fuzzy Tabs Search
1967
Fuzzy search is based on: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
2068
Highlight is based on character.

test_results.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Test results for NavigateTo v2.5.4
1+
Test results for NavigateTo v2.6
22
=========================
33
Testing Glob syntax
44
=========================
55

6-
Ran 90 tests and failed 0
6+
Ran 94 tests and failed 0

0 commit comments

Comments
 (0)