From 6294113e20fd761015d0352bc53f137f2d5e5f62 Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 29 Jun 2007 13:37:58 +0000 Subject: [PATCH] some fixes, etc --HG-- branch : pmacs2 --- method.py | 8 ++++++++ mode2.py | 5 ++++- mode_perl.py | 4 +++- mode_xml.py | 4 +++- window2.py | 11 +++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/method.py b/method.py index 384e107..2a5db00 100644 --- a/method.py +++ b/method.py @@ -1373,3 +1373,11 @@ class CloseBrace(CloseTag): mytag = '}' class CloseBracket(CloseTag): mytag = ']' + +class GetToken(Method): + def _execute(self, w, **vargs): + token = w.get_token() + if token is None: + w.application.set_error('No Token') + else: + w.application.set_error('Token: %r' % token.string) diff --git a/mode2.py b/mode2.py index 143a055..e93de22 100644 --- a/mode2.py +++ b/mode2.py @@ -1,5 +1,5 @@ import os, sets, string -import color, lex2 +import color, lex2, method DEBUG = False @@ -142,6 +142,9 @@ class Fundamental(Handler): self.add_bindings('set-mode', ('C-x m',)) self.add_bindings('cancel', ('C-]',)) + # unbound actions + self.add_action(method.GetToken()) + # create all the insert actions for the basic text input for c in string.letters + string.digits + string.punctuation: self.add_binding('insert-string-%s' % c, c) diff --git a/mode_perl.py b/mode_perl.py index 4de2aa3..f49d4d3 100644 --- a/mode_perl.py +++ b/mode_perl.py @@ -352,7 +352,9 @@ class PerlViewWordPerldoc(method.Method): w.application.data_buffer("*Perldoc*", data, switch_to=True) w.application.set_error('displaying documentation for %r' % word) def _execute(self, w, **vargs): - word = w.get_word(wl=string.letters + string.digits + '_:') + token = w.get_token() + #word = w.get_word(wl=string.letters + string.digits + '_:') + word = token.string # make sure that the name is (mostly) valid if word is None: diff --git a/mode_xml.py b/mode_xml.py index 6a76a4c..60072e7 100644 --- a/mode_xml.py +++ b/mode_xml.py @@ -24,7 +24,9 @@ class XML(mode2.Fundamental): #self.add_bindings('close-brace', ('}',)) #self.add_bindings('close-bracket', (']',)) self.colors = { - 'comment': color.build('red', 'default'), + 'comment.start': color.build('red', 'default'), + 'comment.null': color.build('red', 'default'), + 'comment.end': color.build('red', 'default'), 'opentag.start': color.build('default', 'default'), 'opentag.namespace': color.build('magenta', 'default'), 'opentag.name': color.build('blue', 'default'), diff --git a/window2.py b/window2.py index b3a1880..af92b76 100644 --- a/window2.py +++ b/window2.py @@ -532,6 +532,17 @@ class Window(object): self.buffer.redo() # highlighting tokens + def get_token(self): + return self.get_token_at_point(self.logical_cursor()) + def get_token_at_point(self, p): + for token in self.get_highlighter().tokens[p.y]: + if token.end_x() <= p.x: + continue + elif token.x > p.x: + continue + else: + return token + return None def get_next_token_by_lambda(self, p, f): for token in self.get_highlighter().tokens[p.y]: if token.x < p.x: