Skip to content

Commit a757851

Browse files
deathaxeFichteFoll
authored andcommitted
Improve SyntaxTestHighlighterListener header handling
1. The `self.header` is an object attribute and should be therefore declared in `__init__()` 2. The `self.header` is queried first in `__del__()` to avoid reading settings, if we are not within a syntax_test_... 3. Save 2 lines of code when checking syntax_test_ file name
1 parent e5cc2dd commit a757851

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

plugins_/syntaxtest_dev.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def get_syntax_test_tokens(view):
5252

5353

5454
class SyntaxTestHighlighterListener(sublime_plugin.ViewEventListener):
55-
header = None
5655

5756
@classmethod
5857
def is_applicable(cls, settings):
@@ -61,14 +60,15 @@ def is_applicable(cls, settings):
6160

6261
def __init__(self, view):
6362
super().__init__(view)
63+
self.header = None
6464
self.on_modified_async()
6565
self.on_selection_modified_async()
6666

6767
def __del__(self):
6868
# Settings were (most likely) changed to use tabs
6969
# or plugin was unloaded.
7070
# Complain about the former, if we have a test file.
71-
if not self.is_applicable(self.view.settings()) and self.header:
71+
if self.header and not self.is_applicable(self.view.settings()):
7272
_show_tab_warning()
7373

7474
def on_modified_async(self):
@@ -78,11 +78,9 @@ def on_modified_async(self):
7878
"""
7979

8080
name = self.view.file_name()
81-
if name:
82-
name = path.basename(name)
83-
if not name.startswith('syntax_test_'):
84-
self.header = None
85-
return
81+
if name and not path.basename(name).startswith('syntax_test_'):
82+
self.header = None
83+
return
8684
self.header = get_syntax_test_tokens(self.view)
8785
# if there is no comment start token, clear the header
8886
if self.header and not self.header.comment_start:

0 commit comments

Comments
 (0)