Skip to content

Commit

Permalink
[LaTeX] Refactor braces contexts
Browse files Browse the repository at this point in the history
Illustrate how `braces` are implemented in both TeX & LaTeX with same
content but different sub-scopes. Re-implementing a context without
meta_prepend/meta_append overrides it completely.
  • Loading branch information
deathaxe committed Nov 19, 2022
1 parent 874f1d3 commit 4f2b78f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
17 changes: 11 additions & 6 deletions LaTeX/LaTeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ contexts:
braces:
- match: \{
scope: punctuation.definition.group.brace.begin.latex
push:
- meta_scope: meta.group.brace.latex
- match: \}
scope: punctuation.definition.group.brace.end.latex
pop: true
- include: main
push: brace-group-body

brace-group-body:
- meta_scope: meta.group.brace.latex
- include: brace-group-end
- include: main

brace-group-end:
- match: \}
scope: punctuation.definition.group.brace.end.latex
pop: true

# these are used to identify arguments in commands
general-optional-arguments:
Expand Down
21 changes: 11 additions & 10 deletions LaTeX/TeX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,17 @@ contexts:
braces:
- match: \{
scope: punctuation.definition.group.brace.begin.tex
push:
- meta_scope: meta.group.brace.tex
- include: brace-group-end
- include: main
push: brace-group-body

brace-group-body:
- meta_scope: meta.group.brace.tex
- include: brace-group-end
- include: main

brace-group-end:
- match: \}
scope: punctuation.definition.group.brace.end.tex
pop: true

# within macros, it is possible that only part of some nested struture
# is present. To prevent this from causing problems, here we only match
Expand Down Expand Up @@ -383,12 +390,6 @@ contexts:
- match: (?=\S)
pop: true

# matches a closing brace and pops the context
brace-group-end:
- match: \}
scope: punctuation.definition.group.brace.end.tex
pop: true

immediately-pop:
- match: ''
pop: true
Expand Down

0 comments on commit 4f2b78f

Please sign in to comment.