parent
9bdaade444
commit
551589644d
|
@ -646,7 +646,7 @@ class Application(object):
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# running external programs
|
# running external programs
|
||||||
def run_pipe(self, args, b, name='*Output*', switch='yes', modename=None):
|
def run_pipe(self, args, b, name='*Output*', switch=True, modename=None):
|
||||||
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
pipe = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
|
||||||
pipe.stdin.write(b.make_string())
|
pipe.stdin.write(b.make_string())
|
||||||
pipe.stdin.close()
|
pipe.stdin.close()
|
||||||
|
|
109
mode/perl.py
109
mode/perl.py
|
@ -1,6 +1,6 @@
|
||||||
import os, re, string, sys
|
import os, re, string, sys
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
import buffer, color, commands, completer, context, default, method, mode, regex, tab
|
import buffer, color, commands, completer, context, 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, \
|
||||||
OverridePatternRule, PatternGroupRule
|
OverridePatternRule, PatternGroupRule
|
||||||
|
@ -192,48 +192,48 @@ class PerlTabber2(StackTabber2):
|
||||||
|
|
||||||
class PerlSetLib(Method):
|
class PerlSetLib(Method):
|
||||||
'''Set the path(s) to find perl modules'''
|
'''Set the path(s) to find perl modules'''
|
||||||
args = [Argument("lib", type=type(""), prompt="Location of lib: ",
|
args = [method.arg("lib", dt='path', p="Lib: ", dv=lambda w: '.')]
|
||||||
default=default.build_constant("."))]
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.application.config['perl.lib'] = vargs['lib']
|
w.application.config['perl.libs'] = vargs['lib'].split(':')
|
||||||
w.application.config['perl.libs'] = [vargs['lib']]
|
class PerlAddLib(PerlSetLib):
|
||||||
class PerlAddLib(Method):
|
|
||||||
'''Set the path(s) to find perl modules'''
|
'''Set the path(s) to find perl modules'''
|
||||||
args = [Argument("lib", type=type(""), prompt="Location of lib: ",
|
|
||||||
default=default.build_constant("."))]
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.application.config['perl.libs'].append(vargs['lib'])
|
w.application.config['perl.libs'].append(vargs['lib'])
|
||||||
|
|
||||||
class PerlCheckSyntax(Method):
|
class PerlBase(Method):
|
||||||
|
bname = '*Perl*'
|
||||||
|
def get_args(self, w, **vargs):
|
||||||
|
return ['perl', '-e', 'print "hello world\n"']
|
||||||
|
def run_pipe(self, w, args, switch, mname=None):
|
||||||
|
return w.application.run_pipe(args, w.buffer, self.bname, switch, mname)
|
||||||
|
|
||||||
|
class PerlCheckSyntax(PerlBase):
|
||||||
'''Check the syntax of a perl file'''
|
'''Check the syntax of a perl file'''
|
||||||
def _execute(self, w, **vargs):
|
bname = '*Perl-Syntax*'
|
||||||
a = w.application
|
def get_args(self, w, **vargs):
|
||||||
if a.config.get('perl.libs', None):
|
|
||||||
args = ['perl']
|
args = ['perl']
|
||||||
for l in a.config.get('perl.libs'):
|
for l in w.application.config.get('perl.libs', []):
|
||||||
args.extend(('-I', l))
|
args.extend(('-I', l))
|
||||||
args.extend(('-c', '-'))
|
return args + ['-c', '-']
|
||||||
else:
|
|
||||||
args = ('perl', '-I', a.config.get('perl.lib', '.'), '-c', '-')
|
|
||||||
retval = a.run_pipe(args, w.buffer, '*Perl-Syntax*', lambda x: x != 0,
|
|
||||||
modename='error')
|
|
||||||
b = a.get_buffer_by_name('*Perl-Syntax*')
|
|
||||||
b.orig_path = w.buffer.path
|
|
||||||
if retval == 0: a.set_error("Syntax OK")
|
|
||||||
|
|
||||||
|
|
||||||
class PerldocModule(Method):
|
|
||||||
'''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):
|
||||||
app = w.application
|
args = self.get_args(w, **vargs)
|
||||||
args = ('perl', '-e', self.prog)
|
r = self.run_pipe(w, args, lambda x: x != 0, 'error')
|
||||||
app.run_pipe(args, w.buffer, '*Perldoc*', True)
|
b = w.application.get_buffer_by_name(self.bname)
|
||||||
|
b.orig_path = w.buffer.path
|
||||||
|
if r == 0: w.set_error("Syntax OK")
|
||||||
|
|
||||||
|
class PerldocModule(PerlBase):
|
||||||
|
'''View documentation about this buffer using perldoc'''
|
||||||
|
bname = '*Perldoc*'
|
||||||
|
prog = 'use Pod::Text; Pod::Text->new()->parse_from_filehandle();';
|
||||||
|
def get_args(self, w, **vargs):
|
||||||
|
return ('perl', '-e', self.prog)
|
||||||
|
def _execute(self, w, **vargs):
|
||||||
|
self.run_pipe(w, self.get_args(w, **vargs), True)
|
||||||
|
|
||||||
class Perldoc(Method):
|
class Perldoc(Method):
|
||||||
name_re = re.compile('(?:[a-zA-Z_][a-zA-Z0-9_]*::)*[a-zA-Z_][a-zA-Z0-9_]*')
|
name_re = re.compile('(?:[a-zA-Z_][a-zA-Z0-9_]*::)*[a-zA-Z_][a-zA-Z0-9_]*')
|
||||||
args = [Argument("name", type(""), "", "Perldoc: ")]
|
args = [method.arg("name", p="Perldoc: ")]
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
name = vargs['name']
|
name = vargs['name']
|
||||||
if not self.name_re.match(name):
|
if not self.name_re.match(name):
|
||||||
|
@ -255,42 +255,33 @@ class Perldoc(Method):
|
||||||
if data:
|
if data:
|
||||||
self._show(w, data, name)
|
self._show(w, data, name)
|
||||||
else:
|
else:
|
||||||
w.application.set_error('nothing found for %r' % name)
|
w.set_error('nothing found for %r' % name)
|
||||||
def _try(self, w, name, asfunc=False):
|
def _try(self, w, name, asfunc=False):
|
||||||
a = w.application
|
|
||||||
if asfunc:
|
if asfunc:
|
||||||
cmd = "perldoc -t -T -f '%s'" % (name,)
|
cmd = "perldoc -t -T -f '%s'" % name
|
||||||
else:
|
else:
|
||||||
cmd = "perldoc -t -T '%s'" % (name,)
|
cmd = "perldoc -t -T '%s'" % name
|
||||||
|
|
||||||
if a.config.get('perl.libs', None):
|
l = w.application.config.get('perl.libs', [])
|
||||||
s = ':'.join(['%r' % x for x in a.config.get('perl.libs')])
|
if l:
|
||||||
cmd = 'PERL5LIB=%r %s' % (s, cmd)
|
cmd = 'PERL5LIB=%r %s' % (':'.join(['%r' % x for x in l]), cmd)
|
||||||
elif a.config.get('perl.lib', None):
|
|
||||||
cmd = 'PERL5LIB=%r %s' % (a.config.get('perl.lib'), cmd)
|
|
||||||
|
|
||||||
(status, data) = commands.getstatusoutput(cmd)
|
status, data = commands.getstatusoutput(cmd)
|
||||||
if status == 0:
|
if status == 0:
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
def _show(self, w, data, name):
|
def _show(self, w, data, name):
|
||||||
w.application.data_buffer("*Perldoc*", data, switch_to=True)
|
w.application.data_buffer("*Perldoc*", data, switch_to=True)
|
||||||
w.application.set_error('displaying documentation for %r' % name)
|
w.set_error('displaying perldoc for %r' % name)
|
||||||
|
|
||||||
class PerldocWord(Perldoc):
|
class PerldocWord(Perldoc):
|
||||||
'''View documentation about a package or function using perldoc'''
|
'''View documentation about a package or function using perldoc'''
|
||||||
args = []
|
args = []
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
token = w.get_token()
|
word = w.get_token().string
|
||||||
word = token.string
|
|
||||||
|
|
||||||
# make sure that the name is (mostly) valid
|
|
||||||
if word is None:
|
if word is None:
|
||||||
w.application.set_error('no word selected')
|
w.set_error('no word selected')
|
||||||
return
|
|
||||||
elif ':' in word and '::' not in word:
|
|
||||||
w.application.set_error('invalid word: %r' % word)
|
|
||||||
return
|
return
|
||||||
return Perldoc._execute(self, w, name=word)
|
return Perldoc._execute(self, w, name=word)
|
||||||
|
|
||||||
|
@ -298,7 +289,7 @@ class PerlInitFunctions(Method):
|
||||||
'''Jump to a function defined in this module'''
|
'''Jump to a function defined in this module'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.mode.context.build_name_map()
|
w.mode.context.build_name_map()
|
||||||
w.application.set_error("Initialized function map")
|
w.set_error("Initialized function map")
|
||||||
|
|
||||||
class PerlGotoFunction(Method):
|
class PerlGotoFunction(Method):
|
||||||
'''Jump to a function defined in this module'''
|
'''Jump to a function defined in this module'''
|
||||||
|
@ -309,7 +300,7 @@ class PerlGotoFunction(Method):
|
||||||
if name in functions:
|
if name in functions:
|
||||||
w.goto(Point(0, functions[name]))
|
w.goto(Point(0, functions[name]))
|
||||||
else:
|
else:
|
||||||
w.application.set_error("Function %r was not found" % name)
|
w.set_error("Function %r was not found" % name)
|
||||||
|
|
||||||
class PerlListFunctions(Method):
|
class PerlListFunctions(Method):
|
||||||
'''Show the user all functions defined in this module'''
|
'''Show the user all functions defined in this module'''
|
||||||
|
@ -324,11 +315,11 @@ class PerlWhichFunction(Method):
|
||||||
cursor = w.logical_cursor()
|
cursor = w.logical_cursor()
|
||||||
name = w.mode.context.get_line_name(cursor.y)
|
name = w.mode.context.get_line_name(cursor.y)
|
||||||
if name is None:
|
if name is None:
|
||||||
w.application.set_error("None");
|
w.set_error("None");
|
||||||
else:
|
else:
|
||||||
functions = w.mode.context.get_names()
|
functions = w.mode.context.get_names()
|
||||||
i = functions[name] + 1
|
i = functions[name] + 1
|
||||||
w.application.set_error("line %d: %s" % (i, name))
|
w.set_error("line %d: %s" % (i, name))
|
||||||
|
|
||||||
class PerlHashCleanup(Method):
|
class PerlHashCleanup(Method):
|
||||||
'''Correctly align assignment blocks and literal hashes'''
|
'''Correctly align assignment blocks and literal hashes'''
|
||||||
|
@ -729,10 +720,8 @@ class Perl(mode.Fundamental):
|
||||||
'translate.end': ('magenta', 'default', 'bold'),
|
'translate.end': ('magenta', 'default', 'bold'),
|
||||||
'translate.null': ('magenta', 'default', 'bold'),
|
'translate.null': ('magenta', 'default', 'bold'),
|
||||||
}
|
}
|
||||||
config = {
|
config = {}
|
||||||
'perl.lib': 'lib',
|
lconfig = {'perl.libs': []}
|
||||||
'perl.libs': ['lib'],
|
|
||||||
}
|
|
||||||
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup,
|
actions = [PerlSetLib, PerlCheckSyntax, PerlHashCleanup,
|
||||||
PerldocModule, PerldocWord, Perldoc, PerlWrapParagraph,
|
PerldocModule, PerldocWord, Perldoc, PerlWrapParagraph,
|
||||||
PerlInitFunctions, PerlGotoFunction, PerlWhichFunction,
|
PerlInitFunctions, PerlGotoFunction, PerlWhichFunction,
|
||||||
|
@ -788,10 +777,8 @@ class Perl(mode.Fundamental):
|
||||||
if a.config.get('perl.libs', None):
|
if a.config.get('perl.libs', None):
|
||||||
s = ':'.join(['%s' % x for x in a.config.get('perl.libs')])
|
s = ':'.join(['%s' % x for x in a.config.get('perl.libs')])
|
||||||
cmd = 'PERL5LIB=%r %s' % (s, cmd)
|
cmd = 'PERL5LIB=%r %s' % (s, cmd)
|
||||||
elif a.config.get('perl.lib', None):
|
|
||||||
cmd = 'PERL5LIB=%r %s' % (a.config.get('perl.lib'), cmd)
|
|
||||||
|
|
||||||
(status, data) = commands.getstatusoutput(cmd)
|
(status, data) = commands.getstatusoutput(cmd)
|
||||||
|
|
||||||
if status != 0:
|
if status != 0:
|
||||||
raise Exception, "%r failed" % cmd
|
raise Exception, "%r failed" % cmd
|
||||||
self.perlinc = data.split('\n')
|
self.perlinc = data.split('\n')
|
||||||
|
|
Loading…
Reference in New Issue