parent
aa6347d4c6
commit
166285a8e2
14
buffer.py
14
buffer.py
|
@ -409,20 +409,26 @@ class InterpreterBuffer(Buffer):
|
|||
create_name = classmethod(create_name)
|
||||
btype = 'interpreter'
|
||||
readre = re.compile('^([A-Z]+):(.*)\n$')
|
||||
def __init__(self, parent):
|
||||
def __init__(self, parent, app):
|
||||
self.application = app
|
||||
if hasattr(parent, 'path'):
|
||||
self.parent = parent
|
||||
else:
|
||||
self.parent = None
|
||||
Buffer.__init__(self)
|
||||
cmd = self.get_cmd()
|
||||
env = dict(os.environ)
|
||||
env.update(self.get_env())
|
||||
f = open('/dev/null', 'w')
|
||||
self.pipe = Popen(self.get_cmd(), stdin=PIPE, stdout=PIPE, stderr=f)
|
||||
self.pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=f, env=env)
|
||||
self.prompt = '***'
|
||||
self.clear()
|
||||
self.pipe_read()
|
||||
self._name = self.create_name(parent)
|
||||
def name(self):
|
||||
return self._name
|
||||
def get_env(self):
|
||||
return {}
|
||||
def get_cmd(self):
|
||||
raise Exception, 'unimplemented'
|
||||
def pipe_readline(self):
|
||||
|
@ -470,6 +476,8 @@ class IperlBuffer(InterpreterBuffer):
|
|||
return ('iperl', '-p', '-r', self.parent.path)
|
||||
else:
|
||||
return ('iperl', '-p')
|
||||
def get_env(self):
|
||||
return {'PERL5LIB': self.application.config.get('perl.lib', '.')}
|
||||
|
||||
class IpythonBuffer(InterpreterBuffer):
|
||||
_basename = 'IPython'
|
||||
|
@ -480,6 +488,8 @@ class IpythonBuffer(InterpreterBuffer):
|
|||
return ('epython', '-p', '-r', self.parent.path)
|
||||
else:
|
||||
return ('epython', '-p')
|
||||
def get_env(self):
|
||||
return {'PYTHONPATH': self.application.config.get('python.lib', '.')}
|
||||
|
||||
class BinaryDataException(Exception):
|
||||
pass
|
||||
|
|
|
@ -61,20 +61,32 @@ class IperlTab(method.Method):
|
|||
w.insert_string_at_cursor(s)
|
||||
mode.mini.use_completion_window(a, s, candidates)
|
||||
|
||||
class IperlStart(method.Method):
|
||||
'''Evaluate python expressions (for advanced use and debugging only)'''
|
||||
def execute(self, w, **vargs):
|
||||
class IperlPathStart(method.Method):
|
||||
'''Interactively run perl statements in the context of a buffer'''
|
||||
def _start(self, w, parent):
|
||||
a = w.application
|
||||
if not a.has_buffer_name('*IPerl*'):
|
||||
b = buffer.IperlBuffer(None)
|
||||
a.add_buffer(b)
|
||||
window.Window(b, a)
|
||||
if w.buffer.btype == 'iperl':
|
||||
b = w.buffer
|
||||
else:
|
||||
b = a.bufferlist.get_buffer_by_name('*IPerl*')
|
||||
name = buffer.IperlBuffer.create_name(parent)
|
||||
if not a.has_buffer_name(name):
|
||||
b = buffer.IperlBuffer(parent, a)
|
||||
a.add_buffer(b)
|
||||
window.Window(b, a)
|
||||
else:
|
||||
b = a.get_buffer_by_name(name)
|
||||
self.main_buffer = b
|
||||
if a.window().buffer is not b:
|
||||
a.switch_buffer(b)
|
||||
f = lambda x: None
|
||||
w.application.open_mini_buffer('*** ', f, self, None, 'iperlmini')
|
||||
def execute(self, w, **vargs):
|
||||
self._start(w, w.buffer)
|
||||
|
||||
class IperlStart(IperlPathStart):
|
||||
'''Interactively run perl statements'''
|
||||
def execute(self, w, **vargs):
|
||||
self._start(w, None)
|
||||
|
||||
class IperlPageUp(mode.consolemini.ConsolePageUp):
|
||||
subbuf = '*IPerl*'
|
||||
|
@ -87,7 +99,7 @@ class IperlGotoEnd(mode.consolemini.ConsoleGotoEnd):
|
|||
|
||||
class IperlMini(mode.Fundamental):
|
||||
modename = 'IperlMini'
|
||||
actions = [IperlExec, IperlTab, IperlStart,
|
||||
actions = [IperlExec, IperlTab, IperlStart, IperlPathStart,
|
||||
IperlPageUp, IperlPageDown, IperlGotoBeginning, IperlGotoEnd]
|
||||
readre = re.compile('^([A-Z]+):(.*)\n$')
|
||||
def _readline(self):
|
||||
|
@ -130,13 +142,7 @@ class IperlMini(mode.Fundamental):
|
|||
self.history = ['']
|
||||
self.hindex = 0
|
||||
b = self._get_iperl()
|
||||
if hasattr(b, 'pipe'):
|
||||
self.window.application.set_mini_buffer_prompt(b.prompt)
|
||||
else:
|
||||
cmd = ('iperl', '-p')
|
||||
f = open('/dev/null', 'w')
|
||||
b.pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=f)
|
||||
self._read()
|
||||
w.application.set_mini_buffer_prompt(b.prompt)
|
||||
self.add_bindings('iperl-exec', ('RETURN',))
|
||||
self.add_bindings('console-clear', ('C-l',))
|
||||
self.add_bindings('console-cancel', ('C-]',))
|
||||
|
|
|
@ -54,31 +54,16 @@ class IpythonTab(method.Method):
|
|||
elif a.completion_window_is_open():
|
||||
a.close_completion_buffer()
|
||||
|
||||
class IpythonStart(method.Method):
|
||||
'''Evaluate python expressions (for advanced use and debugging only)'''
|
||||
def execute(self, w, **vargs):
|
||||
a = w.application
|
||||
if not a.has_buffer_name('*IPython*'):
|
||||
b = buffer.IpythonBuffer(None)
|
||||
a.add_buffer(b)
|
||||
window.Window(b, a)
|
||||
b = a.bufferlist.get_buffer_by_name('*IPython*')
|
||||
self.main_buffer = b
|
||||
if a.window().buffer is not b:
|
||||
a.switch_buffer(b)
|
||||
f = lambda x: None
|
||||
w.application.open_mini_buffer('*** ', f, self, None, 'ipythonmini')
|
||||
|
||||
class IpythonPathStart(method.Method):
|
||||
'''xyz'''
|
||||
def execute(self, w, **vargs):
|
||||
'''Interactively run python statements in the context of a buffer'''
|
||||
def _start(self, w, parent):
|
||||
a = w.application
|
||||
if w.buffer.btype == 'ipython':
|
||||
b = w.buffer
|
||||
else:
|
||||
name = buffer.IpythonBuffer.create_name(w.buffer)
|
||||
name = buffer.IpythonBuffer.create_name(parent)
|
||||
if not a.has_buffer_name(name):
|
||||
b = buffer.IpythonBuffer(w.buffer)
|
||||
b = buffer.IpythonBuffer(parent, a)
|
||||
a.add_buffer(b)
|
||||
window.Window(b, a)
|
||||
else:
|
||||
|
@ -88,6 +73,13 @@ class IpythonPathStart(method.Method):
|
|||
a.switch_buffer(b)
|
||||
f = lambda x: None
|
||||
w.application.open_mini_buffer('*** ', f, self, None, 'ipythonmini')
|
||||
def execute(self, w, **vargs):
|
||||
self._start(w, w.buffer)
|
||||
|
||||
class IpythonStart(IpythonPathStart):
|
||||
'''Interactively run python statements'''
|
||||
def execute(self, w, **vargs):
|
||||
self._start(w, None)
|
||||
|
||||
class IpythonPageUp(mode.consolemini.ConsolePageUp):
|
||||
subbuf = '*IPython*'
|
||||
|
|
|
@ -244,7 +244,7 @@ do with the way I evaluate blocks. Sorry.
|
|||
EOT
|
||||
|
||||
# the big one!
|
||||
sub main {
|
||||
sub run {
|
||||
# ugh stupid fucking Term::ReadLine's automatic escapes
|
||||
my ($prompt1, $prompt2) = (">>>", '..>');
|
||||
#my ($prompt1, $prompt2) = ("\001\033[24m\002>>>", "\001\033[24m\002..>");
|
||||
|
@ -379,4 +379,4 @@ sub main {
|
|||
}
|
||||
print "Bye.\n";
|
||||
}
|
||||
main();
|
||||
run();
|
||||
|
|
Loading…
Reference in New Issue