diff --git a/application.py b/application.py index 5a19a78..6edd614 100755 --- a/application.py +++ b/application.py @@ -397,7 +397,7 @@ class Application(object): def eval(self, s): return eval(s) - # the might run-loop! + # the mighty run-loop! def run(self): self.done = False while not self.done: @@ -420,6 +420,13 @@ class Application(object): if self.error_timestamp is not None and ERROR_TIMEOUT > 0 and \ time.time() - self.error_timestamp > ERROR_TIMEOUT: self.clear_error() + + # clear the error line; it might look confusing to the user + try: + self.win.addstr(self.y-1, 0, ' ' * self.x) + except: + pass + self.win.refresh() return # highlighting diff --git a/method.py b/method.py index 7698ade..a792d04 100644 --- a/method.py +++ b/method.py @@ -229,16 +229,34 @@ class KillBuffer(Method): default=default.current_buffer)] def _execute(self, w, **vargs): name = vargs['buffername'] - app = w.application - assert name in app.bufferlist.buffer_names, "Buffer %r does not exist" % name + a = w.application + assert name in a.bufferlist.buffer_names, "Buffer %r does not exist" % name assert name != '*Scratch*', "Can't kill scratch buffer" - b = app.bufferlist.buffer_names[name] - if not self.force: - assert not b.changed(), "Buffer %r has been modified" % (name) - if app.bufferlist.is_buffer_visible(b): - app.bufferlist.set_slot(app.active_slot, app.bufferlist.hidden_buffers[0]) - app.bufferlist.remove_buffer(b) + self._to_kill = a.bufferlist.buffer_names[name] + self._old_window = w + if self.force or not self._to_kill.changed(): + self._doit() + else: + self._prompt = "Buffer has unsaved changes; kill anyway? " + a.open_mini_buffer(self._prompt, self._callback) + def _doit(self): + a = self._old_window.application + b = self._to_kill + if a.bufferlist.is_buffer_visible(b): + a.bufferlist.set_slot(a.active_slot, a.bufferlist.hidden_buffers[0]) + a.bufferlist.remove_buffer(b) b.close() + def _callback(self, v): + a = self._old_window.application + if v == 'yes': + self._doit() + a.close_mini_buffer() + elif v == 'no': + a.close_mini_buffer() + else: + a.close_mini_buffer() + a.set_error('Please type "yes" or "no"') + class ForceKillBuffer(KillBuffer): force=True args = [Argument('buffername', datatype="buffer", prompt="Force Kill Buffer: ", @@ -297,20 +315,35 @@ class TransposeWords(Method): '''Switch the place of the two words nearest the cursor''' pass -# exit/exit2 +# you wanna quit right? class Exit(Method): '''Exit the program, unless there are unsaved changes''' def _execute(self, w, **vargs): + a = w.application + assert a.mini_buffer_is_open() is False, "Recursive minibuffer antics" + + changed = False for b in w.application.bufferlist.buffers: - if b.changed(): - s = "Buffer %s was modified" % b.name() - w.application.set_error(s) - return - w.application.exit() -class Exit2(Method): - '''Exit the program, discarding unsaved changes''' - def _execute(self, w, **vargs): - w.application.exit() + changed = b.changed() + if changed: + break + if not changed: + w.application.exit() + return + else: + self._old_window = w + self._prompt = "There are buffers with unsaved changes; exit? " + a.open_mini_buffer(self._prompt, self._callback) + + def _callback(self, v): + a = self._old_window.application + if v == 'yes': + a.exit() + a.close_mini_buffer() + if v == 'no': + return + a.open_mini_buffer(self._prompt, self._callback) + a.set_error('Please type "yes" or "no"') # insert text class InsertString(Method): diff --git a/mode2.py b/mode2.py index 35e0525..f2cc6c7 100644 --- a/mode2.py +++ b/mode2.py @@ -127,7 +127,6 @@ class Fundamental(Handler): self.add_bindings('replace', ('M-%',)) self.add_bindings('open-file', ('C-x C-f',)) self.add_bindings('kill-buffer', ('C-x k',)) - self.add_bindings('force-kill-buffer', ('C-x K',)) self.add_bindings('list-buffers', ('C-x C-b',)) self.add_bindings('meta-x', ('M-x',)) self.add_bindings('wrap-line', ('M-q',)) @@ -136,7 +135,6 @@ class Fundamental(Handler): self.add_bindings('save-buffer-as', ('C-x C-w',)) self.add_bindings('relex-buffer', ('M-r',)) self.add_bindings('exit', ('C-x C-c',)) - self.add_bindings('exit2', ('C-c C-c',)) self.add_bindings('split-window', ('C-x s',)) self.add_bindings('unsplit-window', ('C-u s',)) self.add_bindings('toggle-window', ('C-x o',))