|
8 | 8 | <dict> |
9 | 9 | <key>comment</key> |
10 | 10 | <string> |
11 | | - Indent any unclosed groups - open parens that don't have a corresponding closing paren on the same line. |
12 | | - Unindent any closed groups - close parens that don't have a corresponding opening paren on the same line. |
13 | | - Also apply to the `expect-regexp` meta scope, because otherwise a line like `- match: (?=\))` in a `.sublime-syntax` file would not have these rules applied to it because the `source.regexp` scope (correctly) doesn't cover the newline. |
| 11 | + Indent any unclosed groups |
| 12 | + (open paren that doesn't have a corresponding closing paren on the same line). |
| 13 | +
|
| 14 | + Unindent when a closing paren is the first non-whitespace character on a line. |
| 15 | +
|
| 16 | + Also apply to the `expect-regexp` meta scope, |
| 17 | + because otherwise a line like `- match: (?=\))` in a `.sublime-syntax` file |
| 18 | + would not have these rules applied to it |
| 19 | + because the `source.regexp` scope (correctly) doesn't cover the newline. |
| 20 | +
|
14 | 21 | Parens inside comments (whether YAML or Regex) are ignored. |
15 | 22 | </string> |
16 | 23 | <key>indentParens</key> |
17 | 24 | <false/> |
18 | 25 | <key>increaseIndentPattern</key> |
19 | | - <string><![CDATA[(?x)^ |
| 26 | + <string><![CDATA[(?x) |
| 27 | + # define sub-expressions |
20 | 28 | (?<not_paren> |
21 | | - (?: |
22 | | - [^\\()]++ # anything that isn't a slash or a paren |
23 | | - | \\(?> # this is the "known_char_escape" variable from the syntax definition |
24 | | - [tnrfae] |
25 | | - | [0-7]{3} |
26 | | - | x \h\h |
27 | | - | x \{ \h{1,8} \} |
28 | | - | c \d+ |
29 | | - | C- \d+ |
30 | | - | M- \d+ |
31 | | - | M-\\C- \d+ |
32 | | - ) |
33 | | - | \\. # a single escape character |
| 29 | + [^\\()]++ # anything that isn't a slash or a paren |
| 30 | + | \\(?> # this is the "known_char_escape" variable from the syntax definition |
| 31 | + [tnrfae] |
| 32 | + | [0-7]{3} |
| 33 | + | x \h\h |
| 34 | + | x \{ \h{1,8} \} |
| 35 | + | c \d+ |
| 36 | + | C- \d+ |
| 37 | + | M- \d+ |
| 38 | + | M-\\C- \d+ |
| 39 | + ) |
| 40 | + | \\. # a single escape character |
| 41 | + ){0} |
| 42 | + (?<group> |
| 43 | + \( # an open paren |
| 44 | + ( # followed by either |
| 45 | + \g<not_paren> # ... anything that's not a group-related paren |
| 46 | + | \g<group> # ... or a parens group (recursive) |
34 | 47 | )*+ |
35 | | - ) |
36 | | - (?<balanced_paren>(?: |
37 | | - \( # an open paren |
38 | | - \g<not_paren> # followed by anything that's not a group-related paren |
39 | | - \g<balanced_paren> # followed by any number of nested parens |
40 | | - \g<not_paren> # followed by anything that's not a group-related paren |
41 | | - \) # a closing paren |
42 | | - )*+) |
43 | | - \g<not_paren> # followed by anything that's not a group-related paren |
44 | | - \( # followed by an unbalanced open paren |
| 48 | + \) # a closing paren |
| 49 | + ){0} |
| 50 | + (?<balanced_pattern> |
| 51 | + ( |
| 52 | + \g<not_paren> # anything that's not a group-related paren |
| 53 | + | \g<group> # or a parens group (recursive) |
| 54 | + )*+ |
| 55 | + ){0} |
| 56 | +
|
| 57 | + # now the actual match |
| 58 | + ^ # start at the beginning of the line |
| 59 | + \g<balanced_pattern> # the longest sequence of groups and non-group characters |
| 60 | + \( # followed by an unbalanced open paren |
45 | 61 | ]]></string> |
46 | 62 | <key>decreaseIndentPattern</key> |
47 | | - <string><![CDATA[(?x)^ |
48 | | - (?<not_paren> |
49 | | - (?: |
50 | | - [^\\()]++ # anything that isn't a slash or a paren |
51 | | - | \\(?> # this is the "known_char_escape" variable from the syntax definition |
52 | | - [tnrfae] |
53 | | - | [0-7]{3} |
54 | | - | x \h\h |
55 | | - | x \{ \h{1,8} \} |
56 | | - | c \d+ |
57 | | - | C- \d+ |
58 | | - | M- \d+ |
59 | | - | M-\\C- \d+ |
60 | | - ) |
61 | | - | \\. # a single escape character |
62 | | - )*+ |
63 | | - ) |
64 | | - (?<balanced_paren>(?: |
65 | | - \( # an open paren |
66 | | - \g<not_paren> # followed by anything that's not a group-related paren |
67 | | - \g<balanced_paren> # followed by any number of nested parens |
68 | | - \g<not_paren> # followed by anything that's not a group-related paren |
69 | | - \) # a closing paren |
70 | | - )*+) |
71 | | - \g<not_paren> # followed by anything that's not a group-related paren |
72 | | - \) # followed by an unbalanced close paren |
| 63 | + <string><![CDATA[(?x) |
| 64 | + # decrease indentation (while typing) |
| 65 | + # if a closing paren is the first non-whitespace character on a line |
| 66 | + ^ |
| 67 | + \s* |
| 68 | + \) |
73 | 69 | ]]></string> |
74 | 70 | </dict> |
75 | 71 | </dict> |
|
0 commit comments