3
3
from orgmode import echo , ORGMODE , apply_count
4
4
from orgmode .menu import Submenu , ActionEntry
5
5
from orgmode .keybinding import Keybinding , MODE_VISUAL , MODE_OPERATOR , Plug
6
- from liborgmode import DIRECTION_FORWARD , DIRECTION_BACKWARD
6
+ from liborgmode import Direction
7
7
8
8
import vim
9
9
@@ -41,7 +41,7 @@ def parent(cls, mode):
41
41
p = heading .parent
42
42
43
43
if mode == u'visual' :
44
- cls ._change_visual_selection (heading , p , direction = DIRECTION_BACKWARD , parent = True )
44
+ cls ._change_visual_selection (heading , p , direction = Direction . BACKWARD , parent = True )
45
45
else :
46
46
vim .current .window .cursor = (p .start_vim , p .level + 1 )
47
47
return p
@@ -72,15 +72,15 @@ def parent_next_sibling(cls, mode):
72
72
ns = heading .parent .next_sibling
73
73
74
74
if mode == u'visual' :
75
- cls ._change_visual_selection (heading , ns , direction = DIRECTION_FORWARD , parent = False )
75
+ cls ._change_visual_selection (heading , ns , direction = Direction . FORWARD , parent = False )
76
76
elif mode == u'operator' :
77
77
vim .current .window .cursor = (ns .start_vim , 0 )
78
78
else :
79
79
vim .current .window .cursor = (ns .start_vim , ns .level + 1 )
80
80
return ns
81
81
82
82
@classmethod
83
- def _change_visual_selection (cls , current_heading , heading , direction = DIRECTION_FORWARD , noheadingfound = False , parent = False ):
83
+ def _change_visual_selection (cls , current_heading , heading , direction = Direction . FORWARD , noheadingfound = False , parent = False ):
84
84
current = vim .current .window .cursor [0 ]
85
85
line_start , col_start = [ int (i ) for i in vim .eval (u'getpos("\' <")' .encode (u'utf-8' ))[1 :3 ] ]
86
86
line_end , col_end = [ int (i ) for i in vim .eval (u'getpos("\' >")' .encode (u'utf-8' ))[1 :3 ] ]
@@ -92,7 +92,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
92
92
# << |visual start
93
93
# selection end >>
94
94
if current == line_start :
95
- if (direction == DIRECTION_FORWARD and line_end < f_start ) or noheadingfound and not direction == DIRECTION_BACKWARD :
95
+ if (direction == Direction . FORWARD and line_end < f_start ) or noheadingfound and not direction == Direction . BACKWARD :
96
96
swap_cursor = False
97
97
98
98
# focus heading HERE
@@ -102,7 +102,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
102
102
# << |visual start
103
103
# focus heading HERE
104
104
# selection end >>
105
- if f_start < line_start and direction == DIRECTION_BACKWARD :
105
+ if f_start < line_start and direction == Direction . BACKWARD :
106
106
if current_heading .start_vim < line_start and not parent :
107
107
line_start = current_heading .start_vim
108
108
else :
@@ -115,7 +115,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
115
115
# selection end >>
116
116
# focus heading HERE
117
117
else :
118
- if direction == DIRECTION_FORWARD :
118
+ if direction == Direction . FORWARD :
119
119
if line_end < f_start and not line_start == f_start - 1 and current_heading :
120
120
# focus end of previous heading instead of beginning of next heading
121
121
line_start = line_end
@@ -124,7 +124,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
124
124
# focus end of next heading
125
125
line_start = line_end
126
126
line_end = f_end
127
- elif direction == DIRECTION_BACKWARD :
127
+ elif direction == Direction . BACKWARD :
128
128
if line_end < f_end :
129
129
pass
130
130
else :
@@ -142,7 +142,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
142
142
swap_cursor = False
143
143
144
144
elif (line_start > f_start or \
145
- line_start == f_start ) and line_end <= f_end and direction == DIRECTION_BACKWARD :
145
+ line_start == f_start ) and line_end <= f_end and direction == Direction . BACKWARD :
146
146
line_end = line_start
147
147
line_start = f_start
148
148
@@ -157,7 +157,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
157
157
# selection end| >>
158
158
# focus heading HERE
159
159
else :
160
- if direction == DIRECTION_FORWARD :
160
+ if direction == Direction . FORWARD :
161
161
if line_end < f_start - 1 :
162
162
# focus end of previous heading instead of beginning of next heading
163
163
line_end = f_start - 1
@@ -176,7 +176,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
176
176
(line_start , move_col_start , vim .eval (u'visualmode()' .encode (u'utf-8' )), line_end , move_col_end , swap )).encode (u'utf-8' ))
177
177
178
178
@classmethod
179
- def _focus_heading (cls , mode , direction = DIRECTION_FORWARD , skip_children = False ):
179
+ def _focus_heading (cls , mode , direction = Direction . FORWARD , skip_children = False ):
180
180
u"""
181
181
Focus next or previous heading in the given direction
182
182
@@ -190,7 +190,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
190
190
# FIXME this is just a piece of really ugly and unmaintainable code. It
191
191
# should be rewritten
192
192
if not heading :
193
- if direction == DIRECTION_FORWARD and d .headings \
193
+ if direction == Direction . FORWARD and d .headings \
194
194
and vim .current .window .cursor [0 ] < d .headings [0 ].start_vim :
195
195
# the cursor is in the meta information are, therefore focus
196
196
# first heading
@@ -202,7 +202,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
202
202
else :
203
203
echo (u'No heading found' )
204
204
return
205
- elif direction == DIRECTION_BACKWARD :
205
+ elif direction == Direction . BACKWARD :
206
206
if vim .current .window .cursor [0 ] != heading .start_vim :
207
207
# the cursor is in the body of the current heading, therefore
208
208
# the current heading will be focused
@@ -216,17 +216,17 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
216
216
217
217
# so far no heading has been found that the next focus should be on
218
218
if not focus_heading :
219
- if not skip_children and direction == DIRECTION_FORWARD and heading .children :
219
+ if not skip_children and direction == Direction . FORWARD and heading .children :
220
220
focus_heading = heading .children [0 ]
221
- elif direction == DIRECTION_FORWARD and heading .next_sibling :
221
+ elif direction == Direction . FORWARD and heading .next_sibling :
222
222
focus_heading = heading .next_sibling
223
- elif direction == DIRECTION_BACKWARD and heading .previous_sibling :
223
+ elif direction == Direction . BACKWARD and heading .previous_sibling :
224
224
focus_heading = heading .previous_sibling
225
225
if not skip_children :
226
226
while focus_heading .children :
227
227
focus_heading = focus_heading .children [- 1 ]
228
228
else :
229
- if direction == DIRECTION_FORWARD :
229
+ if direction == Direction . FORWARD :
230
230
focus_heading = current_heading .next_heading
231
231
else :
232
232
focus_heading = current_heading .previous_heading
@@ -239,7 +239,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
239
239
focus_heading = heading
240
240
noheadingfound = True
241
241
else :
242
- if direction == DIRECTION_FORWARD :
242
+ if direction == Direction . FORWARD :
243
243
echo (u'Already focussing last heading' )
244
244
else :
245
245
echo (u'Already focussing first heading' )
@@ -248,7 +248,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
248
248
if mode == u'visual' :
249
249
cls ._change_visual_selection (current_heading , focus_heading , direction = direction , noheadingfound = noheadingfound )
250
250
elif mode == u'operator' :
251
- if direction == DIRECTION_FORWARD and vim .current .window .cursor [0 ] >= focus_heading .start_vim :
251
+ if direction == Direction . FORWARD and vim .current .window .cursor [0 ] >= focus_heading .start_vim :
252
252
vim .current .window .cursor = (focus_heading .end_vim , len (vim .current .buffer [focus_heading .end ].decode (u'utf-8' )))
253
253
else :
254
254
vim .current .window .cursor = (focus_heading .start_vim , 0 )
@@ -264,15 +264,15 @@ def previous(cls, mode, skip_children=False):
264
264
u"""
265
265
Focus previous heading
266
266
"""
267
- return cls ._focus_heading (mode , direction = DIRECTION_BACKWARD , skip_children = skip_children )
267
+ return cls ._focus_heading (mode , direction = Direction . BACKWARD , skip_children = skip_children )
268
268
269
269
@classmethod
270
270
@apply_count
271
271
def next (cls , mode , skip_children = False ):
272
272
u"""
273
273
Focus next heading
274
274
"""
275
- return cls ._focus_heading (mode , direction = DIRECTION_FORWARD , skip_children = skip_children )
275
+ return cls ._focus_heading (mode , direction = Direction . FORWARD , skip_children = skip_children )
276
276
277
277
def register (self ):
278
278
# normal mode
0 commit comments