parent
a2b8913d04
commit
aa6347d4c6
124
buffer.py
124
buffer.py
|
@ -399,41 +399,16 @@ class ConsoleBuffer(Buffer):
|
|||
def readonly(self):
|
||||
return True
|
||||
|
||||
iperl = None
|
||||
class IperlBuffer(Buffer):
|
||||
btype = 'iperl'
|
||||
modename = 'iperl'
|
||||
def __new__(cls, *args, **kwargs):
|
||||
global iperl
|
||||
if iperl is None:
|
||||
iperl = object.__new__(IperlBuffer, *args, **kwargs)
|
||||
return iperl
|
||||
def __init__(self):
|
||||
Buffer.__init__(self)
|
||||
self.clear()
|
||||
def clear(self):
|
||||
iperl.set_data('', force=True)
|
||||
def name(self):
|
||||
return '*IPerl*'
|
||||
def changed(self):
|
||||
return False
|
||||
def close(self):
|
||||
global iperl
|
||||
iperl = None
|
||||
def readonly(self):
|
||||
return True
|
||||
|
||||
class IperlBuffer2(Buffer):
|
||||
def get_iperl_name(parent):
|
||||
class InterpreterBuffer(Buffer):
|
||||
_basename = 'Interpreter'
|
||||
def create_name(cls, parent):
|
||||
if hasattr(parent, 'path'):
|
||||
return '*IPerl:%s*' % parent.name()
|
||||
return '*%s:%s*' % (cls._basename, parent.name())
|
||||
else:
|
||||
return '*IPerl*'
|
||||
get_iperl_name = classmethod(get_iperl_name)
|
||||
btype = 'iperl'
|
||||
modename = 'iperl'
|
||||
return '*%s*' % cls._basename
|
||||
create_name = classmethod(create_name)
|
||||
btype = 'interpreter'
|
||||
readre = re.compile('^([A-Z]+):(.*)\n$')
|
||||
_name = '*IPerl*'
|
||||
def __init__(self, parent):
|
||||
if hasattr(parent, 'path'):
|
||||
self.parent = parent
|
||||
|
@ -445,14 +420,11 @@ class IperlBuffer2(Buffer):
|
|||
self.prompt = '***'
|
||||
self.clear()
|
||||
self.pipe_read()
|
||||
self._name = get_iperl_name(parent)
|
||||
self._name = self.create_name(parent)
|
||||
def name(self):
|
||||
return self._name
|
||||
def get_cmd(self):
|
||||
if self.parent:
|
||||
return ('iperl', '-p', self.parent.path)
|
||||
else:
|
||||
return ('iperl',)
|
||||
raise Exception, 'unimplemented'
|
||||
def pipe_readline(self):
|
||||
line = self.pipe.stdout.readline()
|
||||
m = self.readre.match(line)
|
||||
|
@ -482,7 +454,6 @@ class IperlBuffer2(Buffer):
|
|||
assert typ_ == 'COMPLETIONS', '%r %r' % (typ_, value)
|
||||
candidates = [x for x in value.split('|') if x]
|
||||
return candidates
|
||||
|
||||
def clear(self):
|
||||
self.set_data('', force=True)
|
||||
def changed(self):
|
||||
|
@ -490,72 +461,25 @@ class IperlBuffer2(Buffer):
|
|||
def readonly(self):
|
||||
return True
|
||||
|
||||
class IpythonBuffer(Buffer):
|
||||
def get_ipython_name(parent):
|
||||
if hasattr(parent, 'path'):
|
||||
return '*IPython:%s*' % parent.name()
|
||||
else:
|
||||
return '*IPython*'
|
||||
get_ipython_name = classmethod(get_ipython_name)
|
||||
btype = 'ipython'
|
||||
modename = 'ipython'
|
||||
readre = re.compile('^([A-Z]+):(.*)\n$')
|
||||
_name = '*IPython*'
|
||||
def __init__(self, parent):
|
||||
if hasattr(parent, 'path'):
|
||||
self.parent = parent
|
||||
else:
|
||||
self.parent = None
|
||||
Buffer.__init__(self)
|
||||
f = open('/dev/null', 'w')
|
||||
self.pipe = Popen(self.get_cmd(), stdin=PIPE, stdout=PIPE, stderr=f)
|
||||
self.prompt = '***'
|
||||
self.clear()
|
||||
self.pipe_read()
|
||||
self._name = get_ipython_name(parent)
|
||||
def name(self):
|
||||
return self._name
|
||||
class IperlBuffer(InterpreterBuffer):
|
||||
_basename = 'IPerl'
|
||||
btype = 'iperl'
|
||||
modename = 'iperl'
|
||||
def get_cmd(self):
|
||||
if self.parent:
|
||||
return ('epython', '-p', self.parent.path)
|
||||
return ('iperl', '-p', '-r', self.parent.path)
|
||||
else:
|
||||
return ('epython',)
|
||||
def pipe_readline(self):
|
||||
line = self.pipe.stdout.readline()
|
||||
m = self.readre.match(line)
|
||||
if m:
|
||||
return (m.group(1), m.group(2))
|
||||
else:
|
||||
return (None, line.rstrip())
|
||||
def pipe_read(self):
|
||||
lines = []
|
||||
while True:
|
||||
(type_, value) = self.pipe_readline()
|
||||
if type_ == 'PROMPT':
|
||||
self.prompt = value.strip() + ' '
|
||||
break
|
||||
value.rstrip()
|
||||
if value:
|
||||
lines.append(value)
|
||||
if lines:
|
||||
output = '\n'.join(lines) + '\n'
|
||||
p = self.get_buffer_end()
|
||||
self.insert_string(p, output, force=True)
|
||||
def pipe_write(self, s):
|
||||
self.pipe.stdin.write("%s\n" % s)
|
||||
self.pipe.stdin.flush()
|
||||
def pipe_read_completions(self):
|
||||
(typ_, value) = self.pipe_readline()
|
||||
assert typ_ == 'COMPLETIONS', '%r %r' % (typ_, value)
|
||||
candidates = [x for x in value.split('|') if x]
|
||||
return candidates
|
||||
return ('iperl', '-p')
|
||||
|
||||
def clear(self):
|
||||
self.set_data('', force=True)
|
||||
def changed(self):
|
||||
return False
|
||||
def readonly(self):
|
||||
return True
|
||||
class IpythonBuffer(InterpreterBuffer):
|
||||
_basename = 'IPython'
|
||||
btype = 'ipython'
|
||||
modename = 'ipython'
|
||||
def get_cmd(self):
|
||||
if self.parent:
|
||||
return ('epython', '-p', '-r', self.parent.path)
|
||||
else:
|
||||
return ('epython', '-p')
|
||||
|
||||
class BinaryDataException(Exception):
|
||||
pass
|
||||
|
|
|
@ -66,10 +66,11 @@ class IperlStart(method.Method):
|
|||
def execute(self, w, **vargs):
|
||||
a = w.application
|
||||
if not a.has_buffer_name('*IPerl*'):
|
||||
b = buffer.IperlBuffer()
|
||||
b = buffer.IperlBuffer(None)
|
||||
a.add_buffer(b)
|
||||
window.Window(b, a)
|
||||
b = a.bufferlist.get_buffer_by_name('*IPerl*')
|
||||
else:
|
||||
b = a.bufferlist.get_buffer_by_name('*IPerl*')
|
||||
if a.window().buffer is not b:
|
||||
a.switch_buffer(b)
|
||||
f = lambda x: None
|
||||
|
@ -117,8 +118,11 @@ class IperlMini(mode.Fundamental):
|
|||
def _get_iperl(self):
|
||||
a = self.window.application
|
||||
if not a.has_buffer_name('*IPerl*'):
|
||||
raise Exception, "No iperl found!"
|
||||
b = a.bufferlist.get_buffer_by_name('*IPerl*')
|
||||
b = buffer.IperlBuffer(None)
|
||||
a.add_buffer(b)
|
||||
window.Window(b, a)
|
||||
else:
|
||||
b = a.bufferlist.get_buffer_by_name('*IPerl*')
|
||||
return b
|
||||
|
||||
def __init__(self, w):
|
||||
|
|
|
@ -76,7 +76,7 @@ class IpythonPathStart(method.Method):
|
|||
if w.buffer.btype == 'ipython':
|
||||
b = w.buffer
|
||||
else:
|
||||
name = buffer.IpythonBuffer.get_ipython_name(w.buffer)
|
||||
name = buffer.IpythonBuffer.create_name(w.buffer)
|
||||
if not a.has_buffer_name(name):
|
||||
b = buffer.IpythonBuffer(w.buffer)
|
||||
a.add_buffer(b)
|
||||
|
|
|
@ -98,7 +98,8 @@ if __name__ == "__main__":
|
|||
stanzas.append(('path', value))
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('-e', '--eval', type='string', action='callback', callback=add_eval)
|
||||
parser.add_option('-p', '--path', type='string', action='callback', callback=add_path)
|
||||
parser.add_option('-r', '--run', type='string', action='callback', callback=add_path)
|
||||
parser.add_option('-p', '--pipe', action='store_true')
|
||||
parser.parse_args()
|
||||
del parser, add_path, add_eval
|
||||
|
||||
|
|
Loading…
Reference in New Issue