From 2726b9edef6e9ce677ab0b6f21463fe4ef83d167 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 8 Mar 2009 05:19:58 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- method/shell.py | 2 -- mode/erlang.py | 12 ++++++++- mode/perl.py | 65 +++++++++++++++++++++++++++++-------------------- mode/python.py | 16 ++++++++++-- 4 files changed, 63 insertions(+), 32 deletions(-) diff --git a/method/shell.py b/method/shell.py index 3273710..0cbad83 100644 --- a/method/shell.py +++ b/method/shell.py @@ -144,10 +144,8 @@ class Interact(Method): def _execute(self, w, **vargs): bname = vargs['bname'] cmd = vargs['cmd'] - a = w.application a.close_buffer_by_name(bname) - #b = buffer.emul.XTermBuffer(a, cmd, [], name=bname) b = buffer.emul.XTermBuffer(a, 'bash', ['-c', cmd], name=bname) a.add_buffer(b) window.Window(b, a) diff --git a/mode/erlang.py b/mode/erlang.py index 1fcfe27..d5f0396 100644 --- a/mode/erlang.py +++ b/mode/erlang.py @@ -1,7 +1,8 @@ import commands, os.path, string, sys, traceback -import color, completer, default, mode, method, regex, tab +import color, completer, default, mode, regex, tab from point import Point from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule +from method.shell import Interact class AtomGrammar(Grammar): rules = [ @@ -76,6 +77,12 @@ class ErlangTabber(tab.StackTabber): currlvl = self.get_curr_level() return currlvl +## this shit doesn't work... hmmm +#class ErlStart(Interact): +# args = [] +# def _execute(self, w, **vargs): +# Interact._execute(self, w, bname='*Erl*', cmd='erl') + class Erlang(mode.Fundamental): modename = 'Erlang' extensions = ['.erl'] @@ -101,6 +108,9 @@ class Erlang(mode.Fundamental): 'erl_atom.null': ('magenta', 'default', 'bold'), 'erl_atom.end': ('magenta', 'default', 'bold'), } + actions = [ + #ErlStart, + ] _bindings = { 'close-paren': (')',), 'close-brace': ('}',), diff --git a/mode/perl.py b/mode/perl.py index f29f86d..5ecab0a 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -230,14 +230,37 @@ class PerlViewModulePerldoc(Method): args = ('perl', '-e', self.prog) app.run_pipe(args, w.buffer, '*Perldoc*', True) -class PerlViewWordPerldoc(Method): - '''View documentation about a package or function using perldoc''' - def _try(self, w, word, asfunc=False): +class PerlViewPerldoc(Method): + name_re = re.compile('(?:[a-zA-Z_][a-zA-Z0-9_]*::)*[a-zA-Z_][a-zA-Z0-9_]*') + args = [Argument("name", type(""), "", "Perldoc: ")] + def _execute(self, w, **vargs): + name = vargs['name'] + if not self.name_re.match(name): + w.set_error("name %r is invalid" % name) + return + + # try it as a module first + parts = name.split('::') + while len(parts) > 0: + newname = '::'.join(parts) + data = self._try(w, newname, asfunc=False) + if data: + self._show(w, data, newname) + return + parts.pop(-1) + + # then try it as a function + data = self._try(w, name, asfunc=True) + if data: + self._show(w, data, name) + else: + w.application.set_error('nothing found for %r' % name) + def _try(self, w, name, asfunc=False): a = w.application if asfunc: - cmd = "perldoc -t -T -f '%s'" % (word,) + cmd = "perldoc -t -T -f '%s'" % (name,) else: - cmd = "perldoc -t -T '%s'" % (word,) + cmd = "perldoc -t -T '%s'" % (name,) if a.config.get('perl.libs', None): s = ':'.join(['%r' % x for x in a.config.get('perl.libs')]) @@ -250,12 +273,16 @@ class PerlViewWordPerldoc(Method): return data else: return None - def _show(self, w, data, word): + def _show(self, w, data, name): w.application.data_buffer("*Perldoc*", data, switch_to=True) - w.application.set_error('displaying documentation for %r' % word) + w.application.set_error('displaying documentation for %r' % name) + +class PerlViewWordPerldoc(PerlViewPerldoc): + '''View documentation about a package or function using perldoc''' + args = [] def _execute(self, w, **vargs): token = w.get_token() - word = token.string + word = token.string # make sure that the name is (mostly) valid if word is None: @@ -264,24 +291,7 @@ class PerlViewWordPerldoc(Method): elif ':' in word and '::' not in word: w.application.set_error('invalid word: %r' % word) return - - # first try it is a package, unless it's a builtin - if not token.name == "perl_builtin": - parts = word.split('::') - while len(parts) > 0: - newword = '::'.join(parts) - data = self._try(w, newword, asfunc=False) - if data: - self._show(w, data, newword) - return - parts.pop(-1) - - # then try it as a function - data = self._try(w, word, asfunc=True) - if data: - self._show(w, data, word) - else: - w.application.set_error('nothing found for %r' % word) + return PerlViewPerldoc._execute(self, w, name=word) class PerlInitFunctions(Method): '''Jump to a function defined in this module''' @@ -723,7 +733,8 @@ class Perl(mode.Fundamental): 'perl.libs': ['lib'], } actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup, - PerlViewModulePerldoc, PerlViewWordPerldoc, PerlWrapParagraph, + PerlViewModulePerldoc, PerlViewWordPerldoc, PerlViewPerldoc, + PerlWrapParagraph, PerlInitFunctions, PerlGotoFunction, PerlWhichFunction, PerlListFunctions, PerlOpenModule, PerlOpenModuleWord, PerlSemanticComplete] diff --git a/mode/python.py b/mode/python.py index 475a373..d5f0562 100644 --- a/mode/python.py +++ b/mode/python.py @@ -4,7 +4,8 @@ from point import Point from render import RenderString from lex import Grammar, PatternRule, RegionRule, OverridePatternRule from parse import Any, And, Or, Optional, Name, Match, Matchs -from method import Method +from method import Method, arg +from method.shell import Exec try: import bike @@ -303,6 +304,14 @@ class PythonDictCleanup(method.Method): w.delete(start_p, end_p) w.insert_string(start_p, data) +class PythonHelp(Exec): + '''Generate a help page on a python object''' + args = [arg('name', t="string", p="Name: ", h='name to get help on')] + def _execute(self, w, **vargs): + name = vargs['name'] + stmt = '"try:\n import %s\nexcept:\n pass\nhelp(%s)"' % (name, name) + self._doit(w, None, 'python -c %s' % stmt) + class PythonInsertTripleSquotes(method.Method): '''Insert a triple-quoted string using single-quotes''' _q = "'''" @@ -310,6 +319,7 @@ class PythonInsertTripleSquotes(method.Method): w.insert_string_at_cursor('%s%s' % (self._q, self._q)) for i in range(0, 3): w.backward() + class PythonInsertTripleDquotes(PythonInsertTripleSquotes): '''Insert a triple-quoted string using double-quotes''' _q = '"""' @@ -355,12 +365,14 @@ class PythonGotoName(method.Method): w.goto(Point(0, d[name])) else: w.application.set_error("%r %r was not found" % (title, name)) + class PythonGotoFunction(PythonGotoName): '''Jump to a function defined in this module''' args = [method.Argument("name", type(""), "pythonfunction", "Goto Function: ")] title = 'Function' def _get_dict(self, w): return w.mode.context.get_functions() + class PythonGotoClass(method.Method): '''Jump to a class defined in this module''' args = [method.Argument("name", type(""), "pythonclass", "Goto Class: ")] @@ -558,7 +570,7 @@ class Python(mode.Fundamental): lconfig = { 'ignore-suffix': ['.pyc', '.pyo'], } - actions = [PythonInitNames, PythonListNames, PythonGotoName, + actions = [PythonInitNames, PythonListNames, PythonGotoName, PythonHelp, PythonGotoFunction, PythonGotoClass, PythonCheckSyntax, PythonDictCleanup, PythonSemanticComplete, PythonBrmFindReferences, PythonInsertTripleSquotes, PythonInsertTripleDquotes]