branch : pmacs2
This commit is contained in:
moculus 2008-11-09 05:53:52 +00:00
parent 714705ec7c
commit 355f1a1d2d
1 changed files with 29 additions and 1 deletions

View File

@ -5,9 +5,10 @@ from method import Method, Argument
num_re = re.compile(r'(?:-?[1-9][0-9]*|0x[0-9A-Fa-f]+|0[0-7]+|0)') num_re = re.compile(r'(?:-?[1-9][0-9]*|0x[0-9A-Fa-f]+|0[0-7]+|0)')
def find_next_number(w): def find_next_number(w, offset=0):
b = w.buffer b = w.buffer
x, y = w.logical_cursor().xy() x, y = w.logical_cursor().xy()
x += offset
while y < len(b.lines): while y < len(b.lines):
m = num_re.search(b.lines[y], x) m = num_re.search(b.lines[y], x)
if m: if m:
@ -15,6 +16,20 @@ def find_next_number(w):
x = 0 x = 0
y += 1 y += 1
return (None, None) return (None, None)
def find_prev_number(w, offset=0):
b = w.buffer
x, y = w.logical_cursor().xy()
x += offset
while y >= 0:
m = m2 = num_re.search(b.lines[y], 0, x)
while m2:
m = m2
m2 = num_re.search(b.lines[y], m2.end(), x)
if m:
return (Point(m.start(), y), Point(m.end(), y))
y -= 1
x = len(b.lines[y])
return (None, None)
def get_converter(s): def get_converter(s):
if s.startswith('0x'): if s.startswith('0x'):
@ -24,6 +39,19 @@ def get_converter(s):
else: else:
return str return str
class GotoPrevNumber(Method):
'''Move the cursor to the start of the word to the right'''
def _execute(self, w, **vargs):
(p1, p2) = find_prev_number(w, -1)
if p1 is not None:
w.goto(p1)
class GotoNextNumber(Method):
def _execute(self, w, **vargs):
(p1, p2) = find_next_number(w, 1)
if p1 is not None:
w.goto(p2.add(-1, 0))
class Increment(Method): class Increment(Method):
'''Increment the next number''' '''Increment the next number'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):