Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #15 from KuttKatrea/syntax-ignore
Browse files Browse the repository at this point in the history
Support for syntax ignore
  • Loading branch information
bluegray committed Jul 23, 2016
2 parents 47dd1a7 + 6ca1e85 commit 0209366
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DEFAULT_REGEX = '(\t+ +(?![*]))|( +\t+)|([\t ]+$)'
DEFAULT_REGEX_COOL = '[\u2026\u2018\u2019\u201c\u201d\u2013\u2014\u00a0]'
DEFAULT_DELAY = 3000

DEFAULT_SYNTAX_IGNORE = []

class Preferences:
def load(self, settings):
Expand All @@ -22,6 +22,7 @@ def load(self, settings):
self.color_scope_name = settings.get('highlighter_scope_name', DEFAULT_COLOR_SCOPE_NAME)
self.color_scope_name_cool = settings.get('highlighter_scope_name_cool', DEFAULT_COLOR_SCOPE_NAME_COOL)
self.delay = settings.get('highlighter_delay', DEFAULT_DELAY)
self.syntax_ignore = settings.get('highlighter_syntax_ignore', DEFAULT_SYNTAX_IGNORE)

Pref = Preferences()

Expand All @@ -38,6 +39,19 @@ def is_find_results(view):
"Find Results" in view.settings().get('syntax')


# Returns True if the view should be ignored, False otherwise.
def ignore_view(view):
view_syntax = view.settings().get('syntax')

if not view_syntax:
return False

for syntax_ignore in Pref.syntax_ignore:
if syntax_ignore in view_syntax:
return True

return False

# Return an array of regions matching regex.
def find_regexes(view):
return view.find_all(Pref.regex)
Expand All @@ -49,7 +63,7 @@ def find_regexes_cool(view):

# Highlight regex matches.
def highlighter(view):
if view.size() <= Pref.max_size and not is_find_results(view):
if view.size() <= Pref.max_size and not ignore_view(view) and not is_find_results(view):
regions = find_regexes(view)
regions_cool = find_regexes_cool(view)
view.add_regions('HighlighterListener', regions,
Expand Down

0 comments on commit 0209366

Please sign in to comment.