Skip to content

Commit f54c236

Browse files
committed
Merge commit '481b52767988253ac67bb6c65be9f08e2977cd73' into v0.4
2 parents 9e73736 + 481b527 commit f54c236

File tree

7 files changed

+115
-80
lines changed

7 files changed

+115
-80
lines changed

Diff for: ftplugin/liborgmode.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import re
44
from UserList import UserList
55

6-
DIRECTION_FORWARD = True
7-
DIRECTION_BACKWARD = False
6+
class Direction():
7+
FORWARD = 1
8+
BACKWARD = 2
9+
810

911
def flatten_list(l):
1012
res = []
@@ -1028,13 +1030,13 @@ def all_headings(self):
10281030
h = h.next_heading
10291031
raise StopIteration()
10301032

1031-
def find_heading(self, position=0, direction=DIRECTION_FORWARD, \
1033+
def find_heading(self, position=0, direction=Direction.FORWARD, \
10321034
heading=Heading, connect_with_document=True):
10331035
u""" Find heading in the given direction
10341036
1035-
:postition: starting line, counting from 0 (in vim you start counting from 1, don't forget)
1036-
:direction: downwards == DIRECTION_FORWARD, upwards == DIRECTION_BACKWARD
1037-
:heading: Heading class from which new heading objects will be instanciated
1037+
:postition: starting line, counting from 0 (in vim you start counting from 1, don't forget)
1038+
:direction: downwards == Direction.FORWARD, upwards == Direction.BACKWARD
1039+
:heading: Heading class from which new heading objects will be instanciated
10381040
:connect_with_document: if True, the newly created heading will be connected with the document, otherwise not
10391041
10401042
:returns: New heading object or None
@@ -1049,7 +1051,7 @@ def find_heading(self, position=0, direction=DIRECTION_FORWARD, \
10491051
end = None
10501052

10511053
# Search heading upwards
1052-
if direction == DIRECTION_FORWARD:
1054+
if direction == Direction.FORWARD:
10531055
while tmp_line < len_cb:
10541056
if heading.identify_heading(self._content[tmp_line]) is not None:
10551057
if start is None:

Diff for: ftplugin/orgmode/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from orgmode.document import VimBuffer
1414
from orgmode.exceptions import PluginError
1515

16-
from liborgmode import DIRECTION_FORWARD, DIRECTION_BACKWARD
16+
from liborgmode import Direction
17+
1718

1819
REPEAT_EXISTS = bool(int(vim.eval('exists("*repeat#set()")')))
1920
TAGSPROPERTIES_EXISTS = False

Diff for: ftplugin/orgmode/document.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from exceptions import BufferNotFound, BufferNotInSync
4-
from liborgmode import Document, Heading, MultiPurposeList, DIRECTION_BACKWARD
4+
from liborgmode import Document, Heading, MultiPurposeList, Direction
55
import settings
66
import vim
77
from UserList import UserList
@@ -304,7 +304,7 @@ def write_heading(self, heading, including_children=True):
304304
# Retrieve a potentially dirty document
305305
d = ORGMODE.get_document(allow_dirty=True)
306306
# Don't rely on the DOM, retrieve the heading afresh
307-
h = d.find_heading(direction=DIRECTION_FORWARD, position=100)
307+
h = d.find_heading(direction=Direction.FORWARD, position=100)
308308
# Update tags
309309
h.tags = ['tag1', 'tag2']
310310
# Write the heading
@@ -380,5 +380,5 @@ def find_current_heading(self, position=None, heading=Heading):
380380
"""
381381
return self.find_heading(vim.current.window.cursor[0] - 1 \
382382
if position is None else position, \
383-
direction=DIRECTION_BACKWARD, heading=heading, \
383+
direction=Direction.BACKWARD, heading=heading, \
384384
connect_with_document=False)

Diff for: ftplugin/orgmode/plugins/EditStructure.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3-
from orgmode import ORGMODE, apply_count, repeat, realign_tags, DIRECTION_FORWARD, DIRECTION_BACKWARD
3+
from orgmode import ORGMODE, apply_count, repeat, realign_tags
4+
from orgmode import Direction
45
from orgmode.menu import Submenu, Separator, ActionEntry
56
from orgmode.keybinding import Keybinding, Plug, MODE_INSERT, MODE_NORMAL
67
from liborgmode import Heading
@@ -258,16 +259,16 @@ def promote_heading(cls, including_children=True, on_heading=False, insert_mode=
258259
return u'OrgPromoteHeadingNormal'
259260

260261
@classmethod
261-
def _move_heading(cls, direction=DIRECTION_FORWARD, including_children=True):
262+
def _move_heading(cls, direction=Direction.FORWARD, including_children=True):
262263
u""" Move heading up or down
263264
264265
:returns: heading or None
265266
"""
266267
d = ORGMODE.get_document()
267268
heading = d.current_heading()
268269
if (not heading) or \
269-
(direction == DIRECTION_FORWARD and not heading.next_sibling) or \
270-
(direction == DIRECTION_BACKWARD and not heading.previous_sibling):
270+
(direction == Direction.FORWARD and not heading.next_sibling) or \
271+
(direction == Direction.BACKWARD and not heading.previous_sibling):
271272
return None
272273

273274
cursor_offset_within_the_heading_vim = vim.current.window.cursor[0] - (heading._orig_start + 1)
@@ -276,7 +277,7 @@ def _move_heading(cls, direction=DIRECTION_FORWARD, including_children=True):
276277
heading.previous_sibling.children.extend(heading.children)
277278
del heading.children
278279

279-
heading_insert_position = 0 if direction == DIRECTION_FORWARD else -1
280+
heading_insert_position = 0 if direction == Direction.FORWARD else -1
280281
l = heading.get_parent_list()
281282
idx = heading.get_index_in_parent_list()
282283
del l[idx]
@@ -295,14 +296,14 @@ def _move_heading(cls, direction=DIRECTION_FORWARD, including_children=True):
295296
@repeat
296297
@apply_count
297298
def move_heading_upward(cls, including_children=True):
298-
if cls._move_heading(direction=DIRECTION_BACKWARD, including_children=including_children):
299+
if cls._move_heading(direction=Direction.BACKWARD, including_children=including_children):
299300
return u'OrgMoveHeadingUpward'
300301

301302
@classmethod
302303
@repeat
303304
@apply_count
304305
def move_heading_downward(cls, including_children=True):
305-
if cls._move_heading(direction=DIRECTION_FORWARD, including_children=including_children):
306+
if cls._move_heading(direction=Direction.FORWARD, including_children=including_children):
306307
return u'OrgMoveHeadingDownward'
307308

308309
def register(self):

Diff for: ftplugin/orgmode/plugins/Navigator.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from orgmode import echo, ORGMODE, apply_count
44
from orgmode.menu import Submenu, ActionEntry
55
from orgmode.keybinding import Keybinding, MODE_VISUAL, MODE_OPERATOR, Plug
6-
from liborgmode import DIRECTION_FORWARD, DIRECTION_BACKWARD
6+
from liborgmode import Direction
77

88
import vim
99

@@ -41,7 +41,7 @@ def parent(cls, mode):
4141
p = heading.parent
4242

4343
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)
4545
else:
4646
vim.current.window.cursor = (p.start_vim, p.level + 1)
4747
return p
@@ -72,15 +72,15 @@ def parent_next_sibling(cls, mode):
7272
ns = heading.parent.next_sibling
7373

7474
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)
7676
elif mode == u'operator':
7777
vim.current.window.cursor = (ns.start_vim, 0)
7878
else:
7979
vim.current.window.cursor = (ns.start_vim, ns.level + 1)
8080
return ns
8181

