-
Notifications
You must be signed in to change notification settings - Fork 41
/
subcomments.py
30 lines (24 loc) · 923 Bytes
/
subcomments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def get_comment(view, pt):
"""
Ripped from Sublime's Default.comment.py to find comment convention
"""
shell_vars = view.meta_info("shellVariables", pt)
if not shell_vars:
return ([], [])
# transform the list of dicts into a single dict
all_vars = {}
for v in shell_vars:
if 'name' in v and 'value' in v:
all_vars[v['name']] = v['value']
line_comments = []
block_comments = []
# transform the dict into a single array of valid comments
suffixes = [""] + ["_" + str(i) for i in range(1, 10)]
for suffix in suffixes:
start = all_vars.setdefault("TM_COMMENT_START" + suffix)
end = all_vars.setdefault("TM_COMMENT_END" + suffix)
if start and end is None:
line_comments.append((start,))
elif start and end:
block_comments.append((start, end))
return (line_comments, block_comments)