Skip to content

Commit b4c3ee8

Browse files
authored
Merge pull request #33 from TheSecEng/st4/no_auto_generate
fix: remove color generator, include butchered sublime_lib
2 parents 6f6ea1f + c11cb47 commit b4c3ee8

20 files changed

+4031
-175
lines changed

Commands.sublime-commands

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
[
22
{
3-
"caption": "Colored Comments: Generate Color Scheme",
4-
"command": "colored_comments_theme_generator"
5-
},
6-
{
7-
"caption": "Colored Comments: Remove Generated Color Scheme",
8-
"command": "colored_comments_theme_revert"
3+
"caption": "Colored Comments: Override Current Color Scheme",
4+
"command": "colored_comments_edit_scheme"
95
},
106
{
117
"caption": "Colored Comments: Clear Colorization",

LICENSE

+23
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,26 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22+
23+
MIT License
24+
25+
Copyright (c) 2010-2014 Guillermo López-Anglada (Vintageous)
26+
Copyright (c) 2012-2019 FichteFoll <[email protected]>
27+
28+
Permission is hereby granted, free of charge, to any person obtaining a copy of
29+
this software and associated documentation files (the "Software"), to deal in
30+
the Software without restriction, including without limitation the rights to
31+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
32+
of the Software, and to permit persons to whom the Software is furnished to do
33+
so, subject to the following conditions:
34+
35+
The above copyright notice and this permission notice shall be included in all
36+
copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44+
SOFTWARE.

colored_comments.py

+111-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,123 @@
22
import sublime_plugin
33

44
from .plugin import logger as log
5-
from .plugin.color_manager import color_manager, load_color_manager
5+
from .lib.sublime_lib import ResourcePath
66
from .plugin.settings import load_settings, settings, unload_settings
77

88
NAME = "Colored Comments"
99
VERSION = "3.0.3"
1010

1111
comment_selector = "comment - punctuation.definition.comment"
1212

13+
# Thanks PackageDev
14+
SCHEME_TEMPLATE = """\
15+
{
16+
// http://www.sublimetext.com/docs/3/color_schemes.html
17+
"variables": {
18+
"important_comment": "var(region.redish)",
19+
"deprecated_comment": "var(region.purplish)",
20+
"question_comment": "var(region.cyanish)",
21+
"todo_comment": "var(region.greenish)",
22+
"fixme_comment": "var(region.bluish)",
23+
"undefined_comment": "var(region.accent)",
24+
},
25+
"globals": {
26+
// "foreground": "var(green)",
27+
},
28+
"rules": [
29+
{
30+
"name": "IMPORTANT COMMENTS",
31+
"scope": "comments.important",
32+
"foreground": "var(important_comment)",
33+
"background": "rgba(1,22,38, 0.1)",
34+
},
35+
{
36+
"name": "DEPRECATED COMMENTS",
37+
"scope": "comments.deprecated",
38+
"foreground": "var(deprecated_comment)",
39+
"background": "rgba(1,22,38, 0.1)",
40+
},
41+
{
42+
"name": "QUESTION COMMENTS",
43+
"scope": "comments.question",
44+
"foreground": "var(question_comment)",
45+
"background": "rgba(1,22,38, 0.1)",
46+
},
47+
{
48+
"name": "TODO COMMENTS",
49+
"scope": "comments.todo",
50+
"foreground": "var(todo_comment)",
51+
"background": "rgba(1,22,38, 0.1)",
52+
},
53+
{
54+
"name": "FIXME COMMENTS",
55+
"scope": "comments.fixme",
56+
"foreground": "var(fixme_comment)",
57+
"background": "rgba(1,22,38, 0.1)",
58+
},
59+
{
60+
"name": "UNDEFINED COMMENTS",
61+
"scope": "comments.undefined",
62+
"foreground": "var(undefined_comment)",
63+
"background": "rgba(1,22,38, 0.1)",
64+
},
65+
],
66+
}""".replace(" ", "\t")
67+
68+
KIND_SCHEME = (sublime.KIND_ID_VARIABLE, "s", "Scheme")
69+
DEFAULT_CS = 'Packages/Color Scheme - Default/Mariana.sublime-color-scheme'
70+
71+
72+
class ColoredCommentsEditSchemeCommand(sublime_plugin.WindowCommand):
73+
74+
"""Like syntax-specific settings but for the currently used color scheme."""
75+
76+
def run(self):
77+
view = self.window.active_view()
78+
if not view:
79+
return
80+
81+
scheme_path = self.get_scheme_path(view, 'color_scheme')
82+
if scheme_path != 'auto':
83+
self.open_scheme(scheme_path)
84+
else:
85+
paths = [
86+
(setting, self.get_scheme_path(view, setting))
87+
for setting in ('dark_color_scheme', 'light_color_scheme')
88+
]
89+
choices = [
90+
sublime.QuickPanelItem(
91+
setting, details=str(path), kind=KIND_SCHEME)
92+
for setting, path in paths
93+
]
94+
95+
def on_done(i):
96+
if i >= 0:
97+
self.open_scheme(paths[i][1])
98+
99+
self.window.show_quick_panel(choices, on_done)
100+
101+
@staticmethod
102+
def get_scheme_path(view, setting_name):
103+
# Be lazy here and don't consider invalid values
104+
scheme_setting = view.settings().get(setting_name, DEFAULT_CS)
105+
if scheme_setting == 'auto':
106+
return 'auto'
107+
elif "/" not in scheme_setting:
108+
return ResourcePath.glob_resources(scheme_setting)[0]
109+
else:
110+
return ResourcePath(scheme_setting)
111+
112+
def open_scheme(self, scheme_path):
113+
self.window.run_command(
114+
'edit_settings',
115+
{
116+
'base_file': '/'.join(("${packages}",) + scheme_path.parts[1:]),
117+
'user_file': "${packages}/User/" + scheme_path.stem + '.sublime-color-scheme',
118+
'default': SCHEME_TEMPLATE,
119+
},
120+
)
121+
13122

14123
class ColoredCommentsEventListener(sublime_plugin.EventListener):
15124
def on_init(self, views):
@@ -63,7 +172,7 @@ def ApplyDecorations(self) -> None:
63172
self.view.add_regions(
64173
key=key.lower(),
65174
regions=to_decorate.get(key),
66-
scope=settings.get_scope_for_region(tag),
175+
scope=settings.get_scope_for_region(key, tag),
67176
icon=settings.get_icon(),
68177
flags=settings.get_flags(tag),
69178
)
@@ -87,9 +196,7 @@ def run(self, edit):
87196

88197

89198
def plugin_loaded() -> None:
90-
global color_scheme_manager
91199
load_settings()
92-
load_color_manager()
93200
log.set_debug_logging(settings.debug)
94201

95202

colored_comments.sublime-settings

+8-37
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Character to continue matching on
77
"continued_matching_pattern": "-",
88
// Shows comment icon next to comments
9-
"comment_icon_enabled": true,
9+
"comment_icon_enabled": false,
1010
// Which comment icon to use
1111
// Valid options: comment, dots
1212
"comment_icon": "dots",
@@ -23,6 +23,8 @@
2323
// and used in the OrderedDict
2424
// These should be unique
2525
"Important": {
26+
// The name of the scope being use in your color scheme file
27+
"scope": "comments.important",
2628
// The actual identifier used to highlight the comments
2729
"identifier": "!",
2830
// Enables sublime.DRAW_SOLID_UNDERLINE
@@ -43,59 +45,28 @@
4345
"is_regex": false,
4446
// Enables ignorecase for the ideentifier
4547
"ignorecase": true,
46-
// Colors used for Scope generation
47-
"color": {
48-
// Scope name this becomes colored.comments.color.important
49-
"name": "important",
50-
// Color you want the text to be
51-
"foreground": "#FF2D00",
52-
// Color you want the background to be
53-
// this HAS to be slightly different than
54-
// your themes background....Because Sublime
55-
"background": "rgba(1,22,38, 0.1)"
56-
},
5748
},
5849
"Deprecated": {
50+
"scope": "comments.deprecated",
5951
"identifier": "*",
60-
"color": {
61-
"name": "deprecated",
62-
"foreground": "#98C379",
63-
"background": "rgba(1,22,38, 0.1)"
64-
},
6552
},
6653
"Question": {
54+
"scope": "comments.question",
6755
"identifier": "?",
68-
"color": {
69-
"name": "question",
70-
"foreground": "#3498DB",
71-
"background": "rgba(1,22,38, 0.1)"
72-
},
7356
},
7457
"TODO": {
75-
"color": {
76-
"background": "rgba(1,22,38, 0.1)",
77-
"foreground": "#FF8C00",
78-
"name": "todo"
79-
},
58+
"scope": "comments.todo",
8059
"identifier": "TODO[:]?|todo[:]?",
8160
"is_regex": true,
8261
"ignorecase": true,
8362
},
8463
"FIXME": {
85-
"color": {
86-
"background": "rgba(1,22,38, 0.1)",
87-
"foreground": "#9933FF",
88-
"name": "fixme"
89-
},
64+
"scope": "comments.fixme",
9065
"identifier": "FIXME[:]?|fixme[:]?",
9166
"is_regex": true
9267
},
9368
"UNDEFINED": {
94-
"color": {
95-
"background": "rgba(1,22,38, 0.1)",
96-
"foreground": "#474747",
97-
"name": "undefined"
98-
},
69+
"scope": "comments.undefined",
9970
"identifier": "//[:]?",
10071
"is_regex": true
10172
}

lib/sublime_lib/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Thomas Smith
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

lib/sublime_lib/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .resource_path import ResourcePath # noqa: F401

lib/sublime_lib/_compat/__init__.py

Whitespace-only changes.

lib/sublime_lib/_compat/pathlib.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from pathlib import * # noqa: F401, F403
3+
except ImportError:
4+
from ..vendor.pathlib.pathlib import * # type: ignore # noqa: F401, F403

lib/sublime_lib/_compat/typing.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from typing import * # noqa: F401, F403
3+
except ImportError:
4+
from .typing_stubs import * # type: ignore # noqa: F401, F403

lib/sublime_lib/_util/__init__.py

Whitespace-only changes.

lib/sublime_lib/_util/glob.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import re
2+
from functools import lru_cache
3+
4+
from .._compat.typing import Callable
5+
6+
__all__ = ['get_glob_matcher']
7+
8+
9+
GLOB_RE = re.compile(r"""(?x)(
10+
\*
11+
| \?
12+
| \[ .*? \]
13+
)""")
14+
15+
16+
@lru_cache()
17+
def get_glob_matcher(pattern: str) -> Callable[[str], bool]:
18+
if pattern.startswith('/'):
19+
pattern = pattern[1:]
20+
else:
21+
pattern = '**/' + pattern
22+
23+
expr_string = r'\A'
24+
for component in pattern.split('/'):
25+
if component == '':
26+
pass
27+
elif component == '*':
28+
# Component must not be empty.
29+
expr_string += r'(?:[^/])+' + '/'
30+
elif component == '**':
31+
expr_string += r'(?:.*(?:\Z|/))?'
32+
elif '**' in component:
33+
raise ValueError("Invalid pattern: '**' can only be an entire path component")
34+
else:
35+
for part in GLOB_RE.split(component):
36+
if part == '':
37+
pass
38+
elif part == '*':
39+
expr_string += r'(?:[^/])*'
40+
elif part == '?':
41+
expr_string += r'(?:[^/])'
42+
elif part[0] == '[':
43+
expr_string += part
44+
else:
45+
expr_string += re.escape(part)
46+
expr_string += '/'
47+
48+
expr_string = expr_string.rstrip('/') + r'\Z'
49+
expr = re.compile(expr_string)
50+
51+
return lambda path: (expr.search(path) is not None)

0 commit comments

Comments
 (0)