branch : pmacs2
This commit is contained in:
moculus 2007-06-14 10:10:20 +00:00
parent 6f8fdb638a
commit 5ae3d1ef45
5 changed files with 75 additions and 65 deletions

View File

@ -10,7 +10,7 @@ from point2 import Point
#import mode, mode_c, mode_mini, mode_python, mode_nasm, mode_perl, mode_search #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_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 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): def run(buffers, jump_to_line=None, init_mode=None):
# save terminal state so we can restore it when the program exits # save terminal state so we can restore it when the program exits
@ -88,7 +88,7 @@ class Application(object):
'perl': mode_perl.Perl, 'perl': mode_perl.Perl,
'python': mode_python.Python, 'python': mode_python.Python,
# 'replace': mode_replace.Replace, # 'replace': mode_replace.Replace,
# 'search': mode_search.Search, 'search': mode_search.Search,
# 'sh': mode_sh.Sh, # 'sh': mode_sh.Sh,
# 'text': mode_text.Text, # 'text': mode_text.Text,
# 'which': mode_which.Which, # 'which': mode_which.Which,
@ -450,11 +450,18 @@ class Application(object):
self.draw_slot(i) self.draw_slot(i)
self.draw_status_bar(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): def draw_slot(self, i):
#assert len(self.bufferlist.slots) == 1, "only one"
assert self.active_slot < len(self.bufferlist.slots), "only two" assert self.active_slot < len(self.bufferlist.slots), "only two"
assert i < len(self.bufferlist.slots), "only three" assert i < len(self.bufferlist.slots), "only three"
#assert i == 0, "only four"
slot = self.bufferlist.slots[i] slot = self.bufferlist.slots[i]
if slot.window is None: if slot.window is None:
@ -467,18 +474,10 @@ class Application(object):
lines = w.buffer.lines lines = w.buffer.lines
count = 0 count = 0
(x, y) = w.first.xy() (x, y) = w.first.xy()
cursor = w.logical_cursor()
(cx, cy) = cursor.xy()
(px, py) = (None, None)
while count < slot.height: while count < slot.height:
if y >= len(lines): if y >= len(lines):
self.win.addstr(slot.offset + count, 0, '~', redattr) self.win.addstr(slot.offset + count, 0, '~', redattr)
else: 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] line = lines[y]
if modename in w.buffer.highlights: if modename in w.buffer.highlights:
highlighter = w.buffer.highlights[modename] highlighter = w.buffer.highlights[modename]
@ -517,40 +516,59 @@ class Application(object):
x += slot.width x += slot.width
count += 1 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: if self.margins_visible:
for (limit, shade) in self.margins: for (limit, shade) in self.margins:
if self.x > limit: if self.x > limit:
for j in range(0, slot.height): 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 char = self.win.inch(j + slot.offset, limit) & 255
attr = color.build('default', shade, 'bold') attr = color.build('default', shade, 'bold')
self.win.addch(j + slot.offset, limit, char, attr) self.win.addch(j + slot.offset, limit, char, attr)
if self.mini_active is False and self.active_slot == i: 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): if w.active_point is not None and w.point_is_visible(w.active_point):
pa = w.physical_point(w.active_point) p = 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)
else: else:
assert px is not None and py is not None p = w.logical_cursor()
count = 0
if cy >= len(lines): (x, y) = w.first.xy()
self.set_error('in main1: cursor error; %d >= %d' % (cy, len(lines))) while count < slot.height:
return if p.y == y and p.x >= x and p.x < x + slot.width:
elif cx == len(lines[cy]): self.highlight_char(slot.offset + count, p.x - x)
c = ' ' break
elif px > len(lines[cy]): if x + slot.width >= len(line):
self.set_error('why? %r %r' % (cx, len(lines[cy]))) x = 0
return y += 1
else: else:
c = lines[cy][cx] x += slot.width
self.win.addch(slot.offset + py , px, c, curses.A_REVERSE) count += 1
def draw_status_bar(self, slotname): def draw_status_bar(self, slotname):
slot = self.bufferlist.slots[slotname] slot = self.bufferlist.slots[slotname]

View File

