branch : pmacs2
This commit is contained in:
moculus 2009-04-10 05:29:44 +00:00
parent a235355533
commit 4c63cdcd60
1 changed files with 20 additions and 22 deletions

View File

@ -53,9 +53,7 @@ class AwkGrammar(Grammar):
class AwkTabber(StackTabber2):
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
control_tokens = {
'awk.keyword': set(['if', 'else', 'while', 'do', 'for'])
}
control_tokens = {'awk.keyword': set(['if', 'else', 'while', 'do', 'for'])}
end_at_eof = True
end_at_tokens = {}
def _is_base(self, y):
@ -64,7 +62,6 @@ class AwkTabber(StackTabber2):
if t.fqisa('awk.regex.start'): return True
if t.isa('awk.field', 'awk.global'): return True
if t.matchs('awk.keyword', ('BEGIN', 'END')): return True
return False
def _is_indent(self, t): return t.isa('spaces')
def _is_ignored(self, t): return t.isa('spaces', 'eol', 'comment')
@ -72,17 +69,17 @@ class AwkTabber(StackTabber2):
class AwkFilterFile(Exec):
'''Filter a file through the current buffer's AWK program'''
show_success = True
args = [arg('path', dt="path", p="Filter File: ", dv=default.path_dirname,
ld=True, h="file to open")]
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 %r has no program" % w.buffer.name())
w.set_error('Buffer %r has no program' % w.buffer.name())
return
elif w.buffer.changed():
w.set_error("Buffer %r is not saved" % w.buffer.name())
w.set_error('Buffer %r is not saved' % w.buffer.name())
return
elif not os.path.exists(vargs['path']):
w.set_error("File %r not found" % vargs['path'])
w.set_error('File %r not found' % vargs['path'])
return
cmd = 'awk -f %r %r' % (w.buffer.path, vargs['path'])
@ -90,20 +87,21 @@ class AwkFilterFile(Exec):
outdata = pipe.stdout.read()
status = pipe.wait() >> 8
w.application.data_buffer('*Awk-Output*', outdata, switch_to=True)
w.set_error("awk exited with status %d" % status)
w.set_error('awk exited with status %d' % status)
class AwkFilterBuffer(Pipe):
'''Filter a buffer through the current buffer's AWK program'''
args = [arg('name', dt="buffer", p="Filter Buffer: ", h="name of the buffer to switch to")]
args = [arg('name', dt='buffer', p='Filter Buffer: ',
h='name of the buffer to switch to')]
def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'):
w.set_error("Buffer %r has no program" % w.buffer.name())
w.set_error('Buffer %r has no program' % w.buffer.name())
return
elif w.buffer.changed():
w.set_error("Buffer %r is not saved" % w.buffer.name())
w.set_error('Buffer %r is not saved' % w.buffer.name())
return
elif not w.application.has_buffer_name(vargs['name']):
w.set_error("Buffer %r not found" % vargs['name'])
w.set_error('Buffer %r not found' % vargs['name'])
return
b = w.application.bufferlist.get_buffer_by_name(vargs['name'])
@ -115,17 +113,17 @@ class AwkFilterBuffer(Pipe):
output = pipe.stdout.read()
status = pipe.wait() >> 8
w.application.data_buffer('*Awk-Output*', output, switch_to=True)
w.set_error("awk exited with status %d" % status)
w.set_error('awk exited with status %d' % status)
class AwkFilterInput(Method):
'''Filter input through the current buffer's AWK program'''
args = [arg('input', p="Data To Filter: ", h="data to filter")]
args = [arg('input', p='Data To Filter: ', h='data to filter')]
def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'):
w.set_error("Buffer %r has no program" % w.buffer.name())
w.set_error('Buffer %r has no program' % w.buffer.name())
return
elif w.buffer.changed():
w.set_error("Buffer %r is not saved" % w.buffer.name())
w.set_error('Buffer %r is not saved' % w.buffer.name())
return
opts = w.application.config['awk.cmd-opts']
@ -136,7 +134,7 @@ class AwkFilterInput(Method):
output = pipe.stdout.read()
status = pipe.wait() >> 8
w.application.data_buffer('*Awk-Output*', output, switch_to=True)
w.set_error("awk exited with status %d" % status)
w.set_error('awk exited with status %d' % status)
class Awk(Fundamental):
name = 'awk'
@ -147,7 +145,7 @@ class Awk(Fundamental):
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
config = {'awk.cmd-opts': ""}
config = {'awk.cmd-opts': ''}
actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput]
colors = {
'awk.global': ('yellow', 'default', 'bold'),