branch : pmacs2
This commit is contained in:
moculus 2009-04-27 02:13:57 +00:00
parent 27b2b3db3a
commit 1a66165dbd
3 changed files with 28 additions and 22 deletions

View File

@ -98,17 +98,16 @@ class Pipe(Method):
lines = data.split('\n')
if lines and lines[-1] == '':
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))
bufname = '*%s*' % self.name.title()
b = w.application.data_buffer(bufname, data, switch_to=True, modename='error')
b.orig_path = w.buffer.path
w.set_error("%s exited with status %d" % (prog, status))
def _execute(self, w, **vargs):
(prog, cmd, shell) = self._parse(w, **vargs)
if prog is None or not cmd:
return
self._dopipe(w, prog, cmd, shell)
def _dopipe(self, w, prog, cmd, shell):
@ -129,11 +128,12 @@ class Grep(Pipe):
args = [arg('pattern', dt="str", p="Pattern: ")]
def _parse(self, w, **vargs):
return ('grep', ('grep', '-E', '-n', vargs['pattern']), False)
class Sed(Pipe):
'''Push the buffer's contents through a sed expression'''
args = [arg('expression', dt="str", p="Expression: ")]
def _parse(self, w, **vargs):
return ('grep', ('sed', '-r', '-e', vargs['expression']), False)
return ('sed', ('sed', '-r', '-e', vargs['expression']), False)
class Interact(Method):
'''Interact with a program via a PTY'''

View File

@ -7,6 +7,7 @@ _error_regexes = [
r'File "(?P<file>.+?)", line (?P<line>\d+)(?:, in \S+)?$', #python
r'^(?P<file>\S+?):(?P<line>\d+): ', #javac/gcc
r'at \S+\((?P<file>.+?):(?P<line>\d+)\)$', #java
r'^(?P<line>\d+):', #grep
]
error_regexes = [re.compile(s) for s in _error_regexes]
@ -31,12 +32,17 @@ class ErrorGotoLine(Method):
w.set_error("nothing found")
return
errline = w.buffer.lines[y]
path, line = m.group('file'), int(m.group('line'))
if path == '-':
d = m.groupdict()
path = d.get('file')
line = d.get('line')
if line is None:
return
elif path is None or path == '-':
path = w.buffer.orig_path
b2 = a.open_path(path)
a.switch_buffer(b2)
a.methods['goto-line'].execute(b2.windows[0], lineno=line)
a.methods['goto-line'].execute(b2.windows[0], lineno=int(line))
w.set_error(errline)
class Error(Fundamental):

View File

@ -5,7 +5,7 @@ from point import Point
from render import RenderString
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
from parse import Any, And, Or, Optional, Name, Match, Matchs
from method import Method, arg
from method import Method, arg, Argument
from method.shell import Exec
class StringGrammar1(Grammar):
@ -203,7 +203,7 @@ class PythonTabber(tab.StackTabber):
self._append(s, currlvl + w, y)
return currlvl
class PythonCheckSyntax(method.Method):
class PythonCheckSyntax(Method):
'''Check the syntax of the current python file'''
def _execute(self, w, **vargs):
pythonlib = w.application.config.get('python.lib')
@ -219,7 +219,7 @@ class PythonCheckSyntax(method.Method):
modename='error')
del sys.path[0]
class PythonDictCleanup(method.Method):
class PythonDictCleanup(Method):
'''Align assignment blocks and literal dictionaries'''
def _execute(self, w, **vargs):
cursor = w.logical_cursor()
@ -309,7 +309,7 @@ class PythonHelp(Exec):
stmt = 'try:\n import %s\nexcept:\n pass\nhelp(%s)' % (name, name)
self._doit(w, None, 'python -c "%s"' % stmt)
class PythonInsertTripleSquotes(method.Method):
class PythonInsertTripleSquotes(Method):
'''Insert a triple-quoted string using single-quotes'''
_q = "'''"
def _execute(self, w, **vargs):
@ -321,7 +321,7 @@ class PythonInsertTripleDquotes(PythonInsertTripleSquotes):
'''Insert a triple-quoted string using double-quotes'''
_q = '"""'
class PythonInitNames(method.Method):
class PythonInitNames(Method):
'''Jump to a function defined in this module'''
def _execute(self, w, **vargs):
w.mode.context.build_name_map()
@ -349,9 +349,9 @@ class PythonSemanticComplete(method.introspect.TokenComplete):
return self._prune_candidates(t, minlen, candidates)
class PythonGotoName(method.Method):
class PythonGotoName(Method):
'''Jump to a class or function defined in this module'''
args = [method.Argument("name", type(""), "pythonname", "Goto Name: ")]
args = [Argument("name", type(""), "pythonname", "Goto Name: ")]
title = 'Name'
def _get_dict(self, w):
return w.mode.context.get_names()
@ -365,26 +365,26 @@ class PythonGotoName(method.Method):
class PythonGotoFunction(PythonGotoName):
'''Jump to a function defined in this module'''
args = [method.Argument("name", type(""), "pythonfunction", "Goto Function: ")]
args = [Argument("name", type(""), "pythonfunction", "Goto Function: ")]
title = 'Function'
def _get_dict(self, w):
return w.mode.context.get_functions()
class PythonGotoClass(method.Method):
class PythonGotoClass(Method):
'''Jump to a class defined in this module'''
args = [method.Argument("name", type(""), "pythonclass", "Goto Class: ")]
args = [Argument("name", type(""), "pythonclass", "Goto Class: ")]
title = 'Class'
def _get_dict(self, w):
return w.mode.context.get_classes()
class PythonListNames(method.Method):
class PythonListNames(Method):
'''Show the user all functions defined in this module'''
def _execute(self, w, **vargs):
names = w.mode.context.get_names()
output = '\n'.join(sorted(names)) + "\n"
w.application.data_buffer("*Python-List-Names*", output, switch_to=True)
class PythonBrmFindReferences(method.Method):
class PythonBrmFindReferences(Method):
def _execute(self, w, **vargs):
if w.mode.brm is None:
w.set_error('bicycle repairman not installed')