forked from odyssomay/paredit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
movement_navigation.py
60 lines (45 loc) · 1.35 KB
/
movement_navigation.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
import sublime, sublime_plugin
try:
from paredit import shared
except:
import shared
def paredit_move(view, edit, direction):
def f(region):
if not region.a == region.b:
return region
point = region.a
if shared.is_inside_string(view, point):
(a, b) = shared.get_expression(view, point, direction)
target_point = shared.step(b, -1, direction)
if point == target_point:
return shared.step(point, 1, direction)
return shared.step(b, -1, direction)
if direction == "backward":
point -= 1
(word_a, word_b) = shared.get_word(view, point, direction)
if word_b:
return word_b
(next_a, next_b) = shared.get_next_expression(view, point, False, direction)
if next_b:
return next_b
expr_point = point
if direction == "backward":
expr_point += 1
(a, b) = shared.get_expression(view, expr_point, direction)
if b:
return b
if direction == "forward":
return shared.step(point, 1, direction)
else:
return point
shared.edit_selections(view, f)
def paredit_forward(view, edit):
paredit_move(view, edit, "forward")
def paredit_backward(view, edit):
paredit_move(view, edit, "backward")
class Paredit_forwardCommand(sublime_plugin.TextCommand):
def run(self, edit):
paredit_forward(self.view, edit)
class Paredit_backwardCommand(sublime_plugin.TextCommand):
def run(self, edit):
paredit_backward(self.view, edit)