Repository navigation
Expand file tree
/
Copy pathHTMLNestComments.py
More file actions
164 lines (158 loc) · 7.29 KB
/
Copy pathHTMLNestComments.py
File metadata and controls
164 lines (158 loc) · 7.29 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import sublime, sublime_plugin
class NestCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
continue
text = self.view.substr(region)
fileExt = self.view.window().extract_variables()['file_extension']
current_scope = self.view.scope_name(self.view.sel()[0].b) # embedding.php text.html.basic
print (current_scope)
# elif (current_scope == 'embedding.php text.html.basic'):
# print (current_scope == 'embedding.php text.html.basic')
# print ('embedding.php text.html.basic' in current_scope)
# print ('embedding.php' in current_scope)
# print ('text.html.basic' in current_scope)
strange_scope = 'text.html.basic source.js.embedded.html source.js meta.block.js meta.conditional.js meta.block.js'
strange_scope_php = 'embedding.php text.html.basic meta.embedded.block.php source.php meta.function.php meta.block.php'
strange_scope_js = 'text.html.basic source.js.embedded.html source.js meta.block.js meta.object-literal.js meta.object-literal.js'
strange_scope_css = 'text.html.basic source.css.embedded.html source.css'
if (((strange_scope in current_scope) and ('html' in fileExt) and ('source.php' not in current_scope)) or
((strange_scope_php in current_scope) and ('php' in fileExt)) or
((strange_scope_js in current_scope) and ('html' in fileExt)) or
((strange_scope_css in current_scope) and ('html' in fileExt)) ):
if text.startswith("/*"):
# print('Uncomment Please')
text = text[2:]
text = text[:-2]
text = text.replace('<~?', '<?')
text = text.replace('?~>', '?>')
text = text.replace('/~*', '/*')
text = text.replace('*~/', '*/')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
text = text.replace('<?', '<~?')
text = text.replace('?>', '?~>')
text = text.replace('/*', '/~*')
text = text.replace('*/', '*~/')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "/*")
self.view.insert(edit, self.view.sel()[0].end(), "*/")
elif ('embedding.php text.html.basic' in current_scope) and ('php' in fileExt) and ('source.php' not in current_scope):
# elif (current_scope == 'embedding.php text.html.basic'):
if text.startswith("<!--"):
# print('Uncomment Please')
text = text[4:]
text = text[:-3]
text = text.replace('<~?', '<?')
text = text.replace('?~>', '?>')
text = text.replace('<!~~', '<!--')
text = text.replace('~~>', '-->')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
text = text.replace('<?', '<~?')
text = text.replace('?>', '?~>')
text = text.replace('<!--', '<!~~')
text = text.replace('-->', '~~>')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "<!--")
self.view.insert(edit, self.view.sel()[0].end(), "-->")
elif ('php' in fileExt) or ('class.php' in fileExt):
if text.startswith("/*"):
# print('Uncomment Please')
text = text[2:]
text = text[:-2]
text = text.replace('<~?', '<?')
text = text.replace('?~>', '?>')
text = text.replace('/~*', '/*')
text = text.replace('*~/', '*/')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
text = text.replace('<?', '<~?')
text = text.replace('?>', '?~>')
text = text.replace('/*', '/~*')
text = text.replace('*/', '*~/')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "/*")
self.view.insert(edit, self.view.sel()[0].end(), "*/")
elif 'css' in fileExt:
if text.startswith("/*"):
# print('Uncomment Please')
text = text[2:]
text = text[:-2]
text = text.replace('<~?', '<?')
text = text.replace('?~>', '?>')
text = text.replace('/~*', '/*')
text = text.replace('*~/', '*/')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
text = text.replace('<?', '<~?')
text = text.replace('?>', '?~>')
text = text.replace('/*', '/~*')
text = text.replace('*/', '*~/')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "/*")
self.view.insert(edit, self.view.sel()[0].end(), "*/")
elif 'js' in fileExt:
if text.startswith("/*"):
# print('Uncomment Please')
text = text[2:]
text = text[:-2]
text = text.replace('<~?', '<?')
text = text.replace('?~>', '?>')
text = text.replace('/~*', '/*')
text = text.replace('*~/', '*/')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
text = text.replace('<?', '<~?')
text = text.replace('?>', '?~>')
text = text.replace('/*', '/~*')
text = text.replace('*/', '*~/')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "/*")
self.view.insert(edit, self.view.sel()[0].end(), "*/")
# else:
elif 'html' in fileExt:
if text.startswith("<!--"):
# print('Uncomment Please')
text = text[4:]
text = text[:-3]
text = text.replace('<~?', '<?')
text = text.replace('?~>', '?>')
text = text.replace('<!~~', '<!--')
text = text.replace('~~>', '-->')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
text = text.replace('<?', '<~?')
text = text.replace('?>', '?~>')
text = text.replace('<!--', '<!~~')
text = text.replace('-->', '~~>')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "<!--")
self.view.insert(edit, self.view.sel()[0].end(), "-->")
else:
if text.startswith("/*"):
# print('Uncomment Please')
text = text[2:]
text = text[:-2]
# text = text.replace('<~?', '<?')
# text = text.replace('?~>', '?>')
text = text.replace('/~*', '/*')
text = text.replace('*~/', '*/')
self.view.replace(edit, region, text)
else:
# print('Comment these nested comments')
# text = text.replace('<?', '<~?')
# text = text.replace('?>', '?~>')
text = text.replace('/*', '/~*')
text = text.replace('*/', '*~/')
self.view.replace(edit, region, text)
self.view.insert(edit, self.view.sel()[0].begin(), "/*")
self.view.insert(edit, self.view.sel()[0].end(), "*/")
#http://www.sublimetext.com/forum/viewtopic.php?f=6&t=10984