This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NextBracket.py
63 lines (45 loc) · 1.89 KB
/
NextBracket.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
import sublime;
import sublime_plugin;
class NextBracketCommand(sublime_plugin.TextCommand):
def run(self, edit, forward):
newPoint = None;
if forward:
newPoint = self.__findNextBracket();
else:
newPoint = self.__findPreviousBracket();
if newPoint:
self.view.sel().clear();
self.view.sel().add(sublime.Region(newPoint.end()));
self.view.show(newPoint);
def __findNextBracket(self):
allBracketPoints = self.view.find_all(self.__getRegex());
result = None;
for potentialPoint in allBracketPoints:
if self.view.rowcol(potentialPoint.begin())[0] > self.__getCaretLine():
if result == None or self.view.rowcol(potentialPoint.begin())[0] == self.view.rowcol(result.begin())[0]:
result = potentialPoint;
else:
break;
return result;
def __findPreviousBracket(self):
allBracketPoints = self.view.find_all(self.__getRegex());
result = None;
for potentialPoint in reversed(allBracketPoints):
if self.view.rowcol(potentialPoint.begin())[0] < self.__getCaretLine():
result = potentialPoint;
break;
return result;
def __getCaretLine(self):
return self.view.rowcol(self.view.sel()[0].begin())[0];
def __getRegex(self):
settings = sublime.load_settings("NextBracket.sublime-settings");
regex = "[";
if settings.get('include_square_brackets'):
regex = regex + "\\[\\]"
if settings.get('include_round_brackets'):
regex = regex + "{}"
if settings.get('include_curly_brackets'):
regex = regex + "()"
if settings.get('include_angle_brackets'):
regex = regex + "<>"
return regex + "]"