-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathodoo-tools.py
executable file
·66 lines (45 loc) · 1.69 KB
/
odoo-tools.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
import sublime, sublime_plugin
class DashesCommand(sublime_plugin.TextCommand):
_line_length = 79
_dash = '-'
_prefix = '# '
def run(self, edit):
if self._is_python():
for region in self.view.sel():
self._dash_line(edit, region)
def _dash_line(self, edit, region):
text = self.view.substr(region)
abs_begin = region.begin()
if text:
text = ' %s ' % text
line_begin = self.view.line(abs_begin).begin()
begin = abs_begin - line_begin
length = self._line_length - begin
ndashes = (length / 2) - (len(text) / 2)
fit = int(length % 2)
dashes_line = '{}{}{}{}'.format(
self._prefix,
self._dash * int(ndashes - len(self._prefix)),
text,
self._dash * int(ndashes + fit),
)[:length]
self.view.replace(edit, region, dashes_line.upper())
def _is_python(self):
sintax = self.view.settings().get('syntax')
return sintax == 'Packages/Python/Python.tmLanguage'
# -----------------------------------------------------------------------------
class FinddashesCommand(sublime_plugin.TextCommand):
_pattern = '^ *# ---.*---$'
def run(self, edit):
selection = self.view.sel()
region = selection[0]
found = self._find_next(region.begin())
if found:
selection.clear()
selection.add(sublime.Region(found.end()))
self.view.show(found.end())
def _find_next(self, pos):
found = self.view.find(self._pattern, pos)
if pos > 0 and not found:
found = self.view.find(self._pattern, 0)
return found