8000 Backported fixes and new feature · vprimachenko/Sublime-Colorcoder@3425fb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3425fb6

Browse files
committed
Backported fixes and new feature
1 parent 2a926dc commit 3425fb6

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

Default.sublime-commands

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
[{ "caption": "Add Colorcode to current color scheme",
1+
[{ "caption": "Tweak Colorcode to current color scheme",
22
"command": "colorshemeemodifier"
3+
},{
4+
"caption": "Dont Colorcode this view",
5+
"command": "colorcoderdisabler"
36
}]

Go.tmLanguage

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<key>name</key>
3232
<string>string.go</string>
3333
</dict>
34+
<dict>
35+
<key>match</key>
36+
<string>`[^']*`</string>
37+
<key>name</key>
38+
<string>string.go</string>
39+
</dict>
3440
<dict>
3541
<key>match</key>
3642
<string>'[^']*'</string>
@@ -53,7 +59,7 @@
5359
</dict>
5460
<dict>
5561
<key>match</key>
56-
<string>\b(package|import|for|if|go|defer|func|_)\b</string>
62+
<string>\b(package|import|range|for|if|go|defer|func|var|_)\b</string>
5763
<key>name</key>
5864
<string>keywords.go</string>
5965
</dict>

Main.sublime-menu

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
[{ "caption": "Colorcoder",
88
"id": "Colorcoder-com",
99
"children":
10-
[{ "caption": "Add Colorcode to current color scheme",
10+
[{ "caption": "Tweak Colorcode on current color scheme",
1111
"command": "colorshemeemodifier"
12+
},{
13+
"caption": "Dont Colorcode this view",
14+
"command": "colorcoderdisabler"
1215
}]
1316
}]
1417
}]

colorcoder.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ def crc(self, msg):
4545
class colorcoder(sublime_plugin.EventListener):
4646

4747
hasher = crc8();
48-
scopes = ['colorize','entity.name','support.function','variable']
49-
5048

5149
def __init__(self):
5250
sublime.set_timeout(self.read_settings,500)
5351

5452
def read_settings(self):
55-
sublime.load_settings("colorcoder.sublime-settings").add_on_change('scopes',self.read_settings)
5653
sublime.load_settings("Preferences.sublime-settings").add_on_change('color_scheme',self.maybefixscheme)
5754
pp = sublime.packages_path()
5855
if not os.path.exists(pp+"/Colorcoder"):
@@ -63,7 +60,6 @@ def read_settings(self):
6360
self.maybefixscheme()
6461
open(firstrunfile, 'a').close()
6562

66-
self.scopes = sublime.load_settings("colorcoder.sublime-settings").get('scopes',['colorize','entity.name','support.function','meta.function-call','variable.other'])
6763
self.on_modified(sublime.active_window().active_view())
6864

6965
def maybefixscheme(self):
@@ -75,14 +71,35 @@ def maybefixscheme(self):
7571
def on_modified(self, view):
7672
sublime.set_timeout(lambda: self.on_modified_async(view), 0)
7773

78-
def on_modified_async(self, view):
74+
def on_load(self,view):
75+
if view.file_name():
76+
filename = os.path.split(view.file_name())[1]
77+
dotp = filename.rfind('.')
78+
ext = '' if dotp == -1 else filename[dotp+1:]
79+
set = sublime.load_settings("colorcoder.sublime-settings")
80+
if (set.has('enabled_for') and ext not in set.get('enabled_for')) or ext in set.get('disabled_for',[]):
81+
view.settings().set('colorcode',False)
82+
return
83+
else:
84+
pass
85+
7986
vcc = view.settings().get('color_scheme')
80-
if vcc and "Widget" in vcc: return
87+
if vcc and "Widget" in vcc:
88+
view.settings().set('colorcode',False)
89+
return
90+
91+
self.on_modified(view)
92+
93+
94+
def on_modified_async(self, view):
95+
if not view.settings().get('colorcode',True):
96+
return
97+
8198
regs = {}
8299
for i in range(256):
83100
regs[hex(i)] = []
84101

85-
for sel in self.scopes:
102+
for sel in sublime.load_settings("colorcoder.sublime-settings").get('scopes'):
86103
for r in view.find_by_selector(sel):
87104
regs[hex(self.hasher.crc(view.substr(r)))].append(r)
88105

@@ -134,6 +151,7 @@ def modify_color_scheme(l,s,read_original = False):
134151
rule["settings"]["background"] = "#000001"
135152

136153
tokenclr = "#%02x%02x%02x" % (r,g,b)
154+
break
137155

138156
cs["name"] = cs["name"] + " (Colorcode)"
139157

@@ -153,3 +171,4 @@ def modify_color_scheme(l,s,read_original = False):
153171
sublime.load_settings("Preferences.sublime-settings").set("original_color_scheme", name)
154172
sublime.load_settings("Preferences.sublime-settings").set("color_scheme","Packages%s" % newname)
155173
sublime.save_settings("Preferences.sublime-settings")
174+

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Motivation
1313

1414
it is important to note i use a `crc8` hash of the variable name to give similar named variables distinct colors to improve typo recognition
1515

16+
Options
17+
-------
18+
Colorcoder allows you to specify white- and blacklist for file-types to highlight: the settings are `enabled_for` and `disabled_for`. If `enabled_for` is present in the config only those file-types will be highlighted, `disabled_for` wont be highlighted even if present in whitelist.
19+
1620
Installation
1721
------------
1822
download the [zip-ball](https://github.com/vprimachenko/Sublime-Colorcoder/archive/master.zip) and unpack to `sublime\data\packages` or via [packageControl](https://sublime.wbond.net/)

0 commit comments

Comments
 (0)
0