bugfix(es)

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-03 16:53:14 +00:00
parent f8c2173b5c
commit a691863149
4 changed files with 106 additions and 108 deletions

View File

@ -47,20 +47,17 @@ class Application(object):
def __init__(self, stdscr, buffers=[], jump_to_line=None, init_mode=None): def __init__(self, stdscr, buffers=[], jump_to_line=None, init_mode=None):
# initalize curses primitives # initalize curses primitives
self.stdscr = stdscr self.stdscr = stdscr
self.y, self.x = self.stdscr.getmaxyx() (self.y, self.x) = self.stdscr.getmaxyx()
# initialize some basic stuff # 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] # each highlighted_range contains three things: [window, start_p, end_p]
self.highlighted_ranges = [] self.highlighted_ranges = []
self.mini_active = False self.mini_active = False
self.mini_buffer = None self.mini_buffer = None
self.mini_prompt = "" self.mini_prompt = ""
self.error_string = "" self.error_string = ""
self.error_timestamp = None self.error_timestamp = None
self.input = keyinput.Handler() self.input = keyinput.Handler()
# initialize our colors # initialize our colors
if curses.has_colors(): if curses.has_colors():
@ -489,7 +486,9 @@ class Application(object):
def highlight_char(self, sy, sx): def highlight_char(self, sy, sx):
junk = self.win.inch(sy, sx) junk = self.win.inch(sy, sx)
c = junk & 255 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) self.win.addch(sy, sx, c, attr)
def highlight_chars(self, sy, sx1, sx2): def highlight_chars(self, sy, sx1, sx2):
for x in range(sx1, sx2): for x in range(sx1, sx2):
@ -511,14 +510,7 @@ class Application(object):
# highlighted regions # highlighted regions
for (high_w, p1, p2) in self.highlighted_ranges: for (high_w, p1, p2) in self.highlighted_ranges:
if w is not high_w: if w is high_w and p2 >= w.first and p1 <= w.last:
# 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 count = 0
(x, y) = w.first.xy() (x, y) = w.first.xy()
px = p1.x px = p1.x
@ -537,9 +529,9 @@ class Application(object):
x += slot.width x += slot.width
count += 1 count += 1
if self.margins_visible: if w.margins_visible:
for (limit, shade) in self.margins: for (limit, shade) in w.margins:
if self.x > limit: if limit <= self.x:
for j in range(0, slot.height): for j in range(0, slot.height):
char = self.win.inch(j + slot.offset, limit) & 255 char = self.win.inch(j + slot.offset, limit) & 255
attr = color.build('default', shade, 'bold') attr = color.build('default', shade, 'bold')

View File

