From 18686df3d2e813c5010822b0088e33262483bbbb Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 20 Mar 2009 19:41:56 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- method/__init__.py | 76 ++++++---------------------------------------- mode/elisp.py | 26 ++++++---------- mode/lisp.py | 16 +++++----- mode/mbox.py | 23 +++++--------- mode/scheme.py | 27 ++++++---------- 5 files changed, 47 insertions(+), 121 deletions(-) diff --git a/method/__init__.py b/method/__init__.py index 57eaecd..4c17780 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -342,71 +342,6 @@ class UppercaseWord(Method): 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')] - name_re = re.compile(r'^ *([a-z0-9_-]+) *(?:\( *\))? *$') - full_re = re.compile(r'^ *([a-z0-9_-]+) *\((.*)\) *$') - arg_re = re.compile(r' *(-?[0-9\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *') - varg_re = re.compile(r' *([a-zA-Z0-9_]+) *= *(-?[0-9\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *') - def _execute(self, w, **vargs): - m = self.name_re.match(vargs['method']) - if m: - name2 = m.group(1) - self._sub_execute(w, name2, {}) - return - m = self.full_re.match(vargs['method']) - if m: - vargs2 = {} - if '=' in m.group(2): - name2, vargs_str = m.group(1), m.group(2) - i = 0 - m = self.varg_re.search(vargs_str, i) - while m: - i = m.end() - vargs2[m.group(1)] = eval(m.group(2)) - if i == len(vargs_str): - break - elif vargs_str[i] != ',': - break - else: - i += 1 - m = self.varg_re.search(vargs_str, i) - if i == len(vargs_str): - self._sub_execute(w, name2, vargs2) - return - else: - name2, args_str = m.group(1), m.group(2) - i = 0 - m = self.arg_re.search(args_str, i) - args = [] - while m: - i = m.end() - args.append(eval(m.group(1))) - if i == len(args_str): - break - elif args_str[i] != ',': - break - else: - i += 1 - m = self.arg_re.search(args_str, i) - d = {} - try: - meth = w.application.methods[name2] - for (arg, value) in zip(meth.args, args): - vargs2[arg.name] = value - except: - pass - if i == len(args_str): - self._sub_execute(w, name2, vargs2) - return - w.set_error('could not parse argument %r' % vargs['method']) - def _sub_execute(self, w, name, vargs): - if name in w.application.methods: - w.application.methods[name].execute(w, **vargs) - else: - w.set_error('no method named %r found' % name) - -class MetaXTwo(MetaX): args = [arg('method', dt="method", p="M-x ", h='Method to execute')] name_re = re.compile(r'[a-z0-9_-]+') @@ -485,7 +420,16 @@ class MetaXTwo(MetaX): else: args.append(value) - w.set_error("func %r; other %r; args %r; vargs %r" % (func, other, args, vargs)) + meth = w.application.methods.get(func) + if meth is None: + w.set_error("method %r not found" % func) + return + try: + for (arg, value) in zip(meth.args, args): vargs[arg.name] = value + except: + w.set_error("4fail") + return + meth.execute(w, **vargs) class ToggleMargins(Method): '''Show or hide column margins''' diff --git a/mode/elisp.py b/mode/elisp.py index 4e54661..79a18d7 100644 --- a/mode/elisp.py +++ b/mode/elisp.py @@ -1,8 +1,7 @@ -import commands, os.path, string, sys, traceback -import color, completer, default, mode, method, regex, tab +from mode import Fundamental from point import Point from lex import Grammar, PatternRule, RegionRule, OverridePatternRule -from mode.lisp import LispTabber +from mode.lisp import Lisp, LispTabber class StringGrammar(Grammar): rules = [ @@ -15,41 +14,36 @@ class ELispGrammar(Grammar): rules = [ PatternRule(r'comment', r';.*$'), PatternRule(r'delimiter', r'[()]'), - PatternRule(r'elisp_reserved', r'(?:nil)(?![a-zA-Z0-9_])'), - PatternRule(r'elisp_keyword', r'(?:while|when|unless|setq-default|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'), + PatternRule(r'spaces', r' +'), + PatternRule(r'eol', r'\n'), + PatternRule(r'elisp_reserved', r'(?:t|nil)(?![^\"\' \t()])'), + PatternRule(r'keyword', r'(?:while|when|unless|setq-default|setq|setcar|require|provide|or|not|mapcar|list|let\*|let|lambda|if|exists|equal|defvar|defun|defstruct|defface|defalias|count|cons|c[ad]+r|apply|and)(?![^\"\' \t()])'), PatternRule(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"), + PatternRule(r'delimiter', r"'"), PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"), PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"), - PatternRule(r'bareword', r"[a-zA-Z_][a-zA-Z0-9-_]*"), PatternRule(r"integer", r"(??\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'), ] -class SchemeCheckSyntax(method.Method): +class SchemeCheckSyntax(Method): '''Check the syntax of a scheme file''' def _execute(self, w, **vargs): app = w.application @@ -37,30 +37,23 @@ class SchemeCheckSyntax(method.Method): else: app.data_buffer("*Scheme-Check-Syntax*", output) -class GuileStart(method.shell.Interact): +class GuileStart(Interact): args = [] def _execute(self, w, **vargs): - method.shell.Interact._execute(self, w, bname='*Guile*', cmd='guile') + Interact._execute(self, w, bname='*Guile*', cmd='guile') -class GuileLoadFile(method.shell.Interact): +class GuileLoadFile(Interact): args = [] def _execute(self, w, **vargs): - method.shell.Interact._execute(self, w, bname='*Guile*', cmd='guile') + Interact._execute(self, w, bname='*Guile*', cmd='guile') b = w.application.get_buffer_by_name('*Guile*') path = os.path.realpath(w.buffer.path) b.pipe_write('(load "%s")\n' % path) -class Scheme(mode.Fundamental): +class Scheme(Lisp): name = 'Scheme' extensions = ['.scm'] - tabwidth = 2 - tabbercls = mode.lisp.LispTabber grammar = SchemeGrammar - commentc = ';' - opentokens = ('delimiter',) - opentags = {'(': ')'} - closetokens = ('delimiter',) - closetags = {')': '('} colors = { 'scheme_keyword': ('cyan', 'default', 'bold'), 'scheme_char': ('green', 'default', 'bold'),