Skip to content

Commit 1026030

Browse files
authored
Merge pull request #27 from TheSecEng/feature/14-16
Feature/14 16
2 parents 8c4c74b + f7fd403 commit 1026030

8 files changed

+176
-153
lines changed

Commands.sublime-commands

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"caption": "Colored Comments: Remove Generated Color Scheme",
88
"command": "colored_comments_theme_revert"
99
},
10+
{
11+
"caption": "Colored Comments: Clear Colorization",
12+
"command": "colored_comments_clear"
13+
},
1014
{
1115
"caption": "Colored Comments: Settings",
1216
"command": "edit_settings",

Main.sublime-menu

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
[
2-
{
3-
"id": "preferences",
4-
"children": [
52
{
6-
"id": "package-settings",
3+
"id": "preferences",
74
"children": [
8-
{
9-
"caption": "Colored Comments",
10-
"children": [
115
{
12-
"caption": "Settings",
13-
"command": "edit_settings",
14-
"args":
15-
{
16-
"base_file": "${packages}/Colored Comments/colored_comments.sublime-settings",
17-
"default": "{\n\t$0\n}\n",
18-
},
19-
}]
20-
}]
21-
}]
22-
}]
6+
"id": "package-settings",
7+
"children": [
8+
{
9+
"caption": "Colored Comments",
10+
"children": [
11+
{
12+
"caption": "Settings",
13+
"command": "edit_settings",
14+
"args": {
15+
"base_file": "${packages}/Colored Comments/colored_comments.sublime-settings",
16+
"default": "{\n\t$0\n}\n"
17+
}
18+
}
19+
]
20+
}
21+
]
22+
}
23+
]
24+
}
25+
]

colored_comments.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
from .plugin.settings import load_settings, settings, unload_settings
77

88
NAME = "Colored Comments"
9-
VERSION = "3.0.1"
9+
VERSION = "3.0.2"
1010

11-
region_keys = list()
1211
color_scheme_manager = ColorManager
13-
1412
comment_selector = "comment - punctuation.definition.comment"
1513

1614

@@ -28,17 +26,17 @@ def on_modified_async(self, view):
2826

2927
class ColoredCommentsCommand(sublime_plugin.TextCommand):
3028
def run(self, edit):
31-
if self.view.match_selector(0, "text.plain"):
29+
if self.view.settings().get("syntax") in settings.disabled_syntax:
3230
return
3331

3432
self.ClearDecorations()
3533
self.ApplyDecorations()
3634

37-
def ClearDecorations(self):
38-
for region_key in region_keys:
35+
def ClearDecorations(self) -> None:
36+
for region_key in settings.region_keys:
3937
self.view.erase_regions(region_key)
4038

41-
def ApplyDecorations(self):
39+
def ApplyDecorations(self) -> None:
4240
to_decorate = dict()
4341
prev_match = str()
4442
for region in self.view.find_by_selector(comment_selector):
@@ -72,10 +70,10 @@ def ApplyDecorations(self):
7270
regions=to_decorate.get(key),
7371
scope=_get_scope_for_region(tag),
7472
icon=settings.comment_icon if settings.comment_icon_enabled else "",
75-
flags=self._get_tag_flags(tag),
73+
flags=self._get_flags(tag),
7674
)
7775

78-
def _get_tag_flags(self, tag):
76+
def _get_flags(self, tag: dict) -> int:
7977
options = {
8078
"outline": sublime.DRAW_NO_FILL,
8179
"underline": sublime.DRAW_SOLID_UNDERLINE,
@@ -84,11 +82,16 @@ def _get_tag_flags(self, tag):
8482
}
8583
flags = sublime.PERSISTENT
8684
for index, option in options.items():
87-
if index in tag.keys() and tag[index] is True:
85+
if tag.get(index) is True:
8886
flags |= option
8987
return flags
9088

9189

90+
class ColoredCommentsClearCommand(ColoredCommentsCommand, sublime_plugin.TextCommand):
91+
def run(self, edit):
92+
self.ClearDecorations()
93+
94+
9295
class ColoredCommentsThemeGeneratorCommand(sublime_plugin.TextCommand):
9396
def run(self, edit):
9497
color_scheme_manager.tags = settings.tags
@@ -99,35 +102,24 @@ class ColoredCommentsThemeRevertCommand(sublime_plugin.TextCommand):
99102
def run(self, edit):
100103
preferences = sublime.load_settings("Preferences.sublime-settings")
101104
if preferences.get("color_scheme"):
102-
color_scheme_manager.remove_override(
103-
preferences.get("color_scheme"))
105+
color_scheme_manager.remove_override(preferences.get("color_scheme"))
104106

105107

106108
def _get_scope_for_region(tag: dict) -> str:
107109
if tag.get("scope"):
108110
return tag.get("scope")
109-
scope_name = "colored.comments.color.{}".format(
110-
tag.get("color").get("name"))
111+
scope_name = "colored.comments.color.{}".format(tag.get("color").get("name"))
111112
return scope_name.replace(" ", ".").lower()
112113

113114

114-
def _generate_region_keys(region_keys, tag_map):
115-
for key in tag_map:
116-
if key.lower() not in region_keys:
117-
region_keys.append(key.lower())
118-
119-
120-
def plugin_loaded():
115+
def plugin_loaded() -> None:
121116
global region_keys
122117
global color_scheme_manager
123118
load_settings()
124-
_generate_region_keys(region_keys, settings.tags)
125119
log.set_debug_logging(settings.debug)
126120

127-
color_scheme_manager = ColorManager(
128-
tags=settings.tags
129-
)
121+
color_scheme_manager = ColorManager(tags=settings.tags)
130122

131123

132-
def plugin_unloaded():
124+
def plugin_unloaded() -> None:
133125
unload_settings()

colored_comments.sublime-settings

