From a69186314986cb6bae761febeb39deb704190f3b Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 3 Jul 2007 16:53:14 +0000 Subject: [PATCH] bugfix(es) --HG-- branch : pmacs2 --- application.py | 36 +++++------- method.py | 20 ++++--- mode_search.py | 154 +++++++++++++++++++++++++------------------------ window2.py | 4 +- 4 files changed, 106 insertions(+), 108 deletions(-) diff --git a/application.py b/application.py index ad9b591..d2034e7 100755 --- a/application.py +++ b/application.py @@ -47,20 +47,17 @@ class Application(object): def __init__(self, stdscr, buffers=[], jump_to_line=None, init_mode=None): # initalize curses primitives self.stdscr = stdscr - self.y, self.x = self.stdscr.getmaxyx() + (self.y, self.x) = self.stdscr.getmaxyx() # initialize some basic stuff - self.margins_visible = False - #self.margins = [(80, 'blue'), (90, 'red')] - self.margins = [(80, 'blue'), ] # each highlighted_range contains three things: [window, start_p, end_p] self.highlighted_ranges = [] - self.mini_active = False - self.mini_buffer = None - self.mini_prompt = "" - self.error_string = "" - self.error_timestamp = None - self.input = keyinput.Handler() + self.mini_active = False + self.mini_buffer = None + self.mini_prompt = "" + self.error_string = "" + self.error_timestamp = None + self.input = keyinput.Handler() # initialize our colors if curses.has_colors(): @@ -489,7 +486,9 @@ class Application(object): def highlight_char(self, sy, sx): junk = self.win.inch(sy, sx) c = junk & 255 - attr = (junk & (curses.A_COLOR|curses.A_ATTRIBUTES)) | curses.A_REVERSE + # FIXME? + #attr = (junk & (curses.A_COLOR|curses.A_ATTRIBUTES)) | curses.A_REVERSE + attr = curses.A_REVERSE self.win.addch(sy, sx, c, attr) def highlight_chars(self, sy, sx1, sx2): for x in range(sx1, sx2): @@ -511,14 +510,7 @@ class Application(object): # highlighted regions for (high_w, p1, p2) in self.highlighted_ranges: - if w is not high_w: - # this region isn't in the current window so skip it - pass - elif p2 < w.first or p1 > w.last: - # this region is not visible, so skip it - pass - else: - # ok, so now we need to do some highlighting + if w is high_w and p2 >= w.first and p1 <= w.last: count = 0 (x, y) = w.first.xy() px = p1.x @@ -537,9 +529,9 @@ class Application(object): x += slot.width count += 1 - if self.margins_visible: - for (limit, shade) in self.margins: - if self.x > limit: + if w.margins_visible: + for (limit, shade) in w.margins: + if limit <= self.x: for j in range(0, slot.height): char = self.win.inch(j + slot.offset, limit) & 255 attr = color.build('default', shade, 'bold') diff --git a/method.py b/method.py index 07720db..4cb457b 100644 --- a/method.py +++ b/method.py @@ -151,19 +151,14 @@ class Search(Method): self.old_cursor = w.logical_cursor() self.old_window = w self.direction = 'next' - w.application.open_mini_buffer('I-Search: ', lambda x: None, self, - None, 'search') + w.application.open_mini_buffer('I-Search: ', lambda x: None, self, None, 'search') class ReverseSearch(Method): '''Interactive search; finds previous occurance of text in buffer''' def execute(self, w, **vargs): self.old_cursor = w.logical_cursor() self.old_window = w self.direction = 'previous' - w.application.open_mini_buffer('I-Search: ', - lambda x: None, - self, - None, - 'search') + w.application.open_mini_buffer('I-Search: ', lambda x: None, self, None, 'search') class Replace(Method): '''Replace occurances of string X with string Y''' def _args(self): @@ -450,6 +445,14 @@ class DeleteRightWhitespace(Method): w.kill(c, p) # random stuff +class DumpRegions(Method): + '''debug region highlighting''' + def _execute(self, w, **vargs): + lines = [] + for (w, p1, p2) in w.application.highlighted_ranges: + lines.append("%r %s %s" % (w, p1, p2)) + output = "\n".join(lines) + w.application.data_buffer("region-dump", output, switch_to=True) class DumpMarkers(Method): '''Dump all tab markers (tab debugging)''' def _execute(self, w, **vargs): @@ -501,8 +504,7 @@ class MetaX(Method): class ToggleMargins(Method): '''Show or hide column margins''' def _execute(self, w, **vargs): - a = w.application - a.margins_visible = not a.margins_visible + w.margins_visible = not w.margins_visible class CenterView(Method): '''Move view to center on cursor''' def _execute(self, w, **vargs): diff --git a/mode_search.py b/mode_search.py index c5f8c4c..211de6a 100644 --- a/mode_search.py +++ b/mode_search.py @@ -36,63 +36,65 @@ class Search(mode2.Fundamental): return "Search" class SearchNext(method.Method): - def execute(self, window, **vargs): - window.buffer.method.direction = 'next' - s = window.buffer.make_string() + def execute(self, w, **vargs): + w.buffer.method.direction = 'next' + s = w.buffer.make_string() if not s: - s = window.application.last_search - window.buffer.set_data(s) + s = w.application.last_search + w.buffer.set_data(s) else: - old_window = window.buffer.method.old_window - _find_next(old_window, window, move=True) + old_w = w.buffer.method.old_window + _find_next(old_w, w, move=True) class SearchPrevious(method.Method): - def execute(self, window, **vargs): - window.buffer.method.direction = 'previous' - s = window.buffer.make_string() + def execute(self, w, **vargs): + w.buffer.method.direction = 'previous' + s = w.buffer.make_string() if not s: return else: - old_window = window.buffer.method.old_window - _find_previous(old_window, window, move=True) + old_w = w.buffer.method.old_window + _find_previous(old_w, w, move=True) class EndSearch(method.Method): - def execute(self, window, **vargs): - old_window = window.buffer.method.old_window - old_cursor = window.buffer.method.old_cursor - _end(window) - old_window.set_mark_point(old_cursor) - window.application.set_error("Mark set to search start") + def execute(self, w, **vargs): + old_w = w.buffer.method.old_window + old_cursor = w.buffer.method.old_cursor + _end(w) + old_w.set_mark_point(old_cursor) + w.set_error("Mark set to search start") class CancelSearch(method.Method): - def execute(self, window, **vargs): - old_window = window.buffer.method.old_window - old_cursor = window.buffer.method.old_cursor - old_window.goto(old_cursor) - _end(window) - window.application.set_error("Search cancelled") + def execute(self, w, **vargs): + old_w = w.buffer.method.old_window + old_cursor = w.buffer.method.old_cursor + old_w.goto(old_cursor) + _end(w) + w.set_error("Search cancelled") class DeleteLeft(method.Method): - def execute(self, window, **vargs): - window.left_delete() - old_cursor = window.buffer.method.old_cursor - old_window = window.buffer.method.old_window - old_window.goto(old_cursor) - if window.buffer.method.direction == 'next': - _find_next(old_window, window, move=False) + def execute(self, w, **vargs): + w.left_delete() + old_cursor = w.buffer.method.old_cursor + old_w = w.buffer.method.old_window + old_w.goto(old_cursor) + _end(w) + return + if w.buffer.method.direction == 'next': + _find_next(old_w, w, move=False) else: - _find_previous(old_window, window, move=False) + _find_previous(old_w, w, move=False) class DeleteLeftWord(method.Method): - def execute(self, window, **vargs): - window.kill_left_word() - old_cursor = window.buffer.method.old_cursor - old_window = window.buffer.method.old_window - old_window.goto(old_cursor) - if window.buffer.method.direction == 'next': - _find_next(old_window, window, move=False) + def execute(self, w, **vargs): + w.kill_left_word() + old_cursor = w.buffer.method.old_cursor + old_w = w.buffer.method.old_window + old_w.goto(old_cursor) + if w.buffer.method.direction == 'next': + _find_next(old_w, w, move=False) else: - _find_previous(old_window, window, move=False) + _find_previous(old_w, w, move=False) class InsertSearchString(method.Method): def __init__(self, s): @@ -100,79 +102,79 @@ class InsertSearchString(method.Method): self.string = s self.args = [] self.help = None - def execute(self, window, **vargs): - window.insert_string_at_cursor(self.string) - s = window.buffer.make_string() + def execute(self, w, **vargs): + w.insert_string_at_cursor(self.string) + s = w.buffer.make_string() if not s: return else: - old_window = window.buffer.method.old_window - if window.buffer.method.direction == 'next': - _find_next(old_window, window, move=False) + old_w = w.buffer.method.old_window + if w.buffer.method.direction == 'next': + _find_next(old_w, w, move=False) else: - _find_previous(old_window, window, move=False) + _find_previous(old_w, w, move=False) -def _end(window): - s = window.buffer.make_string() - window.application.last_search = s - window.application.close_mini_buffer() - #window.application.highlighted_range = [] - window.application.clear_highlighted_ranges() - window.buffer.method.old_cursor = None - window.buffer.method.old_window = None +def _end(w): + s = w.buffer.make_string() + w.application.last_search = s + w.application.close_mini_buffer() + #w.application.highlighted_range = [] + w.application.clear_highlighted_ranges() + w.buffer.method.old_cursor = None + w.buffer.method.old_window = None -def _find_previous(old_window, new_window, move=False): - s = new_window.buffer.make_string() - old_buffer = old_window.buffer - c = old_window.logical_cursor() +def _find_previous(old_w, new_w, move=False): + s = new_w.buffer.make_string() + old_b = old_w.buffer + c = old_w.logical_cursor() (x, y) = (c.x, c.y) if move: x -= 1 - l = old_buffer.lines[y][:x + len(s)] + l = old_b.lines[y][:x + len(s)] # for each line available while y >= 0: if s in l: # success x = l.index(s) - old_window.goto(Point(x, y)) - old_window.application.clear_highlighted_ranges() - new_window.application.add_highlighted_range(old_window, + old_w.goto(Point(x, y)) + old_w.application.clear_highlighted_ranges() + new_w.application.add_highlighted_range(old_w, Point(x,y), Point(x + len(s), y)) break - elif y >= len(old_buffer.lines) - 1: + elif y >= len(old_b.lines) - 1: # failure break else: # keep trying y -= 1 - l = old_buffer.lines[y] + l = old_b.lines[y] x = 0 -def _find_next(old_window, new_window, move=False): - s = new_window.buffer.make_string() - old_buffer = old_window.buffer - c = old_window.logical_cursor() +def _find_next(old_w, new_w, move=False): + s = new_w.buffer.make_string() + old_b = old_w.buffer + c = old_w.logical_cursor() (x, y) = (c.x, c.y) if move: x += 1 - l = old_buffer.lines[y][x:] + l = old_b.lines[y][x:] # for each line available - while y < len(old_buffer.lines): + while y < len(old_b.lines): if s in l: # success x = l.index(s) + x - old_window.goto(Point(x, y)) - old_window.application.clear_highlighted_ranges() - new_window.application.add_highlighted_range(old_window, + old_w.goto(Point(x, y)) + old_w.application.clear_highlighted_ranges() + new_w.application.add_highlighted_range(old_w, Point(x,y), Point(x + len(s), y)) break - elif y >= len(old_buffer.lines) - 1: + elif y >= len(old_b.lines) - 1: # failure break else: # keep trying y += 1 - l = old_buffer.lines[y] + l = old_b.lines[y] x = 0 diff --git a/window2.py b/window2.py index 4339a0d..37e317c 100644 --- a/window2.py +++ b/window2.py @@ -25,7 +25,9 @@ class Window(object): self.height = height self.width = width - self.input_line = "" + self.input_line = "" + self.margins = [(80, 'blue')] + self.margins_visible = False if mode_name is not None: pass