diff --git a/plugins/lib/view_utils.py b/plugins/lib/view_utils.py index 2577437f..db580999 100644 --- a/plugins/lib/view_utils.py +++ b/plugins/lib/view_utils.py @@ -1,4 +1,5 @@ from sublime import Region +from sublime import RegionFlags __all__ = ['has_file_ext', 'base_scope', 'coorded_substr', 'get_text', @@ -165,3 +166,14 @@ def extract_selector(view, selector, point): if reg.contains(point): return reg return None + + +def region_flags_from_strings(flag_names): + """Convert a list of strings into ``sublime.RegionFlags`` object. + + Note: Invalid flag names are silently ignored. + + Example: + flags: sublime.RegionFlags = region_flags_from_strings(["DRAW_EMPTY", "DRAW_NO_FILL"]) + """ + return RegionFlags(sum(getattr(RegionFlags, n, RegionFlags.NONE) for n in flag_names)) diff --git a/plugins/settings/__init__.py b/plugins/settings/__init__.py index 5fc98568..0d2d5fc7 100644 --- a/plugins/settings/__init__.py +++ b/plugins/settings/__init__.py @@ -5,10 +5,9 @@ import sublime import sublime_plugin -from sublime_lib.flags import RegionOption - from ..lib import get_setting, inhibit_word_completions from ..lib import syntax_paths +from ..lib.view_utils import region_flags_from_strings from ..lib.weakmethod import WeakMethodProxy from .region_math import (VALUE_SCOPE, KEY_SCOPE, KEY_COMPLETIONS_SCOPE, @@ -265,7 +264,7 @@ def do_linting(self): unknown_regions, scope=get_setting('settings.highlight_scope', "text"), icon='dot', - flags=RegionOption(*styles) + flags=region_flags_from_strings(styles) ) else: self.view.erase_regions('unknown_settings_keys') diff --git a/plugins/syntax_dev/highlighter.py b/plugins/syntax_dev/highlighter.py index 550c69f2..b3110b09 100644 --- a/plugins/syntax_dev/highlighter.py +++ b/plugins/syntax_dev/highlighter.py @@ -3,9 +3,9 @@ import sublime import sublime_plugin -from sublime_lib.flags import RegionOption - +from ..lib import package_settings from ..lib import syntax_paths +from ..lib.view_utils import region_flags_from_strings __all__ = ( 'SyntaxDefRegexCaptureGroupHighlighter', @@ -23,17 +23,12 @@ def is_applicable(cls, settings): return settings.get('syntax') == syntax_paths.SYNTAX_DEF def on_selection_modified(self): - prefs = sublime.load_settings('PackageDev.sublime-settings') - scope = prefs.get('syntax.captures_highlight_scope', "text") - styles = prefs.get('syntax.captures_highlight_styles', ['DRAW_NO_FILL']) - - style_flags = RegionOption(*styles) - + prefs = package_settings() self.view.add_regions( key='captures', regions=list(self.get_regex_regions()), - scope=scope, - flags=style_flags, + scope=prefs['syntax.captures_highlight_scope'], + flags=region_flags_from_strings(prefs['syntax.captures_highlight_styles']), ) def get_regex_regions(self): diff --git a/plugins/syntaxtest_dev.py b/plugins/syntaxtest_dev.py index a56c00d2..15b841ba 100644 --- a/plugins/syntaxtest_dev.py +++ b/plugins/syntaxtest_dev.py @@ -7,9 +7,8 @@ import sublime import sublime_plugin -from sublime_lib.flags import RegionOption - from .lib import get_setting, path_is_relative_to +from .lib.view_utils import region_flags_from_strings __all__ = ( 'SyntaxTestHighlighterListener', @@ -200,7 +199,7 @@ def on_selection_modified_async(self): scope = get_setting('syntax_test.highlight_scope', 'text') styles = get_setting('syntax_test.highlight_styles', ['DRAW_NO_FILL']) - style_flags = RegionOption(*styles) + style_flags = region_flags_from_strings(styles) self.view.add_regions('current_syntax_test', [region], scope, '', style_flags)