From 0c751d5770c2e70a5517774c5d7eecece6fe67c6 Mon Sep 17 00:00:00 2001 From: moculus Date: Sat, 3 May 2008 21:05:24 +0000 Subject: [PATCH] highlighting regions --HG-- branch : pmacs2 --- application.py | 12 ++++++++++-- buffer.py | 4 ++-- mode/replace.py | 2 +- mode/search.py | 14 +++++++------- searchutil.py | 5 +++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/application.py b/application.py index ca6d349..aa8d3c1 100755 --- a/application.py +++ b/application.py @@ -516,8 +516,16 @@ class Application(object): # highlighting def add_highlighted_range(self, hr): self.highlighted_ranges.append(hr) - def clear_highlighted_ranges(self): - self.highlighted_ranges = [] + def clear_highlighted_ranges(self, name=None): + if name is None: + self.highlighted_ranges = [] + else: + i = 0 + while i < len(self.highlighted_ranges): + if self.highlighted_ranges[i].name == name: + del self.highlighted_ranges[i] + else: + i += 1 def run_external(self, *args): curses.reset_shell_mode() diff --git a/buffer.py b/buffer.py index 9db6876..30980e5 100644 --- a/buffer.py +++ b/buffer.py @@ -40,8 +40,8 @@ class AddMove(object): class DelMove(object): def __init__(self, buffer, p1, p2): self.buffer = buffer - self.p1 = p1 - self.p2 = p2 + self.p1 = p1 + self.p2 = p2 def restore(self, act): assert act == ACT_UNDO or act == ACT_REDO self.buffer.delete(self.p1, self.p2, act) diff --git a/mode/replace.py b/mode/replace.py index cfe2188..424e10d 100644 --- a/mode/replace.py +++ b/mode/replace.py @@ -117,7 +117,7 @@ def _finish(m, w): def _end(w): w.application.close_mini_buffer() - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') w.buffer.method.old_cursor = None w.buffer.method.old_window = None assert not w.application.mini_active diff --git a/mode/search.py b/mode/search.py index 7113934..369334f 100644 --- a/mode/search.py +++ b/mode/search.py @@ -28,7 +28,7 @@ class SearchNext(method.Method): r = _make_regex(w, s) searchutil.find_next(r, w.buffer.method.old_window, move=True) except searchutil.IllegalPatternError: - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') else: action = InsertSearchString(w.application.last_search) action.execute(w) @@ -45,7 +45,7 @@ class SearchPrevious(method.Method): r = _make_regex(w, s) searchutil.find_previous(r, w2, move=True) except searchutil.IllegalPatternError: - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') class EndSearch(method.Method): def execute(self, w, **vargs): @@ -74,7 +74,7 @@ def _post_delete(w): old_w = w.buffer.method.old_window old_w.goto(old_cursor) if not w.buffer.make_string(): - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') return s = w.buffer.make_string() w2 = w.buffer.method.old_window @@ -85,7 +85,7 @@ def _post_delete(w): else: searchutil.find_previous(r, w2, move=False) except searchutil.IllegalPatternError: - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') class InsertSearchString(method.Method): def __init__(self, s): @@ -97,7 +97,7 @@ class InsertSearchString(method.Method): w.insert_string_at_cursor(self.string) s = w.buffer.make_string() if not s: - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') return else: try: @@ -108,11 +108,11 @@ class InsertSearchString(method.Method): else: searchutil.find_previous(r, w2, move=False) except searchutil.IllegalPatternError: - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') def _end(w): w.application.close_mini_buffer() - w.application.clear_highlighted_ranges() + w.application.clear_highlighted_ranges('search') w.application.last_search = w.buffer.make_string() class Search(mode.Fundamental): diff --git a/searchutil.py b/searchutil.py index 79851bc..1582439 100644 --- a/searchutil.py +++ b/searchutil.py @@ -74,7 +74,7 @@ def find(r, w, move=False, direction='next', start=None, end=None): break if ranges and not newc: return None - app.clear_highlighted_ranges() + app.clear_highlighted_ranges('search') if newc: w.goto(newc[0]) for (p1, p2, fg, bg, m) in ranges: @@ -82,7 +82,8 @@ def find(r, w, move=False, direction='next', start=None, end=None): continue elif p2 > w.last: break - app.add_highlighted_range(HighlightRegion(w, p1, p2, fg, bg)) + hr = HighlightRegion(w, p1, p2, fg, bg, match=m, name='search') + app.add_highlighted_range(hr) return newc def find_previous(r, w, move=False, start=None, end=None):