8282
@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):
8484
current = vim.current.window.cursor[0]
8585
line_start, col_start = [ int(i) for i in vim.eval(u'getpos("\'<")'.encode(u'utf-8'))[1:3] ]
8686
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_
9292
# << |visual start
9393
# selection end >>
9494
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:
9696
swap_cursor = False
9797

9898
# focus heading HERE
@@ -102,7 +102,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
102102
# << |visual start
103103
# focus heading HERE
104104
# selection end >>
105-
if f_start < line_start and direction == DIRECTION_BACKWARD:
105+
if f_start < line_start and direction == Direction.BACKWARD:
106106
if current_heading.start_vim < line_start and not parent:
107107
line_start = current_heading.start_vim
108108
else:
@@ -115,7 +115,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
115115
# selection end >>
116116
# focus heading HERE
117117
else:
118-
if direction == DIRECTION_FORWARD:
118+
if direction == Direction.FORWARD:
119119
if line_end < f_start and not line_start == f_start - 1 and current_heading:
120120
# focus end of previous heading instead of beginning of next heading
121121
line_start = line_end
@@ -124,7 +124,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
124124
# focus end of next heading
125125
line_start = line_end
126126
line_end = f_end
127-
elif direction == DIRECTION_BACKWARD:
127+
elif direction == Direction.BACKWARD:
128128
if line_end < f_end:
129129
pass
130130
else:
@@ -142,7 +142,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
142142
swap_cursor = False
143143

144144
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:
146146
line_end = line_start
147147
line_start = f_start
148148

@@ -157,7 +157,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
157157
# selection end| >>
158158
# focus heading HERE
159159
else:
160-
if direction == DIRECTION_FORWARD:
160+
if direction == Direction.FORWARD:
161161
if line_end < f_start - 1:
162162
# focus end of previous heading instead of beginning of next heading
163163
line_end = f_start - 1
@@ -176,7 +176,7 @@ def _change_visual_selection(cls, current_heading, heading, direction=DIRECTION_
176176
(line_start, move_col_start, vim.eval(u'visualmode()'.encode(u'utf-8')), line_end, move_col_end, swap)).encode(u'utf-8'))
177177

178178
@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):
180180
u"""
181181
Focus next or previous heading in the given direction
182182
@@ -190,7 +190,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
190190
# FIXME this is just a piece of really ugly and unmaintainable code. It
191191
# should be rewritten
192192
if not heading:
193-
if direction == DIRECTION_FORWARD and d.headings \
193+
if direction == Direction.FORWARD and d.headings \
194194
and vim.current.window.cursor[0] < d.headings[0].start_vim:
195195
# the cursor is in the meta information are, therefore focus
196196
# first heading
@@ -202,7 +202,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
202202
else:
203203
echo(u'No heading found')
204204
return
205-
elif direction == DIRECTION_BACKWARD:
205+
elif direction == Direction.BACKWARD:
206206
if vim.current.window.cursor[0] != heading.start_vim:
207207
# the cursor is in the body of the current heading, therefore
208208
# the current heading will be focused
@@ -216,17 +216,17 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
216216

217217
# so far no heading has been found that the next focus should be on
218218
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:
220220
focus_heading = heading.children[0]
221-
elif direction == DIRECTION_FORWARD and heading.next_sibling:
221+
elif direction == Direction.FORWARD and heading.next_sibling:
222222
focus_heading = heading.next_sibling
223-
elif direction == DIRECTION_BACKWARD and heading.previous_sibling:
223+
elif direction == Direction.BACKWARD and heading.previous_sibling:
224224
focus_heading = heading.previous_sibling
225225
if not skip_children:
226226
while focus_heading.children:
227227
focus_heading = focus_heading.children[-1]
228228
else:
229-
if direction == DIRECTION_FORWARD:
229+
if direction == Direction.FORWARD:
230230
focus_heading = current_heading.next_heading
231231
else:
232232
focus_heading = current_heading.previous_heading
@@ -239,7 +239,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
239239
focus_heading = heading
240240
noheadingfound = True
241241
else:
242-
if direction == DIRECTION_FORWARD:
242+
if direction == Direction.FORWARD:
243243
echo(u'Already focussing last heading')
244244
else:
245245
echo(u'Already focussing first heading')
@@ -248,7 +248,7 @@ def _focus_heading(cls, mode, direction=DIRECTION_FORWARD, skip_children=False):
248248
if mode == u'visual':
249249
cls._change_visual_selection(current_heading, focus_heading, direction=direction, noheadingfound=noheadingfound)
250250
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:
252252
vim.current.window.cursor = (focus_heading.end_vim, len(vim.current.buffer[focus_heading.end].decode(u'utf-8')))
253253
else:
254254
vim.current.window.cursor = (focus_heading.start_vim, 0)
@@ -264,15 +264,15 @@ def previous(cls, mode, skip_children=False):
264264
u"""
265265
Focus previous heading
266266
"""
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)
268268

269269
@classmethod
270270
@apply_count
271271
def next(cls, mode, skip_children=False):
272272
u"""
273273
Focus next heading
274274
"""
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)
276276

277277
def register(self):
278278
# normal mode

0 commit comments

Comments
 (0)