parent
7e98f06caf
commit
bfdfedfa09
|
@ -315,10 +315,38 @@ 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_-]+) *(?:\( *\))? *$')
|
||||||
|
full_re = re.compile(r'^ *([a-z0-9_-]+) *\((.*)\) *$')
|
||||||
|
varg_re = re.compile(r' *([a-zA-Z0-9_]+) *= *(-?[0-9\.]+|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\\"])*") *')
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
name = vargs['method']
|
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:
|
||||||
|
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 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
|
||||||
|
w.set_error('could not parse argument %r' % vargs['method'])
|
||||||
|
def _sub_execute(self, w, name, vargs):
|
||||||
if name in w.application.methods:
|
if name in w.application.methods:
|
||||||
w.application.methods[name].execute(w)
|
w.application.methods[name].execute(w, **vargs)
|
||||||
else:
|
else:
|
||||||
w.set_error('no method named %r found' % name)
|
w.set_error('no method named %r found' % name)
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,15 @@ class Pipe(Method):
|
||||||
return (None, None, False)
|
return (None, None, False)
|
||||||
|
|
||||||
def _display(self, w, data, status, prog, cmd, shell):
|
def _display(self, w, data, status, prog, cmd, shell):
|
||||||
bufname = '*%s*' % self.name.title()
|
lines = data.split('\n')
|
||||||
w.application.data_buffer(bufname, data, switch_to=True)
|
if lines and lines[-1] == '':
|
||||||
w.set_error("%s exited with status %d" % (prog, status))
|
lines = lines[:-1]
|
||||||
|
if status == 0 and len(lines) == 1:
|
||||||
|
w.set_error("%s output: %r" % (prog, lines[0]))
|
||||||
|
else:
|
||||||
|
bufname = '*%s*' % self.name.title()
|
||||||
|
w.application.data_buffer(bufname, data, switch_to=True)
|
||||||
|
w.set_error("%s exited with status %d" % (prog, status))
|
||||||
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
(prog, cmd, shell) = self._parse(w, **vargs)
|
(prog, cmd, shell) = self._parse(w, **vargs)
|
||||||
|
|
|
@ -180,7 +180,7 @@ class Fundamental(Handler):
|
||||||
self.add_bindings('cancel', ('C-]',))
|
self.add_bindings('cancel', ('C-]',))
|
||||||
self.add_bindings('exec', ('C-c e', 'C-c !'))
|
self.add_bindings('exec', ('C-c e', 'C-c !'))
|
||||||
self.add_bindings('grep', ('C-c g',))
|
self.add_bindings('grep', ('C-c g',))
|
||||||
self.add_bindings('pipe', ('C-c p',))
|
self.add_bindings('pipe', ('C-c p', 'C-c |'))
|
||||||
self.add_bindings('view-buffer-parent', ('C-c .',))
|
self.add_bindings('view-buffer-parent', ('C-c .',))
|
||||||
self.add_bindings('insert-squotes', ('M-\'',))
|
self.add_bindings('insert-squotes', ('M-\'',))
|
||||||
self.add_bindings('insert-dquotes', ('M-"',))
|
self.add_bindings('insert-dquotes', ('M-"',))
|
||||||
|
|
Loading…
Reference in New Issue