new pipe command, and grep command improvements
--HG-- branch : pmacs2
This commit is contained in:
parent
1e3a417fb9
commit
3a36d4f149
|
@ -546,7 +546,8 @@ class Application(object):
|
||||||
|
|
||||||
if w.margins_visible:
|
if w.margins_visible:
|
||||||
for (limit, shade) in w.margins:
|
for (limit, shade) in w.margins:
|
||||||
if limit <= self.x:
|
#if limit <= self.x:
|
||||||
|
if limit < self.x:
|
||||||
for j in range(0, slot.height):
|
for j in range(0, slot.height):
|
||||||
char = self.win.inch(j + slot.offset, limit) & 255
|
char = self.win.inch(j + slot.offset, limit) & 255
|
||||||
attr = color.build('default', shade, 'bold')
|
attr = color.build('default', shade, 'bold')
|
||||||
|
|
38
method.py
38
method.py
|
@ -1405,12 +1405,23 @@ class RegisterRestore(Method):
|
||||||
name = name[0:self.MAX_REG] + '...'
|
name = name[0:self.MAX_REG] + '...'
|
||||||
w.set_error('Restored %r from register %r' % (text2, name2))
|
w.set_error('Restored %r from register %r' % (text2, name2))
|
||||||
|
|
||||||
class Grep(Method):
|
class Pipe(Method):
|
||||||
'''help here'''
|
'''help here'''
|
||||||
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
|
args = [Argument('cmd', datatype="str", prompt="Command: ")]
|
||||||
|
def _parse(self, w, **vargs):
|
||||||
|
m = regex.shell_command.match(vargs['cmd'])
|
||||||
|
if m:
|
||||||
|
prog = m.group(0)
|
||||||
|
return (prog, vargs['cmd'])
|
||||||
|
else:
|
||||||
|
return (None, None)
|
||||||
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
cmd = ("/usr/bin/grep", '-E', '-n', vargs['pattern'], '-')
|
(prog, cmd) = self._parse(w, **vargs)
|
||||||
pipe = popen2.Popen3(cmd, capturestderr=True)
|
if prog is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
pipe = popen2.Popen4(cmd)
|
||||||
pid = pipe.pid
|
pid = pipe.pid
|
||||||
|
|
||||||
indata = w.buffer.make_string()
|
indata = w.buffer.make_string()
|
||||||
|
@ -1418,16 +1429,15 @@ class Grep(Method):
|
||||||
pipe.tochild.close()
|
pipe.tochild.close()
|
||||||
|
|
||||||
outdata = pipe.fromchild.read()
|
outdata = pipe.fromchild.read()
|
||||||
errdata = pipe.childerr.read()
|
|
||||||
status = pipe.wait() >> 8
|
status = pipe.wait() >> 8
|
||||||
|
|
||||||
if status == 0:
|
bufname = '*%s*' % self.name.title()
|
||||||
num = len(outdata.split('\n'))
|
w.application.data_buffer(bufname, outdata, switch_to=True)
|
||||||
w.application.data_buffer("*Grep*", outdata, switch_to=True)
|
w.set_error("%s exited with status %d" % (prog, status))
|
||||||
w.application.set_error("Grep: %d matches found" % num)
|
|
||||||
elif status == 1:
|
class Grep(Pipe):
|
||||||
w.application.set_error("Grep: no matches found")
|
'''help here'''
|
||||||
else:
|
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
|
||||||
w.application.data_buffer("*Grep*", outdata, switch_to=True)
|
def _parse(self, w, **vargs):
|
||||||
w.set_error("Grep: error (exited with status %d)" % status)
|
return ('grep', ('/usr/bin/grep', '-E', '-n', vargs['pattern']))
|
||||||
|
|
3
regex.py
3
regex.py
|
@ -3,6 +3,9 @@ import re
|
||||||
# meta regexes
|
# meta regexes
|
||||||
meta_chars = re.compile(r'([\.\^\$\*\+\?\{\}\(\)\[\]\|\\])')
|
meta_chars = re.compile(r'([\.\^\$\*\+\?\{\}\(\)\[\]\|\\])')
|
||||||
|
|
||||||
|
# shell
|
||||||
|
shell_command = re.compile(r'^[^ ]+')
|
||||||
|
|
||||||
# whitespace regexes
|
# whitespace regexes
|
||||||
leading_whitespace = re.compile('^ *')
|
leading_whitespace = re.compile('^ *')
|
||||||
trailing_whitespace = re.compile(' *$')
|
trailing_whitespace = re.compile(' *$')
|
||||||
|
|
Loading…
Reference in New Issue