lowercase/uppercase, and some bug fixes

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-11-20 21:27:52 +00:00
parent 525f1e70f9
commit 27b1a17e7b
4 changed files with 23 additions and 1 deletions

View File

@ -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')]

View File

@ -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']

View File

@ -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)

View File

@ -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