From 90d7e2f54a509c47ccf802ae7e5c063ebe95c272 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Sun, 24 Nov 2024 04:14:39 +0800 Subject: [PATCH] fix: improve setting syntax for ST syntax files 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 --- plugin/commands/auto_set_syntax.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/commands/auto_set_syntax.py b/plugin/commands/auto_set_syntax.py index 1116f8a0..501a6325 100644 --- a/plugin/commands/auto_set_syntax.py +++ b/plugin/commands/auto_set_syntax.py @@ -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,