forked from guillermooo/Vintageous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformers.py
45 lines (35 loc) · 1.46 KB
/
transformers.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
import sublime
import sublime_plugin
from Vintageous.vi.constants import regions_transformer
from Vintageous.vi.utils import back_one_char
from Vintageous.vi.utils import forward_one_char
from Vintageous.vi.utils import is_at_bol
from Vintageous.vi.utils import is_at_eol
from Vintageous.vi.utils import is_at_hard_eol
from Vintageous.vi.utils import is_line_empty
from Vintageous.vi.utils import is_on_empty_line
from Vintageous.vi.utils import next_non_white_space_char
class ClipEndToLine(sublime_plugin.TextCommand):
def run(self, edit):
def f(view, s):
if not is_on_empty_line(self.view, s) and is_at_eol(self.view, s):
return back_one_char(s)
else:
return s
regions_transformer(self.view, f)
class DontStayOnEolBackward(sublime_plugin.TextCommand):
def run(self, edit, **kwargs):
def f(view, s):
if is_at_eol(self.view, s) and not self.view.line(s.b).empty():
return back_one_char(s)
else:
return s
regions_transformer(self.view, f)
class _vi_d_post_action(sublime_plugin.TextCommand):
def run(self, edit, **kwargs):
def f(view, s):
if is_at_eol(self.view, s) and not self.view.line(s.b).empty():
s = back_one_char(s)
# s = next_non_white_space_char(self.view, s.b)
return s
regions_transformer(self.view, f)