some cleanup and generic buffer piping

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-11-14 04:44:56 +00:00
parent d2334621ee
commit 2dcac2c1f1
2 changed files with 24 additions and 16 deletions

View File

@ -626,6 +626,19 @@ class Application(object):
else: else:
i += 1 i += 1
# running external programs
def run_pipe(self, args, b, name='*Output*', switch='yes'):
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
pipe.stdin.write(b.make_string())
pipe.stdin.close()
output = pipe.stdout.read()
status = pipe.wait()
if callable(switch):
switch_to = switch(status)
else:
switch_to = bool(switch)
self.data_buffer(name, output, switch_to=switch_to)
return status
def run_external(self, *args): def run_external(self, *args):
curses.reset_shell_mode() curses.reset_shell_mode()
try: try:

View File

@ -1,4 +1,5 @@
import os, re, string, sys import os, re, string, sys
from subprocess import Popen, PIPE, STDOUT
import buffer, color, commands, completer, context, default, method, mode, regex, tab import buffer, color, commands, completer, context, default, method, mode, regex, tab
from point import Point from point import Point
from lex import Grammar, PatternRule, ContextPatternRule, RegionRule, \ from lex import Grammar, PatternRule, ContextPatternRule, RegionRule, \
@ -196,25 +197,19 @@ class PerlSetLib(Method):
class PerlCheckSyntax(Method): class PerlCheckSyntax(Method):
'''Check the syntax of a perl file''' '''Check the syntax of a perl file'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
app = w.application a = w.application
perllib = w.application.config.get('perl.lib') args = ('perl', '-I', a.config.get('perl.lib', '.'), '-c', '-')
if perllib: retval = a.run_pipe(args, w.buffer, '*Perl-Syntax*', lambda x: x != 0)
cmd = "perl -c -I '%s' '%s'" % (perllib, w.buffer.path) if retval == 0: a.set_error("Syntax OK")
else:
cmd = "perl -c '%s'" % (w.buffer.path)
(status, output) = commands.getstatusoutput(cmd)
if status == 0:
app.set_error("Syntax OK")
app.data_buffer("*Perl-Check-Syntax*", output, switch_to=False)
else:
app.data_buffer("*Perl-Check-Syntax*", output)
class PerlViewModulePerldoc(Method): class PerlViewModulePerldoc(Method):
'''View documentation about this file using perldoc''' '''View documentation about this buffer using perldoc'''
prog = 'use Pod::Text;' \
'Pod::Text->new(sentence=>0, width=>78)->parse_from_filehandle();'
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
cmd = "perldoc -t -T '%s'" % w.buffer.path app = w.application
(status, output) = commands.getstatusoutput(cmd) args = ('perl', '-e', self.prog)
w.application.data_buffer("*Perldoc*", output, switch_to=True) app.run_pipe(args, w.buffer, '*Perldoc*', True)
class PerlViewWordPerldoc(Method): class PerlViewWordPerldoc(Method):
'''View documentation about a package or function using perldoc''' '''View documentation about a package or function using perldoc'''