-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlazycomment.py
More file actions
37 lines (31 loc) · 1.44 KB
/
lazycomment.py
File metadata and controls
37 lines (31 loc) · 1.44 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
import sublime, sublime_plugin
# Extends TextCommand so that run() receives a View to modify.
class StuCommand(sublime_plugin.TextCommand):
def run(self, edit):
def on_done(input_string):
#self.view.run_command("move_to", {"to": "bof"})
transf = transform_string(input_string.strip())
self.view.run_command("insert", {"characters": transf})
def on_change(input_string):
print("Input changed: %s" % input_string)
def on_cancel():
print("User cancelled the input")
def transform_string(transform):
textLen = len(transform)
neededDash = (78 - textLen) / 2
return '# ' + transform + ' ' + " ".join("-"*int(neededDash) + '\n')
for region in self.view.sel():
if not region.empty():
# Get the selected text
s = self.view.substr(region)
s = s.strip()
transf = transform_string(s)
# Replace the selection with transformed text
self.view.replace(edit, region, transf)
self.view.sel().clear()
(row,col) = self.view.rowcol(region.end())
print(row)
self.view.run_command("goto_line", {"line": row+2})
if region.empty():
window = self.view.window()
window.show_input_panel("Text to Insert:", "", on_done, on_change, on_cancel)