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