This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.py
77 lines (56 loc) · 2.13 KB
/
commands.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
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
# encoding: utf-8
import sublime, sublime_plugin
import re
try:
from . import util
except ValueError:
import util
class IndentVariableCommand(sublime_plugin.TextCommand):
"""Indent the region and increase any variable levels."""
def run(self, edit):
self.view.run_command('indent')
for region in self.view.sel():
for line in self.view.lines(region):
util.update_var_levels(self.view, edit, line, amount=+1)
def description(self):
return 'Indent Variable'
class UnindentVariableCommand(sublime_plugin.TextCommand):
"""Unindent the region and decrease any variable levels."""
def run(self, edit):
self.view.run_command('unindent')
for region in self.view.sel():
for line in self.view.lines(region):
util.update_var_levels(self.view, edit, line, amount=-1)
def description(self):
return 'Unindent Variable'
class CommentEmptyLines(sublime_plugin.TextCommand):
"""Fill all empty lines with an asterisk, so that the file won't get
squashed when opened in the SPOD editor."""
def run(self, edit):
last_point = 0
while True:
empty_line = self.view.find('^\s*\R', last_point)
if not empty_line:
break
self.view.replace(edit, empty_line, u'*\n')
last_point = empty_line.end()
def is_enabled(self):
return util.is_natural_file(self.view)
def is_visible(self):
return util.is_natural_file(self.view)
def description(self):
return "Comment Empty Lines"
class UncommentEmptyLines(sublime_plugin.TextCommand):
"""Uncomment all empty lines to make it resemble a sane source file."""
def run(self, edit):
while True:
empty_line = self.view.find('^\*\s*\R', 0)
if not empty_line:
break
self.view.replace(edit, empty_line, u'\n')
def is_enabled(self):
return util.is_natural_file(self.view)
def is_visible(self):
return util.is_natural_file(self.view)
def description(self):
return "Uncomment Empty Lines"