Skip to content

Commit

Permalink
Scheme handling issues (#46)
Browse files Browse the repository at this point in the history
* Scheme handling issues

Allow `-` in variables names. Write color translations to main scheme object and ensure filtering is done after color translations.

* Update docs and release date
  • Loading branch information
facelessuser committed Jan 2, 2018
1 parent 23e4a41 commit ae18fb9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ScopeHunter 2.11.1

Jan 1, 2018

- **FIX**: Allow `-` in variables names. Write color translations to main scheme object and ensure filtering is done after color translations.

# ScopeHunter 2.11.0

Nov 20, 2017
Expand Down
2 changes: 1 addition & 1 deletion docs/src/markdown/license.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Scope Hunter is released under the MIT license.

Copyright (c) 2012 - 2017 Isaac Muse <isaacmuse@gmail.com>
Copyright (c) 2012 - 2018 Isaac Muse <isaacmuse@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
1 change: 1 addition & 0 deletions docs/theme/extra-4e53a56959.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/theme/extra-f8303dea60.css

This file was deleted.

71 changes: 43 additions & 28 deletions lib/color_scheme_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
""" % COLOR_PARTS

VARIABLES = r"""(?x)
\b(?P<var>var\(\s*(?P<var_content>\w[\w\d]*)\s*\))
\b(?P<var>var\(\s*(?P<var_content>[-\w][-\w\d]*)\s*\))
"""

COLOR_MOD = r"""(?x)
Expand Down Expand Up @@ -359,12 +359,12 @@ def __init__(self, scheme_file, color_filter=None):
self.overrides = []
if NEW_SCHEMES:
self.merge_overrides()
self.scheme_obj = color_filter(self.scheme_obj)
self.scheme_file = scheme_file
self.matched = {}
self.variables = {}

self.parse_scheme()
self.scheme_obj = color_filter(self.scheme_obj)
self.setup_matcher()

def convert_format(self, obj):
"""Convert tmTheme object to new format."""
Expand Down Expand Up @@ -469,18 +469,51 @@ def filter(self, scheme):
def parse_scheme(self):
"""Parse the color scheme."""

for k, v in self.scheme_obj.get('variables', {}).items():
variables = self.scheme_obj.get('variables', {})
for k, v in variables.items():
m = COLOR_RE.match(v.strip())
var = translate_color(m, self.variables, self.scheme_obj.get('variables')) if m is not None else None
self.variables[k] = var if var is not None else ""

color_settings = {}
for k, v in self.scheme_obj[GLOBAL_OPTIONS].items():
var = translate_color(m, self.variables, self.scheme_obj.get('variables')) if m is not None else ""
if var is None:
var = ""
self.variables[k] = var
variables[k] = var

global_options = self.scheme_obj[GLOBAL_OPTIONS]
for k, v in global_options.items():
m = COLOR_RE.match(v.strip())
if m is not None:
global_color = translate_color(m, self.variables, {})
if global_color is not None:
color_settings[k] = global_color
global_options[k] = global_color

# Create scope colors mapping from color scheme file
for item in self.scheme_obj["rules"]:
if item.get('scope', None) is not None:
# Foreground color
color = item.get('foreground', None)
if isinstance(color, list):
# Hashed Syntax Highlighting
for index, c in enumerate(color):
color[index] = translate_color(COLOR_RE.match(c.strip()), self.variables, {})
elif isinstance(color, str):
item['foreground'] = translate_color(COLOR_RE.match(color.strip()), self.variables, {})
# Background color
bgcolor = item.get('background', None)
if isinstance(bgcolor, str):
item['background'] = translate_color(COLOR_RE.match(bgcolor.strip()), self.variables, {})
# Selection foreground color
scolor = item.get('selection_foreground', None)
if isinstance(scolor, str):
item['selection_foreground'] = translate_color(COLOR_RE.match(scolor.strip()), self.variables, {})

def setup_matcher(self):
"""Setup colors for color matcher."""

color_settings = {}
global_options = self.scheme_obj[GLOBAL_OPTIONS]
for k, v in global_options.items():
if v.startswith('#'):
color_settings[k] = v

# Get general theme colors from color scheme file
bground, bground_sim = self.process_color(
Expand All @@ -506,7 +539,6 @@ def parse_scheme(self):
self.special_colors["selection"] = {'color': sbground, 'color_simulated': sbground_sim}
self.special_colors["gutter"] = {'color': gbground, 'color_simulated': gbground_sim}
self.special_colors["gutter_foreground"] = {'color': gfground, 'color_simulated': gfground_sim}

self.colors = {}
# Create scope colors mapping from color scheme file
for item in self.scheme_obj["rules"]:
Expand All @@ -519,33 +551,16 @@ def parse_scheme(self):
if scope is not None:
# Foreground color
color = item.get('foreground', None)
if isinstance(color, list):
# Hashed Syntax Highlighting
for index, c in enumerate(color):
color[index] = translate_color(COLOR_RE.match(c.strip()), self.variables, {})
elif isinstance(color, str):
color = translate_color(COLOR_RE.match(color.strip()), self.variables, {})
else:
color = None
# Background color
bgcolor = item.get('background', None)
if isinstance(bgcolor, str):
bgcolor = translate_color(COLOR_RE.match(bgcolor.strip()), self.variables, {})
else:
bgcolor = None
# Selection foreground color
scolor = item.get('selection_foreground', None)
if isinstance(scolor, str):
scolor = translate_color(COLOR_RE.match(scolor.strip()), self.variables, {})
else:
scolor = None
# Font style
if FONT_STYLE in item:
for s in item.get(FONT_STYLE, '').split(' '):
if s == "bold" or s == "italic": # or s == "underline":
style.append(s)

if scope is not None:
self.add_entry(name, scope, color, bgcolor, scolor, style)

def add_entry(self, name, scope, color, bgcolor, scolor, style):
Expand Down
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repo_url: https://github.com/facelessuser/ScopeHunter
edit_uri: tree/master/docs/src/markdown
site_description: Syntax Scope Viewer in Sublime Text.
copyright: |
Copyright &copy; 2012 - 2017 <a href="https://github.com/facelessuser">Isaac Muse</a>
Copyright &copy; 2012 - 2018 <a href="https://github.com/facelessuser">Isaac Muse</a>
<br><span class="md-footer-custom-text">emoji provided free by </span><a href="http://www.emojione.com">EmojiOne</a>
docs_dir: docs/src/markdown
Expand Down Expand Up @@ -39,6 +39,7 @@ markdown_extensions:
- markdown.extensions.def_list:
- markdown.extensions.tables:
- markdown.extensions.abbr:
- markdown.extensions.footnotes:
- pymdownx.extrarawhtml:
- pymdownx.superfences:
- pymdownx.highlight:
Expand Down Expand Up @@ -78,6 +79,6 @@ extra:
- type: github
link: https://github.com/facelessuser
extra_css:
- extra-f8303dea60.css
- extra-4e53a56959.css
extra_javascript:
- extra-d8800ea088.js
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ http://facelessuser.github.io/ScopeHunter/
# License
Scope Hunter is released under the MIT license.

Copyright (c) 2012 - 2017 Isaac Muse <isaacmuse@gmail.com>
Copyright (c) 2012 - 2018 Isaac Muse <isaacmuse@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion support.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import webbrowser
import re

__version__ = "2.11.0"
__version__ = "2.11.1"
__pc_name__ = 'ScopeHunter'


Expand Down

0 comments on commit ae18fb9

Please sign in to comment.