From 5ae3d1ef45010abcdfa26bf33e8d8fb45b674fb4 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 14 Jun 2007 10:10:20 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- application.py | 88 +++++++++++++++++++++++++++++-------------------- method.py | 9 ++--- mode_replace.py | 12 +++---- mode_search.py | 27 +++++++-------- window2.py | 4 +-- 5 files changed, 75 insertions(+), 65 deletions(-) diff --git a/application.py b/application.py index c91753b..3dfbe42 100755 --- a/application.py +++ b/application.py @@ -10,7 +10,7 @@ from point2 import Point #import mode, mode_c, mode_mini, mode_python, mode_nasm, mode_perl, mode_search #import mode_replace, mode_xml, mode_console, mode_sh, mode_text, mode_which #import mode_mutt, mode_sql, mode_javascript, mode_diff, mode_blame, mode_tt -import mode2, mode_mini, mode_python, mode_perl +import mode2, mode_mini, mode_python, mode_perl, mode_search, mode_replace def run(buffers, jump_to_line=None, init_mode=None): # save terminal state so we can restore it when the program exits @@ -88,7 +88,7 @@ class Application(object): 'perl': mode_perl.Perl, 'python': mode_python.Python, # 'replace': mode_replace.Replace, -# 'search': mode_search.Search, + 'search': mode_search.Search, # 'sh': mode_sh.Sh, # 'text': mode_text.Text, # 'which': mode_which.Which, @@ -450,11 +450,18 @@ class Application(object): self.draw_slot(i) self.draw_status_bar(i) + 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 + self.win.addch(sy, sx, c, attr) + def highlight_chars(self, sy, sx1, sx2): + for x in range(sx1, sx2): + self.highlight_char(sy, x) + def draw_slot(self, i): - #assert len(self.bufferlist.slots) == 1, "only one" assert self.active_slot < len(self.bufferlist.slots), "only two" assert i < len(self.bufferlist.slots), "only three" - #assert i == 0, "only four" slot = self.bufferlist.slots[i] if slot.window is None: @@ -467,18 +474,10 @@ class Application(object): lines = w.buffer.lines count = 0 (x, y) = w.first.xy() - cursor = w.logical_cursor() - (cx, cy) = cursor.xy() - (px, py) = (None, None) while count < slot.height: if y >= len(lines): self.win.addstr(slot.offset + count, 0, '~', redattr) else: - # let's find the cursor - if cy == y and cx >= x and cx < x + slot.width: - px = cx - x - py = count - line = lines[y] if modename in w.buffer.highlights: highlighter = w.buffer.highlights[modename] @@ -517,40 +516,59 @@ class Application(object): x += slot.width count += 1 + # 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 + count = 0 + (x, y) = w.first.xy() + px = p1.x + while count < slot.height: + if p1.y == y and px >= x and px < x + slot.width: + if px + slot.width > p2.x: + self.highlight_chars(slot.offset + count, px, p2.x) + break + else: + self.highlight_chars(slot.offset + count, px, px + slot.width) + px += slot.width + if x + slot.width >= len(line): + x = 0 + y += 1 + else: + x += slot.width + count += 1 + if self.margins_visible: for (limit, shade) in self.margins: if self.x > limit: for j in range(0, slot.height): - # the actual character is the lower 8 bits, and the - # attribute is the upper 8 bits; we will ignore the - # attribute and just get the character char = self.win.inch(j + slot.offset, limit) & 255 attr = color.build('default', shade, 'bold') self.win.addch(j + slot.offset, limit, char, attr) if self.mini_active is False and self.active_slot == i: - if False and w.active_point is not None and w.point_is_visible(w.active_point): - pa = w.physical_point(w.active_point) - va = pa.offset(0, -w.visible_offset()) - if len(lines[va.y]): - a = lines[va.y][va.x] - else: - a = ' ' - self.win.addch(va.y + slot.offset, va.x, a, curses.A_REVERSE) + if w.active_point is not None and w.point_is_visible(w.active_point): + p = w.active_point else: - assert px is not None and py is not None - - if cy >= len(lines): - self.set_error('in main1: cursor error; %d >= %d' % (cy, len(lines))) - return - elif cx == len(lines[cy]): - c = ' ' - elif px > len(lines[cy]): - self.set_error('why? %r %r' % (cx, len(lines[cy]))) - return + p = w.logical_cursor() + count = 0 + (x, y) = w.first.xy() + while count < slot.height: + if p.y == y and p.x >= x and p.x < x + slot.width: + self.highlight_char(slot.offset + count, p.x - x) + break + if x + slot.width >= len(line): + x = 0 + y += 1 else: - c = lines[cy][cx] - self.win.addch(slot.offset + py , px, c, curses.A_REVERSE) + x += slot.width + count += 1 def draw_status_bar(self, slotname): slot = self.bufferlist.slots[slotname] diff --git a/method.py b/method.py index 7fe6300..777e6d9 100644 --- a/method.py +++ b/method.py @@ -147,14 +147,11 @@ class ForwardLines(Method): class Search(Method): '''Interactive search; finds next occurance of text in buffer''' def execute(self, w, **vargs): - self.old_cursor = w.logical_cursor().offset(0, 0) + 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): diff --git a/mode_replace.py b/mode_replace.py index 09a42f6..c7c6494 100644 --- a/mode_replace.py +++ b/mode_replace.py @@ -1,12 +1,12 @@ import sets, string -import color, highlight, method, minibuffer, mode, point -import random +import color, method, minibuffer, mode2 +from point2 import Point -class Replace(mode.Fundamental): +class Replace(mode2.Fundamental): '''This is the default mode''' def __init__(self, w): - mode.Fundamental.__init__(self, w) + mode2.Fundamental.__init__(self, w) self.actions = {} self.bindings = {} @@ -92,8 +92,8 @@ def _find_next(window, move=False): # success x = x + l.index(s) x2 = x + len(s) - m.p1 = point.Point(x, y) - m.p2 = point.Point(x2, y) + m.p1 = Point(x, y) + m.p2 = Point(x2, y) old_window.goto(m.p1) old_window.application.clear_highlighted_ranges() old_window.application.add_highlighted_range(old_window, m.p1, m.p2) diff --git a/mode_search.py b/mode_search.py index 4bf3742..c5f8c4c 100644 --- a/mode_search.py +++ b/mode_search.py @@ -1,11 +1,12 @@ import sets, string -import color, highlight, method, minibuffer, mode, point +import color, method, minibuffer, mode2 +from point2 import Point -class Search(mode.Fundamental): +class Search(mode2.Fundamental): '''This is the default mode''' def __init__(self, w): - mode.Fundamental.__init__(self, w) + mode2.Fundamental.__init__(self, w) self.actions = {} self.bindings = {} @@ -100,7 +101,7 @@ class InsertSearchString(method.Method): self.args = [] self.help = None def execute(self, window, **vargs): - window.insert_string(self.string) + window.insert_string_at_cursor(self.string) s = window.buffer.make_string() if not s: return @@ -133,14 +134,11 @@ def _find_previous(old_window, new_window, move=False): if s in l: # success x = l.index(s) - old_window.goto(point.Point(x, y)) - #new_window.application.highlighted_range = [old_window, - # point.Point(x,y), - # point.Point(x + len(s), y)] + old_window.goto(Point(x, y)) old_window.application.clear_highlighted_ranges() new_window.application.add_highlighted_range(old_window, - point.Point(x,y), - point.Point(x + len(s), y)) + Point(x,y), + Point(x + len(s), y)) break elif y >= len(old_buffer.lines) - 1: # failure @@ -164,14 +162,11 @@ def _find_next(old_window, new_window, move=False): if s in l: # success x = l.index(s) + x - old_window.goto(point.Point(x, y)) - #new_window.application.highlighted_range = [old_window, - # point.Point(x,y), - # point.Point(x + len(s), y)] + old_window.goto(Point(x, y)) old_window.application.clear_highlighted_ranges() new_window.application.add_highlighted_range(old_window, - point.Point(x,y), - point.Point(x + len(s), y)) + Point(x,y), + Point(x + len(s), y)) break elif y >= len(old_buffer.lines) - 1: # failure diff --git a/window2.py b/window2.py index b6f9db6..1846a52 100644 --- a/window2.py +++ b/window2.py @@ -328,8 +328,8 @@ class Window(object): self.assure_visible_cursor() def forward_lines(self, n): assert n > 0, "illegal number of lines: %d" % n - y = min(self.cursor[1] + n, len(self.buffer.lines) - 1) - self.goto_line(y) + y = min(self.logical_cursor().y + n, len(self.buffer.lines) - 1) + self.goto(Point(0, y)) def forward_chars(self, n): (x, y) = self.logical_cursor().xy() for i in range(0, n):