+20-32
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
{
22
// Enable debug logging
33
"debug": false,
4-
54
// Enables continued matching of the previous tag
65
"continued_matching": true,
7-
86
// Character to continue matching on
97
"continued_matching_pattern": "-",
10-
118
// Shows comment icon next to comments
129
"comment_icon_enabled": true,
13-
1410
// Which comment icon to use
1511
// Valid options: comment, dots
1612
"comment_icon": "dots",
17-
13+
// Ignored Syntax List
14+
"disabled_syntax": [
15+
"Packages/Text/Plain text.tmLanguage",
16+
"Packages/Markdown/MultiMarkdown.sublime-syntax",
17+
"Packages/Markdown/Markdown.sublime-syntax"
18+
],
1819
// This is the list of tags/identifiers you want to highlight
1920
// in your code.
20-
"tags":
21-
{
21+
"tags": {
2222
// Friendly name for you to know what the purpose is
2323
// and used in the OrderedDict
2424
// These should be unique
25-
"Important":
26-
{
25+
"Important": {
2726
// The actual identifier used to highlight the comments
2827
"identifier": "!",
2928
// Enables sublime.DRAW_SOLID_UNDERLINE
@@ -45,8 +44,7 @@
4544
// Enables ignorecase for the ideentifier
4645
"ignorecase": true,
4746
// Colors used for Scope generation
48-
"color":
49-
{
47+
"color": {
5048
// Scope name this becomes colored.comments.color.important
5149
"name": "important",
5250
// Color you want the text to be
@@ -57,30 +55,24 @@
5755
"background": "rgba(1,22,38, 0.1)"
5856
},
5957
},
60-
"Deprecated":
61-
{
58+
"Deprecated": {
6259
"identifier": "*",
63-
"color":
64-
{
60+
"color": {
6561
"name": "deprecated",
6662
"foreground": "#98C379",
6763
"background": "rgba(1,22,38, 0.1)"
6864
},
6965
},
70-
"Question":
71-
{
66+
"Question": {
7267
"identifier": "?",
73-
"color":
74-
{
68+
"color": {
7569
"name": "question",
7670
"foreground": "#3498DB",
7771
"background": "rgba(1,22,38, 0.1)"
7872
},
7973
},
80-
"TODO":
81-
{
82-
"color":
83-
{
74+
"TODO": {
75+
"color": {
8476
"background": "rgba(1,22,38, 0.1)",
8577
"foreground": "#FF8C00",
8678
"name": "todo"
@@ -89,21 +81,17 @@
8981
"is_regex": true,
9082
"ignorecase": true,
9183
},
92-
"FIXME":
93-
{
94-
"color":
95-
{
84+
"FIXME": {
85+
"color": {
9686
"background": "rgba(1,22,38, 0.1)",
9787
"foreground": "#9933FF",
9888
"name": "fixme"
9989
},
10090
"identifier": "FIXME[:]?|fixme[:]?",
10191
"is_regex": true
10292
},
103-
"UNDEFINED":
104-
{
105-
"color":
106-
{
93+
"UNDEFINED": {
94+
"color": {
10795
"background": "rgba(1,22,38, 0.1)",
10896
"foreground": "#474747",
10997
"name": "undefined"
@@ -112,4 +100,4 @@
112100
"is_regex": true
113101
}
114102
}
115-
}
103+
}

messages.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
"install": "messages/install.txt",
33
"3.0.0": "messages/3.0.0.txt",
44
"3.0.1": "messages/3.0.1.txt",
5+
"3.0.2": "messages/3.0.2.txt"
56
}

messages/3.0.2.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Version 3.0.2 (May 18, 2020)
2+
----------------------------
3+
4+
* NEW Setting: disabled_syntax
5+
- Now you can specify if colored comments
6+
should be disabled on certain syntax's
7+
8+
* NEW Command: Colored Comments: Clear Colorization
9+
- Useful when the file was edited outside of
10+
Sublime Text and the color regions were messed up

plugin/color_manager.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import sublime
44

5-
65
sublime_settings = "Preferences.sublime-settings"
76
override_path = "Colored Comments Override"
87
scope_name = "colored.comments.color."
@@ -12,10 +11,10 @@ class ColorManager:
1211
def __init__(self, tags):
1312
self.tags = tags
1413

15-
def remove_override(self, scheme):
14+
def remove_override(self, scheme) -> None:
1615
self.save_scheme(os.path.basename(scheme), {"rules": [], "variables": {}})
1716

18-
def create_user_custom_theme(self):
17+
def create_user_custom_theme(self) -> None:
1918
if not self.tags:
2019
return
2120

@@ -44,11 +43,11 @@ def _add_colors_to_scheme(self, scheme_content: dict) -> dict:
4443
scope = "{}{}".format(scope_name, name.lower().replace(" ", "."))
4544
if not any(rule.get("scope") == scope for rule in rules):
4645
entry = {
47-
"name": "[Colored Comments] {}".format(name.title()),
48-
"scope": scope,
49-
"foreground": foreground,
50-
"background": background
51-
}
46+
"name": "[Colored Comments] {}".format(name.title()),
47+
"scope": scope,
48+
"foreground": foreground,
49+
"background": background,
50+
}
5251
rules.append(entry)
5352
scheme_content["rules"] = rules
5453
return scheme_content
@@ -60,7 +59,9 @@ def _build_scheme_path(scheme: str) -> str:
6059

6160

6261
def _create_override_path() -> None:
63-
return os.makedirs(os.path.join(sublime.packages_path(), override_path), exist_ok=True)
62+
return os.makedirs(
63+
os.path.join(sublime.packages_path(), override_path), exist_ok=True
64+
)
6465

6566

6667
def _get_color_property(property: str, tags: dict) -> str:

0 commit comments

Comments
 (0)