highlighting regions

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-05-03 21:05:24 +00:00
parent 210e00eb37
commit 0c751d5770
5 changed files with 23 additions and 14 deletions

View File

@ -516,8 +516,16 @@ class Application(object):
# highlighting # highlighting
def add_highlighted_range(self, hr): def add_highlighted_range(self, hr):
self.highlighted_ranges.append(hr) self.highlighted_ranges.append(hr)
def clear_highlighted_ranges(self): def clear_highlighted_ranges(self, name=None):
self.highlighted_ranges = [] 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): def run_external(self, *args):
curses.reset_shell_mode() curses.reset_shell_mode()

View File

@ -40,8 +40,8 @@ class AddMove(object):
class DelMove(object): class DelMove(object):
def __init__(self, buffer, p1, p2): def __init__(self, buffer, p1, p2):
self.buffer = buffer self.buffer = buffer
self.p1 = p1 self.p1 = p1
self.p2 = p2 self.p2 = p2
def restore(self, act): def restore(self, act):
assert act == ACT_UNDO or act == ACT_REDO assert act == ACT_UNDO or act == ACT_REDO
self.buffer.delete(self.p1, self.p2, act) self.buffer.delete(self.p1, self.p2, act)

View File

@ -117,7 +117,7 @@ def _finish(m, w):
def _end(w): def _end(w):
w.application.close_mini_buffer() 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_cursor = None
w.buffer.method.old_window = None w.buffer.method.old_window = None
assert not w.application.mini_active assert not w.application.mini_active

View File

@ -28,7 +28,7 @@ class SearchNext(method.Method):
r = _make_regex(w, s) r = _make_regex(w, s)
searchutil.find_next(r, w.buffer.method.old_window, move=True) searchutil.find_next(r, w.buffer.method.old_window, move=True)
except searchutil.IllegalPatternError: except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
else: else:
action = InsertSearchString(w.application.last_search) action = InsertSearchString(w.application.last_search)
action.execute(w) action.execute(w)
@ -45,7 +45,7 @@ class SearchPrevious(method.Method):
r = _make_regex(w, s) r = _make_regex(w, s)
searchutil.find_previous(r, w2, move=True) searchutil.find_previous(r, w2, move=True)
except searchutil.IllegalPatternError: except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
class EndSearch(method.Method): class EndSearch(method.Method):
def execute(self, w, **vargs): def execute(self, w, **vargs):
@ -74,7 +74,7 @@ def _post_delete(w):
old_w = w.buffer.method.old_window old_w = w.buffer.method.old_window
old_w.goto(old_cursor) old_w.goto(old_cursor)
if not w.buffer.make_string(): if not w.buffer.make_string():
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
return return
s = w.buffer.make_string() s = w.buffer.make_string()
w2 = w.buffer.method.old_window w2 = w.buffer.method.old_window
@ -85,7 +85,7 @@ def _post_delete(w):
else: else:
searchutil.find_previous(r, w2, move=False) searchutil.find_previous(r, w2, move=False)
except searchutil.IllegalPatternError: except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
class InsertSearchString(method.Method): class InsertSearchString(method.Method):
def __init__(self, s): def __init__(self, s):
@ -97,7 +97,7 @@ class InsertSearchString(method.Method):
w.insert_string_at_cursor(self.string) w.insert_string_at_cursor(self.string)
s = w.buffer.make_string() s = w.buffer.make_string()
if not s: if not s:
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
return return
else: else:
try: try:
@ -108,11 +108,11 @@ class InsertSearchString(method.Method):
else: else:
searchutil.find_previous(r, w2, move=False) searchutil.find_previous(r, w2, move=False)
except searchutil.IllegalPatternError: except searchutil.IllegalPatternError:
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
def _end(w): def _end(w):
w.application.close_mini_buffer() w.application.close_mini_buffer()
w.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges('search')
w.application.last_search = w.buffer.make_string() w.application.last_search = w.buffer.make_string()
class Search(mode.Fundamental): class Search(mode.Fundamental):

View File

@ -74,7 +74,7 @@ def find(r, w, move=False, direction='next', start=None, end=None):
break break
if ranges and not newc: if ranges and not newc:
return None return None
app.clear_highlighted_ranges() app.clear_highlighted_ranges('search')
if newc: if newc:
w.goto(newc[0]) w.goto(newc[0])
for (p1, p2, fg, bg, m) in ranges: 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 continue
elif p2 > w.last: elif p2 > w.last:
break 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 return newc
def find_previous(r, w, move=False, start=None, end=None): def find_previous(r, w, move=False, start=None, end=None):