awk commands

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-10-04 16:09:15 +00:00
parent bc5f6802d8
commit f48db1edda
3 changed files with 121 additions and 91 deletions

View File

@ -10,12 +10,14 @@ class Exec(Method):
'''Execute a command in a shell and put the output in a new buffer'''
show_success = True
args = [Argument('cmd', prompt="Exec: ", datatype='shell')]
def _doit(self, w, path, cmd, cmdname=None, bufname=None, cmddir=None):
def _doit(self, w, path, cmd, cmdname=None, bufname=None, cmddir=None, opts={}):
if cmddir:
cmd = "cd %r && %s" % (cmddir, cmd)
d = dict(opts)
if path:
d['path'] = path
try:
cmd = cmd % {'path': path}
cmd = cmd % d
except:
pass

View File

@ -1,8 +1,10 @@
import commands
import color, method, mode, tab
import commands, os
import color, default, mode, tab
from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar2
from tab import StackTabber2
from method import Method, Argument, arg
from method.shell import Exec, Pipe
class RegexGrammar(Grammar):
rules = [
@ -62,6 +64,26 @@ class AwkTabber(StackTabber2):
def _is_ignored(self, t):
return t.name in ('spaces', 'eol', 'comment')
class AwkFilterFile(Exec):
show_success = True
args = [arg('path', dt="path", p="Filter File: ", dv=default.path_dirname,
ld=True, h="file to open")]
def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no program")
return
elif w.buffer.changed():
w.set_error("Buffer is not saved")
return
else:
self._doit(w, w.buffer.path, w.application.config['awk.filter-cmd'],
cmdname='awk', bufname='*Awk-Output*',
opts={'data': vargs['path']})
class AwkFilterBuffer(Method):
pass
class AwkFilterInput(Method):
pass
class Awk(mode.Fundamental):
tabbercls = AwkTabber
@ -78,5 +100,11 @@ class Awk(mode.Fundamental):
'awk_regex.data': ('cyan', 'default', 'bold'),
'awk_regex.end': ('cyan', 'default', 'bold'),
}
config = {
'awk.filter-cmd': "awk -f %(path)r %(data)r",
}
actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput]
#format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
install = Awk.install