@ -147,14 +147,11 @@ class ForwardLines(Method):
class Search(Method): class Search(Method):
'''Interactive search; finds next occurance of text in buffer''' '''Interactive search; finds next occurance of text in buffer'''
def execute(self, w, **vargs): 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.old_window = w
self.direction = 'next' self.direction = 'next'
w.application.open_mini_buffer('I-Search: ', w.application.open_mini_buffer('I-Search: ', lambda x: None, self,
lambda x: None, None, 'search')
self,
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):

View File

@ -1,12 +1,12 @@
import sets, string import sets, string
import color, highlight, method, minibuffer, mode, point import color, method, minibuffer, mode2
import random from point2 import Point
class Replace(mode.Fundamental): class Replace(mode2.Fundamental):
'''This is the default mode''' '''This is the default mode'''
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)
self.actions = {} self.actions = {}
self.bindings = {} self.bindings = {}
@ -92,8 +92,8 @@ def _find_next(window, move=False):
# success # success
x = x + l.index(s) x = x + l.index(s)
x2 = x + len(s) x2 = x + len(s)
m.p1 = point.Point(x, y) m.p1 = Point(x, y)
m.p2 = point.Point(x2, y) m.p2 = Point(x2, y)
old_window.goto(m.p1) old_window.goto(m.p1)
old_window.application.clear_highlighted_ranges() old_window.application.clear_highlighted_ranges()
old_window.application.add_highlighted_range(old_window, m.p1, m.p2) old_window.application.add_highlighted_range(old_window, m.p1, m.p2)

View File

@ -1,11 +1,12 @@
import sets, string 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''' '''This is the default mode'''
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)
self.actions = {} self.actions = {}
self.bindings = {} self.bindings = {}
@ -100,7 +101,7 @@ class InsertSearchString(method.Method):
self.args = [] self.args = []
self.help = None self.help = None
def execute(self, window, **vargs): def execute(self, window, **vargs):
window.insert_string(self.string) window.insert_string_at_cursor(self.string)
s = window.buffer.make_string() s = window.buffer.make_string()
if not s: if not s:
return return
@ -133,14 +134,11 @@ def _find_previous(old_window, new_window, move=False):
if s in l: if s in l:
# success # success
x = l.index(s) x = l.index(s)
old_window.goto(point.Point(x, y)) old_window.goto(Point(x, y))
#new_window.application.highlighted_range = [old_window,
# point.Point(x,y),
# point.Point(x + len(s), y)]
old_window.application.clear_highlighted_ranges() old_window.application.clear_highlighted_ranges()
new_window.application.add_highlighted_range(old_window, new_window.application.add_highlighted_range(old_window,
point.Point(x,y), Point(x,y),
point.Point(x + len(s), y)) Point(x + len(s), y))
break break
elif y >= len(old_buffer.lines) - 1: elif y >= len(old_buffer.lines) - 1:
# failure # failure
@ -164,14 +162,11 @@ def _find_next(old_window, new_window, move=False):
if s in l: if s in l:
# success # success
x = l.index(s) + x x = l.index(s) + x
old_window.goto(point.Point(x, y)) old_window.goto(Point(x, y))
#new_window.application.highlighted_range = [old_window,
# point.Point(x,y),
# point.Point(x + len(s), y)]
old_window.application.clear_highlighted_ranges() old_window.application.clear_highlighted_ranges()
new_window.application.add_highlighted_range(old_window, new_window.application.add_highlighted_range(old_window,
point.Point(x,y), Point(x,y),
point.Point(x + len(s), y)) Point(x + len(s), y))
break break
elif y >= len(old_buffer.lines) - 1: elif y >= len(old_buffer.lines) - 1:
# failure # failure

View File

@ -328,8 +328,8 @@ class Window(object):
self.assure_visible_cursor() self.assure_visible_cursor()
def forward_lines(self, n): def forward_lines(self, n):
assert n > 0, "illegal number of lines: %d" % n assert n > 0, "illegal number of lines: %d" % n
y = min(self.cursor[1] + n, len(self.buffer.lines) - 1) y = min(self.logical_cursor().y + n, len(self.buffer.lines) - 1)
self.goto_line(y) self.goto(Point(0, y))
def forward_chars(self, n): def forward_chars(self, n):
(x, y) = self.logical_cursor().xy() (x, y) = self.logical_cursor().xy()
for i in range(0, n): for i in range(0, n):