@ -151,19 +151,14 @@ class Search(Method):
self.old_cursor = w.logical_cursor() self.old_cursor = w.logical_cursor()
self.old_window = w self.old_window = w
self.direction = 'next' self.direction = 'next'
w.application.open_mini_buffer('I-Search: ', lambda x: None, self, w.application.open_mini_buffer('I-Search: ', lambda x: None, self, None, 'search')
None, 'search')
class ReverseSearch(Method): class ReverseSearch(Method):
'''Interactive search; finds previous occurance of text in buffer''' '''Interactive search; finds previous occurance of text in buffer'''
def execute(self, w, **vargs): def execute(self, w, **vargs):
self.old_cursor = w.logical_cursor() self.old_cursor = w.logical_cursor()
self.old_window = w self.old_window = w
self.direction = 'previous' self.direction = 'previous'
w.application.open_mini_buffer('I-Search: ', w.application.open_mini_buffer('I-Search: ', lambda x: None, self, None, 'search')
lambda x: None,
self,
None,
'search')
class Replace(Method): class Replace(Method):
'''Replace occurances of string X with string Y''' '''Replace occurances of string X with string Y'''
def _args(self): def _args(self):
@ -450,6 +445,14 @@ class DeleteRightWhitespace(Method):
w.kill(c, p) w.kill(c, p)
# random stuff # 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): class DumpMarkers(Method):
'''Dump all tab markers (tab debugging)''' '''Dump all tab markers (tab debugging)'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
@ -501,8 +504,7 @@ class MetaX(Method):
class ToggleMargins(Method): class ToggleMargins(Method):
'''Show or hide column margins''' '''Show or hide column margins'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
a = w.application w.margins_visible = not w.margins_visible
a.margins_visible = not a.margins_visible
class CenterView(Method): class CenterView(Method):
'''Move view to center on cursor''' '''Move view to center on cursor'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):

View File

@ -36,63 +36,65 @@ class Search(mode2.Fundamental):
return "Search" return "Search"
class SearchNext(method.Method): class SearchNext(method.Method):
def execute(self, window, **vargs): def execute(self, w, **vargs):
window.buffer.method.direction = 'next' w.buffer.method.direction = 'next'
s = window.buffer.make_string() s = w.buffer.make_string()
if not s: if not s:
s = window.application.last_search s = w.application.last_search
window.buffer.set_data(s) w.buffer.set_data(s)
else: else:
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
_find_next(old_window, window, move=True) _find_next(old_w, w, move=True)
class SearchPrevious(method.Method): class SearchPrevious(method.Method):
def execute(self, window, **vargs): def execute(self, w, **vargs):
window.buffer.method.direction = 'previous' w.buffer.method.direction = 'previous'
s = window.buffer.make_string() s = w.buffer.make_string()
if not s: if not s:
return return
else: else:
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
_find_previous(old_window, window, move=True) _find_previous(old_w, w, move=True)
class EndSearch(method.Method): class EndSearch(method.Method):
def execute(self, window, **vargs): def execute(self, w, **vargs):
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
old_cursor = window.buffer.method.old_cursor old_cursor = w.buffer.method.old_cursor
_end(window) _end(w)
old_window.set_mark_point(old_cursor) old_w.set_mark_point(old_cursor)
window.application.set_error("Mark set to search start") w.set_error("Mark set to search start")
class CancelSearch(method.Method): class CancelSearch(method.Method):
def execute(self, window, **vargs): def execute(self, w, **vargs):
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
old_cursor = window.buffer.method.old_cursor old_cursor = w.buffer.method.old_cursor
old_window.goto(old_cursor) old_w.goto(old_cursor)
_end(window) _end(w)
window.application.set_error("Search cancelled") w.set_error("Search cancelled")
class DeleteLeft(method.Method): class DeleteLeft(method.Method):
def execute(self, window, **vargs): def execute(self, w, **vargs):
window.left_delete() w.left_delete()
old_cursor = window.buffer.method.old_cursor old_cursor = w.buffer.method.old_cursor
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
old_window.goto(old_cursor) old_w.goto(old_cursor)
if window.buffer.method.direction == 'next': _end(w)
_find_next(old_window, window, move=False) return
if w.buffer.method.direction == 'next':
_find_next(old_w, w, move=False)
else: else:
_find_previous(old_window, window, move=False) _find_previous(old_w, w, move=False)
class DeleteLeftWord(method.Method): class DeleteLeftWord(method.Method):
def execute(self, window, **vargs): def execute(self, w, **vargs):
window.kill_left_word() w.kill_left_word()
old_cursor = window.buffer.method.old_cursor old_cursor = w.buffer.method.old_cursor
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
old_window.goto(old_cursor) old_w.goto(old_cursor)
if window.buffer.method.direction == 'next': if w.buffer.method.direction == 'next':
_find_next(old_window, window, move=False) _find_next(old_w, w, move=False)
else: else:
_find_previous(old_window, window, move=False) _find_previous(old_w, w, move=False)
class InsertSearchString(method.Method): class InsertSearchString(method.Method):
def __init__(self, s): def __init__(self, s):
@ -100,79 +102,79 @@ class InsertSearchString(method.Method):
self.string = s self.string = s
self.args = [] self.args = []
self.help = None self.help = None
def execute(self, window, **vargs): def execute(self, w, **vargs):
window.insert_string_at_cursor(self.string) w.insert_string_at_cursor(self.string)
s = window.buffer.make_string() s = w.buffer.make_string()
if not s: if not s:
return return
else: else:
old_window = window.buffer.method.old_window old_w = w.buffer.method.old_window
if window.buffer.method.direction == 'next': if w.buffer.method.direction == 'next':
_find_next(old_window, window, move=False) _find_next(old_w, w, move=False)
else: else:
_find_previous(old_window, window, move=False) _find_previous(old_w, w, move=False)
def _end(window): def _end(w):
s = window.buffer.make_string() s = w.buffer.make_string()
window.application.last_search = s w.application.last_search = s
window.application.close_mini_buffer() w.application.close_mini_buffer()
#window.application.highlighted_range = [] #w.application.highlighted_range = []
window.application.clear_highlighted_ranges() w.application.clear_highlighted_ranges()
window.buffer.method.old_cursor = None w.buffer.method.old_cursor = None
window.buffer.method.old_window = None w.buffer.method.old_window = None
def _find_previous(old_window, new_window, move=False): def _find_previous(old_w, new_w, move=False):
s = new_window.buffer.make_string() s = new_w.buffer.make_string()
old_buffer = old_window.buffer old_b = old_w.buffer
c = old_window.logical_cursor() c = old_w.logical_cursor()
(x, y) = (c.x, c.y) (x, y) = (c.x, c.y)
if move: if move:
x -= 1 x -= 1
l = old_buffer.lines[y][:x + len(s)] l = old_b.lines[y][:x + len(s)]
# for each line available # for each line available
while y >= 0: while y >= 0:
if s in l: if s in l:
# success # success
x = l.index(s) x = l.index(s)
old_window.goto(Point(x, y)) old_w.goto(Point(x, y))
old_window.application.clear_highlighted_ranges() old_w.application.clear_highlighted_ranges()
new_window.application.add_highlighted_range(old_window, new_w.application.add_highlighted_range(old_w,
Point(x,y), Point(x,y),
Point(x + len(s), y)) Point(x + len(s), y))
break break
elif y >= len(old_buffer.lines) - 1: elif y >= len(old_b.lines) - 1:
# failure # failure
break break
else: else:
# keep trying # keep trying
y -= 1 y -= 1
l = old_buffer.lines[y] l = old_b.lines[y]
x = 0 x = 0
def _find_next(old_window, new_window, move=False): def _find_next(old_w, new_w, move=False):
s = new_window.buffer.make_string() s = new_w.buffer.make_string()
old_buffer = old_window.buffer old_b = old_w.buffer
c = old_window.logical_cursor() c = old_w.logical_cursor()
(x, y) = (c.x, c.y) (x, y) = (c.x, c.y)
if move: if move:
x += 1 x += 1
l = old_buffer.lines[y][x:] l = old_b.lines[y][x:]
# for each line available # for each line available
while y < len(old_buffer.lines): while y < len(old_b.lines):
if s in l: if s in l:
# success # success
x = l.index(s) + x x = l.index(s) + x
old_window.goto(Point(x, y)) old_w.goto(Point(x, y))
old_window.application.clear_highlighted_ranges() old_w.application.clear_highlighted_ranges()
new_window.application.add_highlighted_range(old_window, new_w.application.add_highlighted_range(old_w,
Point(x,y), Point(x,y),
Point(x + len(s), y)) Point(x + len(s), y))
break break
elif y >= len(old_buffer.lines) - 1: elif y >= len(old_b.lines) - 1:
# failure # failure
break break
else: else:
# keep trying # keep trying
y += 1 y += 1
l = old_buffer.lines[y] l = old_b.lines[y]
x = 0 x = 0

View File

@ -25,7 +25,9 @@ class Window(object):
self.height = height self.height = height
self.width = width self.width = width
self.input_line = "" self.input_line = ""
self.margins = [(80, 'blue')]
self.margins_visible = False
if mode_name is not None: if mode_name is not None:
pass pass