Skip to content

Commit 2108560

Browse files
committed
Replace sublime_lib.RegionOption
ST4 has been shipping `sublime.RegionFlags` for quite a while. Time to switch from 3rd-party to built-in solution.
1 parent 004eb12 commit 2108560

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

plugins/lib/view_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sublime import Region
2+
from sublime import RegionFlags
23

34
__all__ = ['has_file_ext', 'base_scope',
45
'coorded_substr', 'get_text',
@@ -165,3 +166,14 @@ def extract_selector(view, selector, point):
165166
if reg.contains(point):
166167
return reg
167168
return None
169+
170+
171+
def region_flags_from_names(flag_names):
172+
"""Convert a list of strings into ``sublime.RegionFlags`` object.
173+
174+
Note: Invalid flag names are silently ignored.
175+
176+
Example:
177+
flags: sublime.RegionFlags = region_flags_from_names(["DRAW_EMPTY", "DRAW_NO_FILL"])
178+
"""
179+
return RegionFlags(sum(getattr(RegionFlags, n, RegionFlags.NONE) for n in flag_names))

plugins/settings/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import sublime
66
import sublime_plugin
77

8-
from sublime_lib.flags import RegionOption
9-
108
from ..lib import get_setting, inhibit_word_completions
119
from ..lib import syntax_paths
10+
from ..lib.view_utils import region_flags_from_names
1211
from ..lib.weakmethod import WeakMethodProxy
1312

1413
from .region_math import (VALUE_SCOPE, KEY_SCOPE, KEY_COMPLETIONS_SCOPE,
@@ -265,7 +264,7 @@ def do_linting(self):
265264
unknown_regions,
266265
scope=get_setting('settings.highlight_scope', "text"),
267266
icon='dot',
268-
flags=RegionOption(*styles)
267+
flags=region_flags_from_names(styles)
269268
)
270269
else:
271270
self.view.erase_regions('unknown_settings_keys')

plugins/syntax_dev/highlighter.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import sublime
44
import sublime_plugin
55

6-
from sublime_lib.flags import RegionOption
7-
6+
from ..lib import package_settings
87
from ..lib import syntax_paths
8+
from ..lib.view_utils import region_flags_from_names
99

1010
__all__ = (
1111
'SyntaxDefRegexCaptureGroupHighlighter',
@@ -23,17 +23,12 @@ def is_applicable(cls, settings):
2323
return settings.get('syntax') == syntax_paths.SYNTAX_DEF
2424

2525
def on_selection_modified(self):
26-
prefs = sublime.load_settings('PackageDev.sublime-settings')
27-
scope = prefs.get('syntax.captures_highlight_scope', "text")
28-
styles = prefs.get('syntax.captures_highlight_styles', ['DRAW_NO_FILL'])
29-
30-
style_flags = RegionOption(*styles)
31-
26+
prefs = package_settings()
3227
self.view.add_regions(
3328
key='captures',
3429
regions=list(self.get_regex_regions()),
35-
scope=scope,
36-
flags=style_flags,
30+
scope=prefs['syntax.captures_highlight_scope'],
31+
flags=region_flags_from_names(prefs['syntax.captures_highlight_styles']),
3732
)
3833

3934
def get_regex_regions(self):

plugins/syntaxtest_dev.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import sublime
88
import sublime_plugin
99

10-
from sublime_lib.flags import RegionOption
11-
1210
from .lib import get_setting, path_is_relative_to
11+
from .lib.view_utils import region_flags_from_names
1312

1413
__all__ = (
1514
'SyntaxTestHighlighterListener',
@@ -200,7 +199,7 @@ def on_selection_modified_async(self):
200199

201200
scope = get_setting('syntax_test.highlight_scope', 'text')
202201
styles = get_setting('syntax_test.highlight_styles', ['DRAW_NO_FILL'])
203-
style_flags = RegionOption(*styles)
202+
style_flags = region_flags_from_names(styles)
204203

205204
self.view.add_regions('current_syntax_test', [region], scope, '', style_flags)
206205

0 commit comments

Comments
 (0)