diff --git a/application.py b/application.py index 3f95473..dd4a629 100755 --- a/application.py +++ b/application.py @@ -231,23 +231,28 @@ class Application(object): return self.mini_buffer def mini_buffer_is_open(self): return self.mini_buffer is not None - def open_mini_buffer(self, prompt, callback, method=None, tabber=None, - modename=None): + def open_mini_buffer(self, prompt, callback, method=None, tabber=None, modename=None): if self.mini_buffer_is_open(): self.close_mini_buffer() self.mini_prompt = prompt self.mini_buffer = minibuffer.MiniBuffer(callback, method, tabber, modename) - window2.Window(self.mini_buffer, self, height=1, width=self.x-1-len(self.mini_prompt)-1) - self.mini_active = True + try: + window2.Window(self.mini_buffer, self, height=1, + width=self.x-1-len(self.mini_prompt)-1) + self.mini_active = True + except minibuffer.MiniBufferError: + self.mini_buffer = None + self.mini_prompt = '' def exec_mini_buffer(self): self.mini_buffer.callback(self.mini_buffer.make_string()) self.close_mini_buffer() def close_mini_buffer(self): + self.mini_active = False if self.mini_buffer_is_open(): self.mini_buffer.close() self.mini_buffer = None self.mini_prompt = "" - self.mini_active = False + assert not self.mini_active def get_mini_buffer_prompt(self): return self.mini_prompt def set_mini_buffer_prompt(self, p): diff --git a/method.py b/method.py index c11db2a..1ea7cfd 100644 --- a/method.py +++ b/method.py @@ -171,11 +171,7 @@ class Replace(Method): a.last_replace_before = self.before = vargs['before'] a.last_replace_after = self.after = vargs['after'] self.old_window = w - a.open_mini_buffer('I-Replace: ', - lambda x: None, - self, - None, - 'replace') + a.open_mini_buffer('I-Replace: ', lambda x: None, self, None, 'replace') # navigating between buffers class OpenFile(Method): diff --git a/minibuffer.py b/minibuffer.py index d066ca8..bd17949 100644 --- a/minibuffer.py +++ b/minibuffer.py @@ -1,5 +1,8 @@ import buffer2 +class MiniBufferError(Exception): + pass + # minibuffer is a singleton mini = None class MiniBuffer(buffer2.Buffer): diff --git a/mode_python.py b/mode_python.py index e85a912..33c0533 100644 --- a/mode_python.py +++ b/mode_python.py @@ -1,6 +1,6 @@ import commands, os.path, sets, string, sys -import color, completer, default, mode2, lex2, method, regex +import color, completer, default, mode2, lex2, method, regex, tab2 import ctag_python from point2 import Point diff --git a/mode_replace.py b/mode_replace.py index 20cc240..1a13a72 100644 --- a/mode_replace.py +++ b/mode_replace.py @@ -26,6 +26,9 @@ class Replace(mode2.Fundamental): self.add_action_and_bindings(action, sequences) _find_next(w, False) + if w.buffer.method.p1 is None: + w.application.set_error('%r was not found') + raise minibuffer.MiniBufferError _set_prompt(w.buffer.method, w.buffer.method.old_window) def name(self): @@ -62,6 +65,9 @@ class CancelReplace(method.Method): w.application.set_error("Replace cancelled") def _set_prompt(m, w): + if m.p1 is None: + w.application.mini_prompt = '%r was not found' % m.before + return (x, y) = m.p1.xy() count = 0 while y < len(w.buffer.lines): @@ -128,3 +134,4 @@ def _end(w): w.application.clear_highlighted_ranges() w.buffer.method.old_cursor = None w.buffer.method.old_window = None + assert not w.application.mini_active