dumb meta-x thing

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-10-20 02:22:31 +00:00
parent 7b5b9f0c94
commit 2d8a375cd0
1 changed files with 43 additions and 16 deletions

View File

@ -338,6 +338,7 @@ class MetaX(Method):
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_-]+) *(?:\( *\))? *$') name_re = re.compile(r'^ *([a-z0-9_-]+) *(?:\( *\))? *$')
full_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\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *') varg_re = re.compile(r' *([a-zA-Z0-9_]+) *= *(-?[0-9\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *')
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
m = self.name_re.match(vargs['method']) m = self.name_re.match(vargs['method'])
@ -347,10 +348,11 @@ class MetaX(Method):
return return
m = self.full_re.match(vargs['method']) m = self.full_re.match(vargs['method'])
if m: if m:
vargs2 = {}
if '=' in m.group(2):
name2, vargs_str = m.group(1), m.group(2) name2, vargs_str = m.group(1), m.group(2)
i = 0 i = 0
m = self.varg_re.search(vargs_str, i) m = self.varg_re.search(vargs_str, i)
vargs2 = {}
while m: while m:
i = m.end() i = m.end()
vargs2[m.group(1)] = eval(m.group(2)) vargs2[m.group(1)] = eval(m.group(2))
@ -364,6 +366,31 @@ class MetaX(Method):
if i == len(vargs_str): if i == len(vargs_str):
self._sub_execute(w, name2, vargs2) self._sub_execute(w, name2, vargs2)
return 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']) w.set_error('could not parse argument %r' % vargs['method'])
def _sub_execute(self, w, name, vargs): def _sub_execute(self, w, name, vargs):
if name in w.application.methods: if name in w.application.methods: