Skip to content
Browse files

Some houskeeping after pull-request:

1) change context menu Kill option to use repl.kill() instead of signal
2) disable autoindent in repl
3) fix regression with manual repl clear (ctrl+a, del)
4) make delta positive ;)
5) store _killed information
  • Loading branch information...
1 parent 6ae6283 commit 59e52f4f4410f66a291327d3591cae76ff5f93b7 @wuub wuub committed Jun 7, 2012
Showing with 48 additions and 43 deletions.
  1. +1 −1 Context.sublime-menu
  2. +39 −40 sublimerepl.py
  3. +6 −2 subprocess_repl.py
  4. +2 −0 telnet_repl.py
View
2 Context.sublime-menu
@@ -1,5 +1,5 @@
[
{"caption": "-"},
- {"command": "subprocess_repl_send_signal", "caption": "Kill (send SIGTERM)", "args": {"signal": "SIGTERM"}},
+ {"command": "repl_kill", "caption": "Kill"},
{"command": "subprocess_repl_send_signal", "caption": "Send other SIGNAL"}
]
View
79 sublimerepl.py
@@ -196,6 +196,10 @@ def __init__(self, view, repl, syntax):
view.settings().set("repl_id", repl.id)
view.settings().set("repl", True)
view.settings().set("translate_tabs_to_spaces", False)
+ view.settings().set("auto_indent", False)
+ view.settings().set("smart_indent", False)
+ view.settings().set("indent_subsequent_lines", False)
+ view.settings().set("detect_indentation", False)
self._repl_reader = ReplReader(repl)
self._repl_reader.start()
@@ -273,15 +277,13 @@ def new_output(self):
return data, True
def update_view_loop(self):
- if hasattr(self, "killed") and self.killed:
- return
(data, is_still_working) = self.new_output()
if data:
self.write(data)
if is_still_working:
sublime.set_timeout(self.update_view_loop, 100)
else:
- self.write("\n***Repl Closed***\n""")
+ self.write("\n***Repl Killed***\n""" if self.repl._killed else "\n***Repl Closed***\n""")
self._view.set_read_only(True)
if sublime.load_settings(SETTINGS_FILE).get("view_auto_close"):
window = self._view.window()
@@ -308,11 +310,6 @@ def view_previous_command(self, edit):
def view_next_command(self, edit):
self.ensure_history_match()
self.replace_current_with_history(edit, self._history_match.next_command())
-
- def view_kill(self):
- self.killed = True
- self.write("\n***Repl Killed***\n""")
- self.repl.kill()
def replace_current_with_history(self, edit, cmd):
if not cmd:
@@ -333,6 +330,7 @@ def run(self, encoding, type, syntax=None, view_id=None, **kwds):
for view in self.window.views():
if view.id() == view_id:
found = view
+ break
view = found or window.new_file()
rv = ReplView(view, r, syntax)
repl_views[r.id] = rv
@@ -346,14 +344,10 @@ def run(self, encoding, type, syntax=None, view_id=None, **kwds):
class ReplEnterCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
- rv = repl_view(v)
- delta = v.sel()[0].begin() - rv._output_end
- if delta < 0:
- v.run_command("insert", {"characters": "\n"})
- return
if v.sel()[0].begin() != v.size():
v.sel().clear()
v.sel().add(sublime.Region(v.size()))
+ rv = repl_view(v)
rv.push_history(rv.user_input()) # don't include cmd_postfix in history
v.run_command("insert", {"characters": rv.repl.cmd_postfix})
command = rv.user_input()
@@ -376,13 +370,21 @@ def run(self, edit):
w.run_command("right_delete")
+def repl_view_delta(sublime_view):
+ """Return a repl_view and number of characters from current selection
+ to then beggingin of user_input (otherwise known as _output_end)"""
+ rv = repl_view(sublime_view)
+ if not rv:
+ return None, -1
+ delta = rv._output_end - sublime_view.sel()[0].begin()
+ return rv, delta
+
class ReplBackspaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
w = v.window()
- rv = repl_view(v)
- delta = v.sel()[0].begin() - rv._output_end
- if delta < 0:
+ rv, delta = repl_view_delta(v)
+ if delta > 0:
w.run_command("left_delete")
elif delta == 0:
return
@@ -394,9 +396,8 @@ class ReplLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
w = v.window()
- rv = repl_view(v)
- delta = v.sel()[0].begin() - rv._output_end
- if delta < 0:
+ rv, delta = repl_view_delta(v)
+ if delta > 0:
w.run_command("move", {"by": "characters", "forward": False, "extend": False})
elif delta == 0:
return
@@ -408,9 +409,8 @@ class ReplShiftLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
w = v.window()
- rv = repl_view(v)
- delta = v.sel()[0].begin() - rv._output_end
- if delta < 0:
+ rv, delta = repl_view_delta(v)
+ if delta > 0:
w.run_command("move", {"by": "characters", "forward": False, "extend": True})
elif delta == 0:
return
@@ -422,9 +422,8 @@ class ReplHomeCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
w = v.window()
- rv = repl_view(v)
- delta = v.sel()[0].begin() - rv._output_end
- if delta < 0:
+ rv, delta = repl_view_delta(v)
+ if delta > 0:
w.run_command("move_to", {"to": "bol", "extend": False})
else:
for i in range(1, delta + 1):
@@ -435,43 +434,43 @@ class ReplShiftHomeCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
w = v.window()
- rv = repl_view(v)
- delta = v.sel()[0].begin() - rv._output_end
- if delta < 0:
+ rv, delta = repl_view_delta(v)
+ if delta > 0:
w.run_command("move_to", {"to": "bol", "extend": True})
else:
- for i in range(1, delta + 1):
+ for i in range(abs(delta)):
w.run_command("move", {"by": "characters", "forward": False, "extend": True})
class ReplViewPreviousCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = repl_view(self.view)
- rv.scroll_to_end()
- repl_view(self.view).view_previous_command(edit)
+ if rv:
+ rv.scroll_to_end()
+ repl_view(self.view).view_previous_command(edit)
class ReplViewNextCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = repl_view(self.view)
- rv.scroll_to_end()
- repl_view(self.view).view_next_command(edit)
+ if rv:
+ rv.scroll_to_end()
+ repl_view(self.view).view_next_command(edit)
class ReplKillCommand(sublime_plugin.TextCommand):
def run(self, edit):
- repl = repl_view(self.view)
- if repl:
- repl.view_kill()
+ rv = repl_view(self.view)
+ if rv:
+ rv.repl.kill()
class SublimeReplListener(sublime_plugin.EventListener):
def on_close(self, view):
rv = repl_view(view)
- if not rv:
- return
- rv.repl.close()
- _delete_repl(view)
+ if rv:
+ rv.repl.close()
+ _delete_repl(view)
class SubprocessReplSendSignal(sublime_plugin.TextCommand):
View
8 subprocess_repl.py
@@ -37,6 +37,7 @@ def __init__(self, encoding, external_id=None, cmd_postfix="\n", suppress_echo=F
env = self.env(env, extend_env, settings)
self._cmd = self.cmd(cmd, env)
self._soft_quit = soft_quit
+ self._killed = False
self.popen = killableprocess.Popen(
self._cmd,
startupinfo=self.startupinfo(settings),
@@ -127,6 +128,7 @@ def write_bytes(self, bytes):
si.flush()
def kill(self):
+ self._killed = True
self.write(self._soft_quit)
self.popen.kill()
@@ -138,7 +140,9 @@ def available_signals(self):
signals[k] = v
return signals
- def send_signal(self, signal):
+ def send_signal(self, sig):
+ if sig==signal.SIGTERM:
+ self._killed = True
if self.is_alive():
- self.popen.send_signal(signal)
+ self.popen.send_signal(sig)
View
2 telnet_repl.py
@@ -23,6 +23,7 @@ def __init__(self, encoding, external_id=None, host="localhost", port=23, cmd_po
# as long as it can be turned into an INT
self._telnet.open(host, int(port))
self._alive = True
+ self._killed = False
def name(self):
return "%s:%s" % (self._telnet.host, self._telnet.port)
@@ -37,5 +38,6 @@ def write_bytes(self, bytes):
self._telnet.write(bytes)
def kill(self):
+ self._killed = True
self._telnet.close()
self._alive = False

0 comments on commit 59e52f4

Please sign in to comment.
Something went wrong with that request. Please try again.