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

@ -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: