Skip to content

Commit

Permalink
fix: improve setting syntax for ST syntax files
Browse files Browse the repository at this point in the history
As per ST's doc, syntax files are recommended to use "syntax_test_" in
its file name. And the "SYNTAX TEST" in the first line of the file should
always be honored (ST may use a wrong syntax basing on the file
extension).

Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Nov 23, 2024
1 parent 80d024f commit 90d7e2f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugin/commands/auto_set_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def _assign_syntax_for_new_view(view_snapshot: ViewSnapshot, event: ListenerEven
def _assign_syntax_for_st_syntax_test(view_snapshot: ViewSnapshot, event: ListenerEvent | None = None) -> bool:
if (
(view := view_snapshot.valid_view)
and (not view_snapshot.syntax or is_plaintext_syntax(view_snapshot.syntax))
and ((view.file_name() or "").startswith("syntax_test_"))
and (m := RE_ST_SYNTAX_TEST_LINE.search(view_snapshot.first_line))
and (new_syntax := m.group("syntax")).endswith(".sublime-syntax")
):
new_syntax = m.group("syntax")
if syntax := find_syntax_by_syntax_like(new_syntax, include_hidden=True, include_plaintext=True):
return assign_syntax_to_view(
view,
Expand Down

0 comments on commit 90d7e2f

Please sign in to comment.