-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheasymotion.py
More file actions
56 lines (48 loc) · 1.91 KB
/
easymotion.py
File metadata and controls
56 lines (48 loc) · 1.91 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sublime, sublime_plugin
from util.theme import change_em_theme, restore_theme_syntax
from util.char import restore_char, replace_char, jump, search_pair,\
FORWARD, BACKWARD
class CancelEasymotionCommand(sublime_plugin.TextCommand):
""" Turn off easy motion flag """
def run(self, edit):
view = self.view
settings = view.settings()
cancel_easymotion(edit, settings, view, False)
class EasyMotionCommand(sublime_plugin.TextCommand):
""" Turn on easy motion flag """
def run(self, edit, direct = FORWARD):
print('easy motion')
view = self.view
settings = view.settings()
settings.set('easy_motion', True)
settings.set('command_mode', False)
settings.set('easy_motion_command', direct)
change_em_theme(settings, view)
replace_char(view, edit, direct)
class EasyMotionJumpCommand(sublime_plugin.TextCommand):
""" Jump to char """
def run(self, edit, char = 'Z'):
view = self.view
settings = view.settings()
offset = search_pair(char)
cancel_easymotion(edit, settings, view, offset)
def cancel_easymotion(edit, settings, view, offset):
""" Turn off easymotion is required when both jump and cancel,
Abstract it to a single func."""
if typed_command(settings):
restore_theme_syntax(settings, view)
direct = settings.get('easy_motion_command')
region = restore_char(view, edit, direct)
if offset == None:
jump(view, region, 0 - direct)
else:
jump(view, region, offset)
settings.set('easy_motion_command', False)
settings.set('easy_motion', False)
settings.set('command_mode', True)
##########################################################
# Check State Func
def in_em(settings):
return settings.get('easy_motion')
def typed_command(settings):
return settings.get('easy_motion_command')