Skip to content

Commit 4cce8fb

Browse files
[Diff] Configure extensible BOL whitespace (#12)
1 parent 3a03a92 commit 4cce8fb

7 files changed

+138
-126
lines changed

Diff for: Diff/Diff (Basic).sublime-syntax

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ contexts:
1818

1919
diff-header:
2020
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Unified
21-
- match: ^(-{3})[ ](?!$)
21+
- match: '{{bol}}(-{3})[ ](?!$)'
2222
captures:
2323
1: punctuation.definition.from-file.diff
2424
push: diff-header-unified-from-file
25-
- match: ^(\+{3})[ ](?!$)
25+
- match: '{{bol}}(\+{3})[ ](?!$)'
2626
captures:
2727
1: punctuation.definition.to-file.diff
2828
push: diff-header-unified-to-file
@@ -52,7 +52,7 @@ contexts:
5252

5353
diff-line-ranges:
5454
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Unified
55-
- match: ^(@@)(?=[^@\n]+@@(?:\s|$))
55+
- match: '{{bol}}(@@)(?=[^@\n]+@@(?:\s|$))'
5656
captures:
5757
1: punctuation.definition.range.begin.diff
5858
push: [hunk-name, inside-diff-line-ranges-unified]
@@ -83,17 +83,17 @@ contexts:
8383

8484
diff-deltas:
8585
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Unified
86-
- match: ^\+
86+
- match: '{{bol}}\+'
8787
scope: punctuation.definition.inserted.diff
8888
push: line-inserted
89-
- match: ^-
89+
- match: '{{bol}}-'
9090
scope: punctuation.definition.deleted.diff
9191
push: line-deleted
9292
- include: incomplete-line
9393

9494
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Incomplete-Lines
9595
incomplete-line:
96-
- match: ^[\\/]
96+
- match: '{{bol}}[\\/]'
9797
scope: punctuation.definition.comment.begin.diff
9898
push: line-ignored
9999

@@ -179,10 +179,12 @@ variables:
179179
git_hash64: '[0-9a-fA-F]{64}'
180180
git_hash_full: (?:{{git_hash64}}|{{git_hash40}})
181181
git_first_line: |-
182-
^(?x:
182+
{{bol}}(?x:
183183
From [ ] \w+@z [ ]
184184
Thu [ ] Jan [ ]{2} 1 [ ] 00:00:00 [ ] 1970 # git-send-email
185185
| From [ ] {{git_hash_full}} [ ]
186186
Mon [ ] Sep [ ] 17 [ ] 00:00:00 [ ] 2001 # git-format-patch
187187
)
188+
# No whitespace at beginning of line, unless overridden
189+
bol: ^
188190
eol: (?:$\n?)

Diff for: Diff/Diff.sublime-syntax

+37-37
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ first_line_match: |-
2525
2626
contexts:
2727
main:
28-
- match: ^(?={{git_first_line}})
28+
- match: (?={{git_first_line}})
2929
embed: Packages/Git Formats/Git Diff.sublime-syntax#email-first-line
3030
escape: (?!)
3131
# Hack for unit tests
@@ -47,24 +47,24 @@ contexts:
4747
diff-header:
4848
- meta_prepend: true
4949
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Detailed-Context
50-
- match: ^(\*{15}){{eol}}
50+
- match: '{{bol}}(\*{15}){{eol}}'
5151
scope: meta.separator.diff
5252
captures:
5353
1: punctuation.separator.block.diff
54-
- match: ^(\*{3})[ ](?!$)
54+
- match: '{{bol}}(\*{3})[ ](?!$)'
5555
captures:
5656
1: punctuation.definition.from-file.diff
5757
push: diff-header-context-from-file
5858

5959
# https://svnbook.red-bean.com/en/1.7/svn-book.html#svn.ref.svn.c.patch
60-
- match: ^(={67}|={78}|_{67}){{eol}}
60+
- match: '{{bol}}(={67}|={78}|_{67}){{eol}}'
6161
scope: meta.separator.diff
6262
captures:
6363
1: punctuation.separator.block.diff
6464

6565
# File headers from extensions and SVN
6666
- match: |-
67-
^(?x:(
67+
{{bol}}(?x:(
6868
Added | Copied | Deleted | Index | Modified
6969
| Prereq | Property [ ] changes [ ] on
7070
))(:)[ \t]*
@@ -75,7 +75,7 @@ contexts:
7575
7676
# Can't find documentation for these "="-formatted headers, but there
7777
# are preexisting unit tests.
78-
- match: ^(={4}) .+(?= - )
78+
- match: '{{bol}}(={4}) .+(?= - )'
7979
scope: meta.diff.header.from-file meta.header.from-file.diff
8080
captures:
8181
1: punctuation.definition.from-file.diff
@@ -106,7 +106,7 @@ contexts:
106106
- include: timestamps
107107

108108
maybe-diff-header-context-to-file:
109-
- match: ^(-{3})[ ](?!$)
109+
- match: '{{bol}}(-{3})[ ](?!$)'
110110
captures:
111111
1: punctuation.definition.to-file.diff
112112
push: diff-header-context-to-file
@@ -125,20 +125,20 @@ contexts:
125125
diff-line-ranges:
126126
- meta_prepend: true
127127
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Hunks
128-
- match: ^-{3}{{eol}}
128+
- match: '{{bol}}-{3}{{eol}}'
129129
scope: meta.separator.diff punctuation.separator.block.diff
130-
- match: ^\d+(?:(,)\d+)*(a|d|c)\d+(?:(,)\d+)*{{eol}}
130+
- match: '{{bol}}\d+(?:(,)\d+)*(a|d|c)\d+(?:(,)\d+)*{{eol}}'
131131
scope: meta.diff.range.normal meta.range.normal.diff
132132
captures:
133133
1: punctuation.separator.range.diff
134134
2: support.function.diff
135135
3: punctuation.separator.range.diff
136136

137137
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context
138-
- match: ^(-){3}(?= .+ -{4}{{eol}})
138+
- match: '{{bol}}(-){3}(?= .+ -{4}{{eol}})'
139139
scope: punctuation.definition.range.begin.diff
140140
push: inside-diff-line-ranges-context
141-
- match: ^(\*){3}(?= .+ \*{4}{{eol}})
141+
- match: '{{bol}}(\*){3}(?= .+ \*{4}{{eol}})'
142142
scope: punctuation.definition.range.begin.diff
143143
push: inside-diff-line-ranges-context
144144

@@ -155,34 +155,34 @@ contexts:
155155
diff-deltas:
156156
- meta_prepend: true
157157
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Normal
158-
- match: ^> ?
158+
- match: '{{bol}}> ?'
159159
scope: punctuation.definition.inserted.diff
160160
push: line-inserted
161-
- match: ^< ?
161+
- match: '{{bol}}< ?'
162162
scope: punctuation.definition.deleted.diff
163163
push: line-deleted
164164

165165
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-Context
166-
- match: ^\+ ?
166+
- match: '{{bol}}\+ ?'
167167
scope: punctuation.definition.inserted.diff
168168
push: line-inserted
169-
- match: ^- ?
169+
- match: '{{bol}}- ?'
170170
scope: punctuation.definition.deleted.diff
171171
push: line-deleted
172-
- match: ^! ?
172+
- match: '{{bol}}! ?'
173173
scope: punctuation.definition.changed.diff
174174
push: line-changed
175175

176176
###[ DIFF3 ]###################################################################
177177

178178
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Example-diff3-Normal
179179
diff3-normal:
180-
- match: ^====([1-3]?){{eol}}
180+
- match: '{{bol}}====([1-3]?){{eol}}'
181181
scope: meta.hunk.diff punctuation.section.hunk.diff
182182
captures:
183183
1: constant.numeric.from-file.diff
184184

185-
- match: ^(([1-3])(:)(?:\d+(a)|\d+(?:(,)\d+)?(c))){{eol}}
185+
- match: '{{bol}}(([1-3])(:)(?:\d+(a)|\d+(?:(,)\d+)?(c))){{eol}}'
186186
scope: meta.diff.range.normal meta.range.normal.diff
187187
captures:
188188
1: meta.toc-list.hunk.diff
@@ -196,26 +196,26 @@ contexts:
196196
diff3-normal-change:
197197
- meta_scope: meta.hunk.diff
198198
- meta_content_scope: meta.block.diff
199-
- match: ^(?:\t| )
199+
- match: '{{bol}}(?:\t| )'
200200
push: line-changed
201-
- match: ^
201+
- match: '{{bol}}'
202202
pop: 1
203203

204204
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Selecting-Which-Changes-to-Incorporate
205205
diff3-edit:
206-
- match: ^(\d+)(a){{eol}}
206+
- match: '{{bol}}(\d+)(a){{eol}}'
207207
captures:
208208
1: meta.diff.range.normal meta.range.normal.diff
209209
2: support.function.diff
210210
push: diff3-edit-inserted
211211

212-
- match: ^(\d+)(d){{eol}}
212+
- match: '{{bol}}(\d+)(d){{eol}}'
213213
captures:
214214
1: meta.diff.range.normal meta.range.normal.diff
215215
2: support.function.diff
216216
push: diff3-edit-deleted
217217

218-
- match: ^(\d+)(c){{eol}}
218+
- match: '{{bol}}(\d+)(c){{eol}}'
219219
captures:
220220
1: meta.diff.range.normal meta.range.normal.diff
221221
2: support.function.diff
@@ -237,32 +237,32 @@ contexts:
237237
- include: diff3-edit-end
238238

239239
diff3-edit-end:
240-
- match: ^\.$
240+
- match: '{{bol}}\.$'
241241
scope: punctuation.terminator.hunk.diff
242242
pop: 1
243243

244244
###[ CONFLICTS ]###############################################################
245245

246246
# Utility context for other files to use
247247
conflict-markers:
248-
- match: ^({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}}
248+
- match: '{{bol}}({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}}'
249249
scope: meta.block.conflict.begin.diff
250250
captures:
251251
1: punctuation.section.block.begin.diff
252252
2: entity.name.section.diff
253-
- match: ^({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}}
253+
- match: '{{bol}}({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}}'
254254
scope: meta.block.conflict.end.diff
255255
captures:
256256
1: punctuation.section.block.end.diff
257257
2: entity.name.section.diff
258-
- match: ^({{conflict_base}}|{{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}}
258+
- match: '{{bol}}({{conflict_base}}|{{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}}'
259259
scope: meta.block.conflict.separator.diff
260260
captures:
261261
1: punctuation.section.block.diff
262262
2: entity.name.section.diff
263263

264264
conflicts:
265-
- match: ^\s*({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}}
265+
- match: '{{bol}}({{conflict_begin}})(?:\s*({{conflict_identifier}}))?{{eol}}'
266266
scope: meta.block.conflict.begin.diff
267267
captures:
268268
1: punctuation.section.block.begin.diff
@@ -271,7 +271,7 @@ contexts:
271271

272272
conflict-deleted-lines:
273273
- meta_content_scope: meta.block.conflict.diff markup.deleted.diff
274-
- match: ^\s*({{conflict_base}})(?:\s*({{conflict_identifier}}))?{{eol}}
274+
- match: '{{bol}}({{conflict_base}})(?:\s*({{conflict_identifier}}))?{{eol}}'
275275
scope: meta.block.conflict.separator.diff
276276
captures:
277277
1: punctuation.section.block.diff
@@ -281,7 +281,7 @@ contexts:
281281

282282
conflict-base-lines:
283283
- meta_content_scope: meta.block.conflict.diff comment.block.diff
284-
- match: ^\s*({{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}}
284+
- match: '{{bol}}({{conflict_split}})(?:\s*({{conflict_identifier}}))?{{eol}}'
285285
scope: meta.block.conflict.separator.diff
286286
captures:
287287
1: punctuation.section.block.diff
@@ -291,7 +291,7 @@ contexts:
291291

292292
conflict-new-lines:
293293
- meta_content_scope: meta.block.conflict.diff markup.inserted.diff
294-
- match: ^\s*({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}}
294+
- match: '{{bol}}({{conflict_end}})(?:\s*({{conflict_identifier}}))?{{eol}}'
295295
scope: meta.block.conflict.end.diff
296296
captures:
297297
1: punctuation.section.block.end.diff
@@ -302,31 +302,31 @@ contexts:
302302
- include: invalid-conflict-marker
303303

304304
invalid-conflict-marker:
305-
- match: ^(?:{{conflict_any}})
305+
- match: '{{bol}}(?:{{conflict_any}})'
306306
scope: invalid.illegal.conflict.diff
307307

308308
###[ SIDE-BY-SIDE ]############################################################
309309

310310
# https://www.gnu.org/software/diffutils/manual/diffutils.html#Side-by-Side
311311
side-by-side:
312-
- match: ^(.*) (<)$
312+
- match: '{{bol}}(.*) (<)$'
313313
captures:
314314
1: markup.deleted.diff
315315
2: punctuation.definition.deleted.diff
316-
- match: ^(.*) (\()$
316+
- match: '{{bol}}(.*) (\()$'
317317
captures:
318318
1: comment.line.diff
319319
2: punctuation.definition.deleted.diff
320-
- match: ^(.*) ([\\|/]) (.*)$
320+
- match: '{{bol}}(.*) ([\\|/]) (.*)$'
321321
captures:
322322
1: markup.changed.diff
323323
2: punctuation.definition.changed.diff
324324
3: markup.changed.diff
325-
- match: '^ {4,}(>)(?: (.*))?$'
325+
- match: '{{bol}} {4,}(>)(?: (.*))?$'
326326
captures:
327327
1: punctuation.definition.inserted.diff
328328
2: markup.inserted.diff
329-
- match: '^ {4,}(\))(?: (.*))?$'
329+
- match: '{{bol}} {4,}(\))(?: (.*))?$'
330330
captures:
331331
1: punctuation.definition.inserted.diff
332332
2: comment.line.diff

Diff for: Diff/tests/syntax_test_diff.md

-25
This file was deleted.

0 commit comments

Comments
 (0)