From 27b1a17e7b2f158ef0795bdb5ce93cd7538b0c79 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 20 Nov 2008 21:27:52 +0000 Subject: [PATCH] lowercase/uppercase, and some bug fixes --HG-- branch : pmacs2 --- method/__init__.py | 16 ++++++++++++++++ mode/__init__.py | 3 +++ mode/perl.py | 2 ++ window.py | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/method/__init__.py b/method/__init__.py index 526b0cb..e764bda 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -324,6 +324,22 @@ class DeleteRightSpace(Method): if p > c: w.delete(c, p) +# errata +class LowercaseWord(Method): + '''Lowercase all characters in word''' + def _execute(self, w, **vargs): + (p1, p2) = w.get_word_bounds() + word = w.buffer.get_substring(p1, p2) + w.delete(p1, p2) + w.insert_string(p1, word.lower()) +class UppercaseWord(Method): + '''Uppercase all characters in word''' + def _execute(self, w, **vargs): + (p1, p2) = w.get_word_bounds() + word = w.buffer.get_substring(p1, p2) + w.delete(p1, p2) + w.insert_string(p1, word.upper()) + class MetaX(Method): '''Invoke commands by name''' args = [arg('method', dt="method", p="M-x ", h='Method to execute')] diff --git a/mode/__init__.py b/mode/__init__.py index 7a3c909..f67f1b5 100644 --- a/mode/__init__.py +++ b/mode/__init__.py @@ -234,6 +234,9 @@ class Fundamental(Handler): self.add_bindings('increment', ('M-+',)) self.add_bindings('decrement', ('M--',)) + self.add_bindings('uppercase-word', ('M-u',)) + self.add_bindings('lowercase-word', ('M-l',)) + # used for all word operations if not self.word_letters: self.word_letters = w.application.config['word_letters'] diff --git a/mode/perl.py b/mode/perl.py index bfb4eb9..48ef3fd 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -525,6 +525,7 @@ class PerlOpenModule(method.Method): def _execute(self, w, **vargs): path = w.mode.find_module(vargs['module']) if path: + w.set_error("opening %r..." % path) w.application.methods['open-file'].execute(w, filename=path) else: w.set_error("Could not find module %r" % vargs['module']) @@ -545,6 +546,7 @@ class PerlOpenModuleWord(method.Method): else: pkg = parent if path: + w.set_error("opening %r..." % path) w.application.methods['open-file'].execute(w, filename=path) else: w.set_error("Could not find module related to %r" % word) diff --git a/window.py b/window.py index f81f6ae..4df861f 100644 --- a/window.py +++ b/window.py @@ -368,12 +368,13 @@ class Window(object): if p is not None: self.goto(p) def get_word_bounds_at_point(self, p): + wl = self.mode.word_letters if len(self.buffer.lines[p.y]) == 0: return None elif self.cursor_char() not in wl: return None x1 = x2 = p.x - while x1 > 0 and self.xy_char(x1 - 1, p.y) in self.mode.word_letters: + while x1 > 0 and self.xy_char(x1 - 1, p.y) in wl: x1 -= 1 while x2 < len(self.buffer.lines[p.y]) and self.xy_char(x2, p.y) in wl: x2 += 1