From 2dcac2c1f11f46d3344bc5f50fce62b2a8067713 Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 14 Nov 2008 04:44:56 +0000 Subject: [PATCH] some cleanup and generic buffer piping --HG-- branch : pmacs2 --- application.py | 13 +++++++++++++ mode/perl.py | 27 +++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/application.py b/application.py index 99ac837..03dcae5 100755 --- a/application.py +++ b/application.py @@ -626,6 +626,19 @@ class Application(object): else: 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): curses.reset_shell_mode() try: diff --git a/mode/perl.py b/mode/perl.py index c80a3a5..650a48d 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -1,4 +1,5 @@ import os, re, string, sys +from subprocess import Popen, PIPE, STDOUT import buffer, color, commands, completer, context, default, method, mode, regex, tab from point import Point from lex import Grammar, PatternRule, ContextPatternRule, RegionRule, \ @@ -196,25 +197,19 @@ class PerlSetLib(Method): class PerlCheckSyntax(Method): '''Check the syntax of a perl file''' def _execute(self, w, **vargs): - app = w.application - perllib = w.application.config.get('perl.lib') - if perllib: - cmd = "perl -c -I '%s' '%s'" % (perllib, w.buffer.path) - 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) + a = w.application + args = ('perl', '-I', a.config.get('perl.lib', '.'), '-c', '-') + retval = a.run_pipe(args, w.buffer, '*Perl-Syntax*', lambda x: x != 0) + if retval == 0: a.set_error("Syntax OK") 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): - cmd = "perldoc -t -T '%s'" % w.buffer.path - (status, output) = commands.getstatusoutput(cmd) - w.application.data_buffer("*Perldoc*", output, switch_to=True) + app = w.application + args = ('perl', '-e', self.prog) + app.run_pipe(args, w.buffer, '*Perldoc*', True) class PerlViewWordPerldoc(Method): '''View documentation about a package or function using perldoc'''