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,14 +10,16 @@ class Exec(Method):
'''Execute a command in a shell and put the output in a new buffer''' '''Execute a command in a shell and put the output in a new buffer'''
show_success = True show_success = True
args = [Argument('cmd', prompt="Exec: ", datatype='shell')] 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: if cmddir:
cmd = "cd %r && %s" % (cmddir, cmd) cmd = "cd %r && %s" % (cmddir, cmd)
d = dict(opts)
if path: if path:
try: d['path'] = path
cmd = cmd % {'path': path} try:
except: cmd = cmd % d
pass except:
pass
if bufname is None: if bufname is None:
bufname = '*%s*' % self.name.title() bufname = '*%s*' % self.name.title()

View File

@ -1,8 +1,10 @@
import commands import commands, os
import color, method, mode, tab import color, default, mode, tab
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar2 from mode.python import StringGrammar2
from tab import StackTabber2 from tab import StackTabber2
from method import Method, Argument, arg
from method.shell import Exec, Pipe
class RegexGrammar(Grammar): class RegexGrammar(Grammar):
rules = [ rules = [
@ -62,6 +64,26 @@ class AwkTabber(StackTabber2):
def _is_ignored(self, t): def _is_ignored(self, t):
return t.name in ('spaces', 'eol', 'comment') 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): class Awk(mode.Fundamental):
tabbercls = AwkTabber tabbercls = AwkTabber
@ -78,5 +100,11 @@ class Awk(mode.Fundamental):
'awk_regex.data': ('cyan', 'default', 'bold'), 'awk_regex.data': ('cyan', 'default', 'bold'),
'awk_regex.end': ('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 install = Awk.install