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): class MetaX(Method):
'''Invoke commands by name''' '''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_-]+) *(?:\( *\))? *$') 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,23 +348,49 @@ class MetaX(Method):
return return
m = self.full_re.match(vargs['method']) m = self.full_re.match(vargs['method'])
if m: if m:
name2, vargs_str = m.group(1), m.group(2)
i = 0
m = self.varg_re.search(vargs_str, i)
vargs2 = {} vargs2 = {}
while m: if '=' in m.group(2):
i = m.end() name2, vargs_str = m.group(1), m.group(2)
vargs2[m.group(1)] = eval(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): if i == len(vargs_str):
break self._sub_execute(w, name2, vargs2)
elif vargs_str[i] != ',': return
break else:
else: name2, args_str = m.group(1), m.group(2)
i += 1 i = 0
m = self.varg_re.search(vargs_str, i) m = self.arg_re.search(args_str, i)
if i == len(vargs_str): args = []
self._sub_execute(w, name2, vargs2) while m:
return 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: