From 355f1a1d2dbc423f1bacc9750c73b24b7a5fcbd6 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 9 Nov 2008 05:53:52 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- method/numbers.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/method/numbers.py b/method/numbers.py index 875ecca..14d8c75 100644 --- a/method/numbers.py +++ b/method/numbers.py @@ -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)') -def find_next_number(w): +def find_next_number(w, offset=0): b = w.buffer x, y = w.logical_cursor().xy() + x += offset while y < len(b.lines): m = num_re.search(b.lines[y], x) if m: @@ -15,6 +16,20 @@ def find_next_number(w): x = 0 y += 1 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): if s.startswith('0x'): @@ -24,6 +39,19 @@ def get_converter(s): else: 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): '''Increment the next number''' def _execute(self, w, **vargs):