From 2d8a375cd0e91aa36fe9be268f333f4dade5306e Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 20 Oct 2008 02:22:31 +0000 Subject: [PATCH] dumb meta-x thing --HG-- branch : pmacs2 --- method/__init__.py | 59 +++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/method/__init__.py b/method/__init__.py index 970af4e..d7bc32d 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -335,9 +335,10 @@ class DeleteRightSpace(Method): class MetaX(Method): '''Invoke commands by name''' - args = [arg('method', dt="method", p="M-x ", h='Method to execute')] + 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']) @@ -347,23 +348,49 @@ class MetaX(Method): return m = self.full_re.match(vargs['method']) if m: - name2, vargs_str = m.group(1), m.group(2) - i = 0 - m = self.varg_re.search(vargs_str, i) vargs2 = {} - while m: - i = m.end() - vargs2[m.group(1)] = eval(m.group(2)) + 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): - 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 + 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: