Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions plugins/lib/view_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sublime import Region
from sublime import RegionFlags

__all__ = ['has_file_ext', 'base_scope',
'coorded_substr', 'get_text',
Expand Down Expand Up @@ -165,3 +166,20 @@ 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"])
"""
result = RegionFlags.NONE
for name in flag_names:
try:
result |= RegionFlags[name]
except KeyError:
continue
return result
5 changes: 2 additions & 3 deletions plugins/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down
15 changes: 5 additions & 10 deletions plugins/syntax_dev/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions plugins/syntaxtest_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)

Expand Down