parent
74ab76836c
commit
2f685cb23a
|
@ -304,10 +304,10 @@ class Application(object):
|
||||||
# understand. i encourage someone else to write something better.
|
# understand. i encourage someone else to write something better.
|
||||||
numcols = max(self.bufferlist.slots[n].width // (maxlen + 2), 1)
|
numcols = max(self.bufferlist.slots[n].width // (maxlen + 2), 1)
|
||||||
numrows = clen - ((clen // numcols) * (numcols - 1))
|
numrows = clen - ((clen // numcols) * (numcols - 1))
|
||||||
for i in range(0, numrows):
|
for i in xrange(0, numrows):
|
||||||
names = []
|
names = []
|
||||||
index = i * numcols
|
index = i * numcols
|
||||||
for j in range(0, numcols):
|
for j in xrange(0, numcols):
|
||||||
if index + j < clen:
|
if index + j < clen:
|
||||||
names.append('%-*s' % (maxlen, candidates[index + j]))
|
names.append('%-*s' % (maxlen, candidates[index + j]))
|
||||||
else:
|
else:
|
||||||
|
@ -382,7 +382,7 @@ class Application(object):
|
||||||
blist.remove_buffer(b)
|
blist.remove_buffer(b)
|
||||||
b.close()
|
b.close()
|
||||||
active_slot = blist.slots[self.active_slot]
|
active_slot = blist.slots[self.active_slot]
|
||||||
for i in range(0, len(blist.slots)):
|
for i in xrange(0, len(blist.slots)):
|
||||||
if blist.slots[i].is_empty():
|
if blist.slots[i].is_empty():
|
||||||
if blist.hidden_buffers:
|
if blist.hidden_buffers:
|
||||||
blist.set_slot(i, blist.hidden_buffers[0])
|
blist.set_slot(i, blist.hidden_buffers[0])
|
||||||
|
@ -837,7 +837,7 @@ class Application(object):
|
||||||
# sub-drawing methods
|
# sub-drawing methods
|
||||||
def draw_slots(self):
|
def draw_slots(self):
|
||||||
self.win.erase()
|
self.win.erase()
|
||||||
for i in range(0, len(self.bufferlist.slots)):
|
for i in xrange(0, len(self.bufferlist.slots)):
|
||||||
#slot = self.bufferlist.slots[i]
|
#slot = self.bufferlist.slots[i]
|
||||||
self.draw_slot(i)
|
self.draw_slot(i)
|
||||||
self.draw_status_bar(i)
|
self.draw_status_bar(i)
|
||||||
|
@ -854,7 +854,7 @@ class Application(object):
|
||||||
|
|
||||||
def highlight_chars(self, sy, sx1, sx2, fg='default', bg='default'):
|
def highlight_chars(self, sy, sx1, sx2, fg='default', bg='default'):
|
||||||
assert sx2 < self.x, "%d < %d" % (sx2, self.x)
|
assert sx2 < self.x, "%d < %d" % (sx2, self.x)
|
||||||
for x in range(sx1, sx2):
|
for x in xrange(sx1, sx2):
|
||||||
self.highlight_char(sy, x, fg, bg)
|
self.highlight_char(sy, x, fg, bg)
|
||||||
|
|
||||||
def highlight_simple_range(self, slot, y1, x1, x2, fg, bg):
|
def highlight_simple_range(self, slot, y1, x1, x2, fg, bg):
|
||||||
|
@ -936,7 +936,7 @@ class Application(object):
|
||||||
if w.mode.header:
|
if w.mode.header:
|
||||||
rstrs = w.mode.get_header()
|
rstrs = w.mode.get_header()
|
||||||
assert len(rstrs) >= w.mode.header
|
assert len(rstrs) >= w.mode.header
|
||||||
for j in range(0, w.mode.header):
|
for j in xrange(0, w.mode.header):
|
||||||
k = 0
|
k = 0
|
||||||
for rstr in rstrs[j]:
|
for rstr in rstrs[j]:
|
||||||
rstr.draw(self.win, slot.y_offset + j, slot.x_offset + k, slot.width)
|
rstr.draw(self.win, slot.y_offset + j, slot.x_offset + k, slot.width)
|
||||||
|
@ -971,7 +971,7 @@ class Application(object):
|
||||||
shade = util.get_margin_color(w, 'blue')
|
shade = util.get_margin_color(w, 'blue')
|
||||||
limit = util.get_margin_limit(w, 80)
|
limit = util.get_margin_limit(w, 80)
|
||||||
if limit < self.x:
|
if limit < self.x:
|
||||||
for j in range(0, slot.height):
|
for j in xrange(0, slot.height):
|
||||||
char = chr(self.win.inch(j + slot.y_offset, limit) & 255)
|
char = chr(self.win.inch(j + slot.y_offset, limit) & 255)
|
||||||
attr = color.build('default', shade, 'bold')
|
attr = color.build('default', shade, 'bold')
|
||||||
self.addstr(j + slot.y_offset, limit + w.mode.lmargin, char, attr)
|
self.addstr(j + slot.y_offset, limit + w.mode.lmargin, char, attr)
|
||||||
|
@ -996,7 +996,7 @@ class Application(object):
|
||||||
rlines = w.render_line_lit(y, swidth)
|
rlines = w.render_line_lit(y, swidth)
|
||||||
else:
|
else:
|
||||||
rlines = w.render_line_raw(y, swidth)
|
rlines = w.render_line_raw(y, swidth)
|
||||||
for j in range(k, len(rlines)):
|
for j in xrange(k, len(rlines)):
|
||||||
y2 = slot.y_offset + count
|
y2 = slot.y_offset + count
|
||||||
if lm:
|
if lm:
|
||||||
lcont = j > 0
|
lcont = j > 0
|
||||||
|
@ -1031,7 +1031,7 @@ class Application(object):
|
||||||
attr = color.build('default', 'default')
|
attr = color.build('default', 'default')
|
||||||
if self.error_string:
|
if self.error_string:
|
||||||
attr = color.build('default', 'default')
|
attr = color.build('default', 'default')
|
||||||
for i in range(0, len(lines)):
|
for i in xrange(0, len(lines)):
|
||||||
line = lines[i]
|
line = lines[i]
|
||||||
try:
|
try:
|
||||||
self.addstr(self.y - len(lines) + i, 0, line, attr)
|
self.addstr(self.y - len(lines) + i, 0, line, attr)
|
||||||
|
@ -1041,7 +1041,7 @@ class Application(object):
|
||||||
return
|
return
|
||||||
pattr = color.build('cyan', 'default', 'bold')
|
pattr = color.build('cyan', 'default', 'bold')
|
||||||
plines = self.get_minibuffer_x_lines(self.mini_prompt)
|
plines = self.get_minibuffer_x_lines(self.mini_prompt)
|
||||||
for i in range(0, len(plines)):
|
for i in xrange(0, len(plines)):
|
||||||
pline = plines[i]
|
pline = plines[i]
|
||||||
try:
|
try:
|
||||||
self.addstr(self.y - len(lines) + i, 0, pline, pattr)
|
self.addstr(self.y - len(lines) + i, 0, pline, pattr)
|
||||||
|
|
|
@ -284,7 +284,7 @@ class Buffer(object):
|
||||||
assert p1 <= p2, "p1.x (%d) > p2.x (%d)" % (p1.x, p2.x)
|
assert p1 <= p2, "p1.x (%d) > p2.x (%d)" % (p1.x, p2.x)
|
||||||
lines = []
|
lines = []
|
||||||
x = p1.x
|
x = p1.x
|
||||||
for i in range(p1.y, p2.y):
|
for i in xrange(p1.y, p2.y):
|
||||||
lines.append(self.lines[i][x:])
|
lines.append(self.lines[i][x:])
|
||||||
x = 0
|
x = 0
|
||||||
lines.append(self.lines[p2.y][x:p2.x])
|
lines.append(self.lines[p2.y][x:p2.x])
|
||||||
|
@ -325,7 +325,7 @@ class Buffer(object):
|
||||||
self.lines.insert(p.y + 1, [])
|
self.lines.insert(p.y + 1, [])
|
||||||
self.lines[p.y + 1] = lines[-1] + self.lines[p.y][p.x:]
|
self.lines[p.y + 1] = lines[-1] + self.lines[p.y][p.x:]
|
||||||
self.lines[p.y] = self.lines[p.y][:p.x] + lines[0]
|
self.lines[p.y] = self.lines[p.y][:p.x] + lines[0]
|
||||||
for i in range(1, llen - 1):
|
for i in xrange(1, llen - 1):
|
||||||
self.lines.insert(p.y + i, lines[i])
|
self.lines.insert(p.y + i, lines[i])
|
||||||
else:
|
else:
|
||||||
self.lines[p.y] = self.lines[p.y][:p.x] + lines[-1] + self.lines[p.y][p.x:]
|
self.lines[p.y] = self.lines[p.y][:p.x] + lines[-1] + self.lines[p.y][p.x:]
|
||||||
|
@ -376,7 +376,7 @@ class Buffer(object):
|
||||||
return m.end()
|
return m.end()
|
||||||
def detect_indent_level(self, y1, y2):
|
def detect_indent_level(self, y1, y2):
|
||||||
x = None
|
x = None
|
||||||
for y in range(y1, y2):
|
for y in xrange(y1, y2):
|
||||||
if self.is_whitespace(y):
|
if self.is_whitespace(y):
|
||||||
continue
|
continue
|
||||||
c = self.count_leading_whitespace(y)
|
c = self.count_leading_whitespace(y)
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ColorHighlighter(Highlighter):
|
||||||
def delete_token(self, y, i):
|
def delete_token(self, y, i):
|
||||||
del self.tokens[y][i]
|
del self.tokens[y][i]
|
||||||
def relex(self, lines, y1, x1, y2, x2, token=None):
|
def relex(self, lines, y1, x1, y2, x2, token=None):
|
||||||
for y in range(y1, y2 + 1):
|
for y in xrange(y1, y2 + 1):
|
||||||
self.highlight_line(y, lines[y])
|
self.highlight_line(y, lines[y])
|
||||||
|
|
||||||
def highlight_line(self, y, line):
|
def highlight_line(self, y, line):
|
||||||
|
@ -52,7 +52,7 @@ class ColorHighlighter(Highlighter):
|
||||||
if self.tokens:
|
if self.tokens:
|
||||||
return
|
return
|
||||||
self.tokens = [None] * len(lines)
|
self.tokens = [None] * len(lines)
|
||||||
for y in range(0, len(lines)):
|
for y in xrange(0, len(lines)):
|
||||||
self.highlight_line(y, lines[y])
|
self.highlight_line(y, lines[y])
|
||||||
|
|
||||||
class ColorDataBuffer(DataBuffer):
|
class ColorDataBuffer(DataBuffer):
|
||||||
|
|
|
@ -58,7 +58,7 @@ class DirBuffer(Buffer):
|
||||||
continue
|
continue
|
||||||
path = self._make_path(name)
|
path = self._make_path(name)
|
||||||
fields = dirutil.path_fields(path, name)
|
fields = dirutil.path_fields(path, name)
|
||||||
for i in range(0, 5):
|
for i in xrange(0, 5):
|
||||||
try:
|
try:
|
||||||
maxlens[i] = max(maxlens[i], len(fields[i]))
|
maxlens[i] = max(maxlens[i], len(fields[i]))
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -107,7 +107,7 @@ class PipeBuffer(Buffer):
|
||||||
self.lines.insert(p.y + 1, [])
|
self.lines.insert(p.y + 1, [])
|
||||||
self.lines[p.y + 1] = lines[-1] + self.lines[p.y][p.x:]
|
self.lines[p.y + 1] = lines[-1] + self.lines[p.y][p.x:]
|
||||||
self.lines[p.y] = self.lines[p.y][:p.x] + lines[0]
|
self.lines[p.y] = self.lines[p.y][:p.x] + lines[0]
|
||||||
for i in range(1, llen - 1):
|
for i in xrange(1, llen - 1):
|
||||||
self.lines.insert(p.y + i, lines[i])
|
self.lines.insert(p.y + i, lines[i])
|
||||||
else:
|
else:
|
||||||
self.lines[p.y] = self.lines[p.y][:p.x] + lines[-1] + self.lines[p.y][p.x:]
|
self.lines[p.y] = self.lines[p.y][:p.x] + lines[-1] + self.lines[p.y][p.x:]
|
||||||
|
|
|
@ -43,12 +43,12 @@ class BufferList(object):
|
||||||
def fit_slots(self):
|
def fit_slots(self):
|
||||||
total = self.height - len(self.slots) + 1 - self.mini_height
|
total = self.height - len(self.slots) + 1 - self.mini_height
|
||||||
heights = [total / len(self.slots)] * len(self.slots)
|
heights = [total / len(self.slots)] * len(self.slots)
|
||||||
for i in range(0, total % len(self.slots)):
|
for i in xrange(0, total % len(self.slots)):
|
||||||
heights[i] += 1
|
heights[i] += 1
|
||||||
offsets = [0]
|
offsets = [0]
|
||||||
for i in range(1, len(self.slots)):
|
for i in xrange(1, len(self.slots)):
|
||||||
offsets.insert(i, offsets[i - 1] + heights[i - 1] + 1)
|
offsets.insert(i, offsets[i - 1] + heights[i - 1] + 1)
|
||||||
for i in range(0, len(self.slots)):
|
for i in xrange(0, len(self.slots)):
|
||||||
self.slots[i].resize(heights[i], self.width, offsets[i])
|
self.slots[i].resize(heights[i], self.width, offsets[i])
|
||||||
def resize_mini(self, n):
|
def resize_mini(self, n):
|
||||||
self.mini_height = n
|
self.mini_height = n
|
||||||
|
@ -128,13 +128,13 @@ class BufferList(object):
|
||||||
return b
|
return b
|
||||||
return None
|
return None
|
||||||
def close_buffer(self, b):
|
def close_buffer(self, b):
|
||||||
for i in range(0, len(self.slots)):
|
for i in xrange(0, len(self.slots)):
|
||||||
slot = self.slots[i]
|
slot = self.slots[i]
|
||||||
if slot.window is not None and slot.window.buffer is b:
|
if slot.window is not None and slot.window.buffer is b:
|
||||||
self.unset_slot(i)
|
self.unset_slot(i)
|
||||||
def remove_buffer(self, b):
|
def remove_buffer(self, b):
|
||||||
assert b in self.buffers, "buffer %s does not exist" % (b.name())
|
assert b in self.buffers, "buffer %s does not exist" % (b.name())
|
||||||
for i in range(0, len(self.slots)):
|
for i in xrange(0, len(self.slots)):
|
||||||
slot = self.slots[i]
|
slot = self.slots[i]
|
||||||
if slot.window is not None and slot.window.buffer is b:
|
if slot.window is not None and slot.window.buffer is b:
|
||||||
self.unset_slot(i)
|
self.unset_slot(i)
|
||||||
|
|
10
color.py
10
color.py
|
@ -32,9 +32,9 @@ def add_color(name, value, abbrev):
|
||||||
# assign every RGB triple (0-5) to one of six basic colors (red, yellow, green,
|
# assign every RGB triple (0-5) to one of six basic colors (red, yellow, green,
|
||||||
# cyan, blue, magenta) based on some semi-arbitrary rules i came up with.
|
# cyan, blue, magenta) based on some semi-arbitrary rules i came up with.
|
||||||
def iter256():
|
def iter256():
|
||||||
for r in range(0, 6):
|
for r in xrange(0, 6):
|
||||||
for g in range(0, 6):
|
for g in xrange(0, 6):
|
||||||
for b in range(0, 6):
|
for b in xrange(0, 6):
|
||||||
#if r >= 3 and g >= 3 and b >= 3: name = 'white'
|
#if r >= 3 and g >= 3 and b >= 3: name = 'white'
|
||||||
#elif r >= g and g > b: name = 'yellow'
|
#elif r >= g and g > b: name = 'yellow'
|
||||||
if r >= g and g > b: name = 'yellow'
|
if r >= g and g > b: name = 'yellow'
|
||||||
|
@ -90,13 +90,13 @@ def init():
|
||||||
rev_ascii_map['default'] = 'd'
|
rev_ascii_map['default'] = 'd'
|
||||||
|
|
||||||
# add in hex aliases to 256 colors; used by color-data buffers
|
# add in hex aliases to 256 colors; used by color-data buffers
|
||||||
for i in range(0, 256):
|
for i in xrange(0, 256):
|
||||||
name = 'f%02x' % i
|
name = 'f%02x' % i
|
||||||
abbrev = 'f%02x' % i
|
abbrev = 'f%02x' % i
|
||||||
add_color(name, i, abbrev)
|
add_color(name, i, abbrev)
|
||||||
|
|
||||||
# create the 24 flavors of grey in 256 colors
|
# create the 24 flavors of grey in 256 colors
|
||||||
for i in range(0, 24):
|
for i in xrange(0, 24):
|
||||||
name2 = 'grey%d' % i
|
name2 = 'grey%d' % i
|
||||||
abbrev2 = 'G%d' % i
|
abbrev2 = 'G%d' % i
|
||||||
if curses.COLORS == 256:
|
if curses.COLORS == 256:
|
||||||
|
|
|
@ -19,12 +19,13 @@ class Context(object):
|
||||||
return
|
return
|
||||||
elif delta > 0:
|
elif delta > 0:
|
||||||
self.namelines.extend([(None, None)] * delta)
|
self.namelines.extend([(None, None)] * delta)
|
||||||
for i in reversed(range(p.y + 1, len(self.mode.window.buffer.lines))):
|
l = len(self.mode.window.buffer.lines)
|
||||||
|
for i in reversed(xrange(p.y + 1, l)):
|
||||||
self.namelines[i] = self.namelines[i - delta]
|
self.namelines[i] = self.namelines[i - delta]
|
||||||
for i in range(p.y, p.y + delta):
|
for i in xrange(p.y, p.y + delta):
|
||||||
self.namelines[i] = (None, None)
|
self.namelines[i] = (None, None)
|
||||||
else:
|
else:
|
||||||
for i in range(p.y + 1, len(self.mode.window.buffer.lines)):
|
for i in xrange(p.y + 1, len(self.mode.window.buffer.lines)):
|
||||||
self.namelines[i + delta] = self.namelines[i]
|
self.namelines[i + delta] = self.namelines[i]
|
||||||
|
|
||||||
def _init_name_map(self):
|
def _init_name_map(self):
|
||||||
|
@ -56,7 +57,7 @@ class Context(object):
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
def rebuild_name_map(self, y1, y2):
|
def rebuild_name_map(self, y1, y2):
|
||||||
for y in range(y1, y2):
|
for y in xrange(y1, y2):
|
||||||
(name, info) = self.namelines[y]
|
(name, info) = self.namelines[y]
|
||||||
self._del_name(y, name)
|
self._del_name(y, name)
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ def path_fields(path, name):
|
||||||
for bundle in ((stat.S_IRUSR, stat.S_IWUSR, stat.S_IXUSR),
|
for bundle in ((stat.S_IRUSR, stat.S_IWUSR, stat.S_IXUSR),
|
||||||
(stat.S_IRGRP, stat.S_IWGRP, stat.S_IXGRP),
|
(stat.S_IRGRP, stat.S_IWGRP, stat.S_IXGRP),
|
||||||
(stat.S_IROTH, stat.S_IWOTH, stat.S_IXOTH)):
|
(stat.S_IROTH, stat.S_IWOTH, stat.S_IXOTH)):
|
||||||
for j in range(0, 3):
|
for j in xrange(0, 3):
|
||||||
if info.st_mode & bundle[j]:
|
if info.st_mode & bundle[j]:
|
||||||
perm[i] = symbols[j]
|
perm[i] = symbols[j]
|
||||||
else:
|
else:
|
||||||
|
|
26
highlight.py
26
highlight.py
|
@ -12,10 +12,10 @@ color_names = [
|
||||||
color_dict ={}
|
color_dict ={}
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
|
color_list.extend(['\033[3%dm' % x for x in xrange(0, 8)])
|
||||||
color_list.extend(['\033[3%d;1m' % x for x in range(0, 8)])
|
color_list.extend(['\033[3%d;1m' % x for x in xrange(0, 8)])
|
||||||
color_list.extend(['\033[0m'])
|
color_list.extend(['\033[0m'])
|
||||||
for i in range(0, len(color_list)):
|
for i in xrange(0, len(color_list)):
|
||||||
color_dict[color_names[i]] = color_list[i]
|
color_dict[color_names[i]] = color_list[i]
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class Highlighter(object):
|
||||||
|
|
||||||
def dump(self, fmt='(%3s, %2s) | %s'):
|
def dump(self, fmt='(%3s, %2s) | %s'):
|
||||||
print fmt % ('y', 'x', 'string')
|
print fmt % ('y', 'x', 'string')
|
||||||
for i in range(0, len(self.tokens)):
|
for i in xrange(0, len(self.tokens)):
|
||||||
group = self.tokens[i]
|
group = self.tokens[i]
|
||||||
print 'LINE %d' % i
|
print 'LINE %d' % i
|
||||||
for token in group:
|
for token in group:
|
||||||
|
@ -37,7 +37,7 @@ class Highlighter(object):
|
||||||
for token in group:
|
for token in group:
|
||||||
color_name = None
|
color_name = None
|
||||||
name_parts = token.name.split('.')
|
name_parts = token.name.split('.')
|
||||||
for i in range(0, len(name_parts)):
|
for i in xrange(0, len(name_parts)):
|
||||||
if '.'.join(name_parts[i:]) in token_colors:
|
if '.'.join(name_parts[i:]) in token_colors:
|
||||||
color_name = token_colors['.'.join(name_parts[i:])]
|
color_name = token_colors['.'.join(name_parts[i:])]
|
||||||
break
|
break
|
||||||
|
@ -104,7 +104,7 @@ class Highlighter(object):
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
# ok, so this means that ALL the rest of the tokens didn't
|
# ok, so this means that ALL the rest of the tokens didn't
|
||||||
# show up, because we're done. so delete them and exit
|
# show up, because we're done. so delete them and exit
|
||||||
for j in range(y, len(lines)):
|
for j in xrange(y, len(lines)):
|
||||||
del self.tokens[j][i:]
|
del self.tokens[j][i:]
|
||||||
i = 0
|
i = 0
|
||||||
break
|
break
|
||||||
|
@ -188,9 +188,9 @@ class Highlighter(object):
|
||||||
|
|
||||||
# ok, so now we need to "adjust" the (x,y) coordinates of all the tokens
|
# ok, so now we need to "adjust" the (x,y) coordinates of all the tokens
|
||||||
# after the change. first we will copy over the pre-deletion tokens.
|
# after the change. first we will copy over the pre-deletion tokens.
|
||||||
newtokens = [[] for _ in range(0, len(self.tokens) - y2 + y1)]
|
newtokens = [[] for _ in xrange(0, len(self.tokens) - y2 + y1)]
|
||||||
|
|
||||||
for y in range(0, y1):
|
for y in xrange(0, y1):
|
||||||
for token in self.tokens[y]:
|
for token in self.tokens[y]:
|
||||||
newtokens[y].append(token)
|
newtokens[y].append(token)
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ class Highlighter(object):
|
||||||
newtokens[y1].append(token)
|
newtokens[y1].append(token)
|
||||||
|
|
||||||
# finally, we will copy over the tokens from subsequent lines
|
# finally, we will copy over the tokens from subsequent lines
|
||||||
for y in range(y2 + 1, len(self.tokens)):
|
for y in xrange(y2 + 1, len(self.tokens)):
|
||||||
for token in self.tokens[y]:
|
for token in self.tokens[y]:
|
||||||
token.y = token.y - y2 + y1
|
token.y = token.y - y2 + y1
|
||||||
newtokens[y - y2 + y1].append(token)
|
newtokens[y - y2 + y1].append(token)
|
||||||
|
@ -242,11 +242,11 @@ class Highlighter(object):
|
||||||
|
|
||||||
# construct a new token data structure, with the right number of lines
|
# construct a new token data structure, with the right number of lines
|
||||||
newtokens = []
|
newtokens = []
|
||||||
for i in range(0, len(self.tokens) + ydelta):
|
for i in xrange(0, len(self.tokens) + ydelta):
|
||||||
newtokens.append([])
|
newtokens.append([])
|
||||||
|
|
||||||
# copy the tokens that show up before the changed line
|
# copy the tokens that show up before the changed line
|
||||||
for y in range(0, y1):
|
for y in xrange(0, y1):
|
||||||
newtokens[y] = self.tokens[y]
|
newtokens[y] = self.tokens[y]
|
||||||
|
|
||||||
# process the tokens that show up on the changed line
|
# process the tokens that show up on the changed line
|
||||||
|
@ -276,7 +276,7 @@ class Highlighter(object):
|
||||||
|
|
||||||
# add in the new data
|
# add in the new data
|
||||||
newtokens[y1].append(Token('new', '', y1, x1, newlines[0]))
|
newtokens[y1].append(Token('new', '', y1, x1, newlines[0]))
|
||||||
for i in range(1, len(newlines)):
|
for i in xrange(1, len(newlines)):
|
||||||
yi = y1 + i
|
yi = y1 + i
|
||||||
newtokens[yi].append(Token('new', '', yi, 0, newlines[i]))
|
newtokens[yi].append(Token('new', '', yi, 0, newlines[i]))
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ class Highlighter(object):
|
||||||
newtokens[y2].append(t)
|
newtokens[y2].append(t)
|
||||||
|
|
||||||
# for each subsequent line, fix it's tokens' y coordinates
|
# for each subsequent line, fix it's tokens' y coordinates
|
||||||
for y in range(y1 + 1, len(self.tokens)):
|
for y in xrange(y1 + 1, len(self.tokens)):
|
||||||
for t in self.tokens[y]:
|
for t in self.tokens[y]:
|
||||||
t.y += ydelta
|
t.y += ydelta
|
||||||
newtokens[t.y].append(t)
|
newtokens[t.y].append(t)
|
||||||
|
|
|
@ -85,7 +85,7 @@ def setup():
|
||||||
MAP[27][key] = "M-%s" % (MAP[key])
|
MAP[27][key] = "M-%s" % (MAP[key])
|
||||||
|
|
||||||
# add meta character stuff
|
# add meta character stuff
|
||||||
for i in range(33, 126):
|
for i in xrange(33, 126):
|
||||||
if i == 79 or i == 91:
|
if i == 79 or i == 91:
|
||||||
# these keys are used in other sequences
|
# these keys are used in other sequences
|
||||||
continue
|
continue
|
||||||
|
@ -105,7 +105,7 @@ def disable_control_chars():
|
||||||
|
|
||||||
# remove as many signal handlers as we can; we want to leave C-d and C-z
|
# remove as many signal handlers as we can; we want to leave C-d and C-z
|
||||||
# probably
|
# probably
|
||||||
for pos in range(0,len(attr[6])):
|
for pos in xrange(0, len(attr[6])):
|
||||||
if pos == termios.VEOF or pos == termios.VSUSP:
|
if pos == termios.VEOF or pos == termios.VSUSP:
|
||||||
continue
|
continue
|
||||||
attr[6][pos] = '\x00'
|
attr[6][pos] = '\x00'
|
||||||
|
|
|
@ -515,7 +515,7 @@ class TabBuffer(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
y = w.logical_cursor().y
|
y = w.logical_cursor().y
|
||||||
it = InsertTab()
|
it = InsertTab()
|
||||||
for i in range(0, len(w.buffer.lines)):
|
for i in xrange(0, len(w.buffer.lines)):
|
||||||
w.goto_line(i + 1)
|
w.goto_line(i + 1)
|
||||||
it.execute(w)
|
it.execute(w)
|
||||||
w.goto_line(y + 1)
|
w.goto_line(y + 1)
|
||||||
|
@ -548,7 +548,7 @@ class CommentRegion(Method):
|
||||||
c = w.mode.commentc or '#'
|
c = w.mode.commentc or '#'
|
||||||
lvl = w.buffer.detect_indent_level(p1.y, p2.y) or 0
|
lvl = w.buffer.detect_indent_level(p1.y, p2.y) or 0
|
||||||
|
|
||||||
for y in range(p1.y, p2.y):
|
for y in xrange(p1.y, p2.y):
|
||||||
if len(w.buffer.lines[y]) < lvl:
|
if len(w.buffer.lines[y]) < lvl:
|
||||||
pad = lvl - len(w.buffer.lines[y])
|
pad = lvl - len(w.buffer.lines[y])
|
||||||
x = lvl - pad
|
x = lvl - pad
|
||||||
|
@ -574,7 +574,7 @@ class UncommentRegion(Method):
|
||||||
commentc = w.mode.commentc or '#'
|
commentc = w.mode.commentc or '#'
|
||||||
commentre = re.compile('^( *)(%s)' % commentc)
|
commentre = re.compile('^( *)(%s)' % commentc)
|
||||||
|
|
||||||
for y in range(p1.y, p2.y):
|
for y in xrange(p1.y, p2.y):
|
||||||
line = w.buffer.lines[y]
|
line = w.buffer.lines[y]
|
||||||
m = commentre.match(line)
|
m = commentre.match(line)
|
||||||
if not m:
|
if not m:
|
||||||
|
@ -839,7 +839,7 @@ class UnindentBlock(Method):
|
||||||
w.input_line = "Empty kill region"
|
w.input_line = "Empty kill region"
|
||||||
return
|
return
|
||||||
lines = w.buffer.lines[p1.y:p2.y]
|
lines = w.buffer.lines[p1.y:p2.y]
|
||||||
for i in range(0, len(lines)):
|
for i in xrange(0, len(lines)):
|
||||||
if lines[i].startswith(' '):
|
if lines[i].startswith(' '):
|
||||||
lines[i] = lines[i][lvl:]
|
lines[i] = lines[i][lvl:]
|
||||||
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
||||||
|
@ -859,7 +859,7 @@ class IndentBlock(Method):
|
||||||
return
|
return
|
||||||
lines = w.buffer.lines[p1.y:p2.y]
|
lines = w.buffer.lines[p1.y:p2.y]
|
||||||
tstr = ' ' * w.mode.tabwidth
|
tstr = ' ' * w.mode.tabwidth
|
||||||
for i in range(0, len(lines)):
|
for i in xrange(0, len(lines)):
|
||||||
lines[i] = tstr + lines[i]
|
lines[i] = tstr + lines[i]
|
||||||
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
||||||
w.buffer.insert_string(Point(0, p1.y), '\n'.join(lines) + '\n')
|
w.buffer.insert_string(Point(0, p1.y), '\n'.join(lines) + '\n')
|
||||||
|
|
|
@ -13,7 +13,7 @@ class DumpContext(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
lines = []
|
lines = []
|
||||||
if w.mode.context:
|
if w.mode.context:
|
||||||
for i in range(0, len(w.mode.context.namelines)):
|
for i in xrange(0, len(w.mode.context.namelines)):
|
||||||
lines.append("LINE %d: %r" % (i + 1, repr(w.mode.context.namelines[i])))
|
lines.append("LINE %d: %r" % (i + 1, repr(w.mode.context.namelines[i])))
|
||||||
else:
|
else:
|
||||||
lines.append("no context")
|
lines.append("no context")
|
||||||
|
@ -52,7 +52,7 @@ class DumpTokens(Method):
|
||||||
lines = []
|
lines = []
|
||||||
if w.mode.name in w.buffer.highlights:
|
if w.mode.name in w.buffer.highlights:
|
||||||
tokens = w.buffer.highlights[w.mode.name].tokens
|
tokens = w.buffer.highlights[w.mode.name].tokens
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
lines.append("LINE %d" % (i + 1))
|
lines.append("LINE %d" % (i + 1))
|
||||||
group = tokens[i]
|
group = tokens[i]
|
||||||
for token in group:
|
for token in group:
|
||||||
|
|
|
@ -27,7 +27,7 @@ class VcBlame(Method):
|
||||||
gsizes = [0] * self.num_fields
|
gsizes = [0] * self.num_fields
|
||||||
for line in pipe.stdout:
|
for line in pipe.stdout:
|
||||||
d = self._filter(line)
|
d = self._filter(line)
|
||||||
for i in range(0, self.num_fields):
|
for i in xrange(0, self.num_fields):
|
||||||
gsizes[i] = max(gsizes[i], len(d['fields'][i]))
|
gsizes[i] = max(gsizes[i], len(d['fields'][i]))
|
||||||
groups.append(d)
|
groups.append(d)
|
||||||
status = pipe.wait() >> 8
|
status = pipe.wait() >> 8
|
||||||
|
|
|
@ -13,7 +13,7 @@ def proc(asttup):
|
||||||
elif node[0] in token.tok_name:
|
elif node[0] in token.tok_name:
|
||||||
pairs.append((token.tok_name[node[0]], node[1]))
|
pairs.append((token.tok_name[node[0]], node[1]))
|
||||||
else:
|
else:
|
||||||
for i in range(0, len(node) - 1):
|
for i in xrange(0, len(node) - 1):
|
||||||
queue.insert(i, node[i + 1])
|
queue.insert(i, node[i + 1])
|
||||||
return pairs
|
return pairs
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from lex import Grammar, PatternRule
|
||||||
|
|
||||||
class ColortestGrammar(Grammar):
|
class ColortestGrammar(Grammar):
|
||||||
rules = []
|
rules = []
|
||||||
for i in range(0, 256):
|
for i in xrange(0, 256):
|
||||||
c = '%02x' % i
|
c = '%02x' % i
|
||||||
rules.append(PatternRule('z' + c, c))
|
rules.append(PatternRule('z' + c, c))
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ class ConsoleTab(Method):
|
||||||
|
|
||||||
curr_t = None
|
curr_t = None
|
||||||
curr_i = None
|
curr_i = None
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
t = tokens[i]
|
t = tokens[i]
|
||||||
if t.x < x and t.end_x() >= x:
|
if t.x < x and t.end_x() >= x:
|
||||||
curr_i = i
|
curr_i = i
|
||||||
|
|
|
@ -41,12 +41,12 @@ class HexBackward(Method):
|
||||||
class HexForwardWord(Method):
|
class HexForwardWord(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
hf = w.application.methods['hex-forward']
|
hf = w.application.methods['hex-forward']
|
||||||
for i in range(0, w.buffer.wordsize * 2):
|
for i in xrange(0, w.buffer.wordsize * 2):
|
||||||
hf.execute(w, **vargs)
|
hf.execute(w, **vargs)
|
||||||
class HexBackwardWord(Method):
|
class HexBackwardWord(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
hb = w.application.methods['hex-backward']
|
hb = w.application.methods['hex-backward']
|
||||||
for i in range(0, w.buffer.wordsize * 2):
|
for i in xrange(0, w.buffer.wordsize * 2):
|
||||||
hb.execute(w, **vargs)
|
hb.execute(w, **vargs)
|
||||||
|
|
||||||
class HexStartOfLine(Method):
|
class HexStartOfLine(Method):
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Pipe(Fundamental):
|
||||||
continue
|
continue
|
||||||
del self.bindings[key]
|
del self.bindings[key]
|
||||||
|
|
||||||
for i in range(0, 128):
|
for i in xrange(0, 128):
|
||||||
if i in (22, 24, 27):
|
if i in (22, 24, 27):
|
||||||
continue
|
continue
|
||||||
sym = keyinput.MAP.get(i, chr(i))
|
sym = keyinput.MAP.get(i, chr(i))
|
||||||
|
|
|
@ -136,7 +136,7 @@ class PythonTabber(tab.StackTabber):
|
||||||
self.popped = True
|
self.popped = True
|
||||||
# ok, having done all that, we can now process each token
|
# ok, having done all that, we can now process each token
|
||||||
# on the line
|
# on the line
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
currlvl = self._handle_token(currlvl, y, i)
|
currlvl = self._handle_token(currlvl, y, i)
|
||||||
# so let's store the level for this line, as well as some debugging
|
# so let's store the level for this line, as well as some debugging
|
||||||
self.lines[y] = currlvl
|
self.lines[y] = currlvl
|
||||||
|
@ -318,7 +318,7 @@ class PythonInsertTripleSquotes(Method):
|
||||||
_q = "'''"
|
_q = "'''"
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.insert_string_at_cursor('%s%s' % (self._q, self._q))
|
w.insert_string_at_cursor('%s%s' % (self._q, self._q))
|
||||||
for i in range(0, 3):
|
for i in xrange(0, 3):
|
||||||
w.backward()
|
w.backward()
|
||||||
|
|
||||||
class PythonInsertTripleDquotes(PythonInsertTripleSquotes):
|
class PythonInsertTripleDquotes(PythonInsertTripleSquotes):
|
||||||
|
@ -510,7 +510,7 @@ class PythonContext(context.Context):
|
||||||
if last is not None:
|
if last is not None:
|
||||||
curr = '.'.join([x[1] for x in stack])
|
curr = '.'.join([x[1] for x in stack])
|
||||||
if curr:
|
if curr:
|
||||||
for k in range(last, i):
|
for k in xrange(last, i):
|
||||||
self.namelines[k] = (curr, None)
|
self.namelines[k] = (curr, None)
|
||||||
last = None
|
last = None
|
||||||
|
|
||||||
|
@ -525,7 +525,7 @@ class PythonContext(context.Context):
|
||||||
curr = '.'.join([x[1] for x in stack])
|
curr = '.'.join([x[1] for x in stack])
|
||||||
self.names[curr] = i
|
self.names[curr] = i
|
||||||
|
|
||||||
for k in range(1, len(stack)):
|
for k in xrange(1, len(stack)):
|
||||||
curr = '.'.join(x[1] for x in stack[k:])
|
curr = '.'.join(x[1] for x in stack[k:])
|
||||||
if curr not in abbrev:
|
if curr not in abbrev:
|
||||||
abbrev[curr] = i
|
abbrev[curr] = i
|
||||||
|
@ -549,7 +549,7 @@ class PythonContext(context.Context):
|
||||||
n = len(self.namelines[y2][0].split('.'))
|
n = len(self.namelines[y2][0].split('.'))
|
||||||
curr = '.'.join([x[1] for x in stack[:n]])
|
curr = '.'.join([x[1] for x in stack[:n]])
|
||||||
if curr:
|
if curr:
|
||||||
for k in range(last, y2):
|
for k in xrange(last, y2):
|
||||||
self.namelines[k] = (curr, None)
|
self.namelines[k] = (curr, None)
|
||||||
|
|
||||||
# white is for delimiters, operators, numbers
|
# white is for delimiters, operators, numbers
|
||||||
|
|
|
@ -75,7 +75,7 @@ class ShellTab(Method):
|
||||||
|
|
||||||
curr_t = None
|
curr_t = None
|
||||||
curr_i = None
|
curr_i = None
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
t = tokens[i]
|
t = tokens[i]
|
||||||
if t.x < x and t.end_x() >= x:
|
if t.x < x and t.end_x() >= x:
|
||||||
curr_i = i
|
curr_i = i
|
||||||
|
|
4
parse.py
4
parse.py
|
@ -113,12 +113,12 @@ class Repeat(Rule):
|
||||||
self.maximum = maximum
|
self.maximum = maximum
|
||||||
def match(self, tokens):
|
def match(self, tokens):
|
||||||
n = 0
|
n = 0
|
||||||
for _ in range(0, self.minimum):
|
for _ in xrange(0, self.minimum):
|
||||||
result = self.rule.match(tokens[n:])
|
result = self.rule.match(tokens[n:])
|
||||||
if not result:
|
if not result:
|
||||||
return []
|
return []
|
||||||
n += result[0]
|
n += result[0]
|
||||||
for _ in range(self.minimum, self.maximum):
|
for _ in xrange(self.minimum, self.maximum):
|
||||||
result = self.rule.match(tokens[n:])
|
result = self.rule.match(tokens[n:])
|
||||||
if not result:
|
if not result:
|
||||||
return [n]
|
return [n]
|
||||||
|
|
|
@ -46,7 +46,7 @@ def find(r, w, move=False, direction='next', start=None, end=None):
|
||||||
c = w.logical_cursor()
|
c = w.logical_cursor()
|
||||||
newc = None
|
newc = None
|
||||||
ranges = find_ranges(r, w, start, end)
|
ranges = find_ranges(r, w, start, end)
|
||||||
indices = range(0, len(ranges))
|
indices = list(xrange(0, len(ranges)))
|
||||||
(x, y) = c.xy()
|
(x, y) = c.xy()
|
||||||
if move:
|
if move:
|
||||||
offset = 1
|
offset = 1
|
||||||
|
|
20
tab.py
20
tab.py
|
@ -35,14 +35,14 @@ class Tabber(object):
|
||||||
def get_next_left_token(self, y, i):
|
def get_next_left_token(self, y, i):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
assert i >= 0 and i < len(tokens)
|
assert i >= 0 and i < len(tokens)
|
||||||
for j in range(1, i):
|
for j in xrange(1, i):
|
||||||
if not self.token_is_whitespace(y, i - j):
|
if not self.token_is_whitespace(y, i - j):
|
||||||
return tokens[i - j]
|
return tokens[i - j]
|
||||||
return None
|
return None
|
||||||
def get_next_right_token(self, y, i):
|
def get_next_right_token(self, y, i):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
assert i >= 0 and i < len(tokens)
|
assert i >= 0 and i < len(tokens)
|
||||||
for j in range(i + 1, len(tokens)):
|
for j in xrange(i + 1, len(tokens)):
|
||||||
if not self.token_is_whitespace(y, j):
|
if not self.token_is_whitespace(y, j):
|
||||||
return tokens[j]
|
return tokens[j]
|
||||||
return None
|
return None
|
||||||
|
@ -55,27 +55,27 @@ class Tabber(object):
|
||||||
|
|
||||||
def get_leftmost_token(self, y):
|
def get_leftmost_token(self, y):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
if not self.token_is_whitespace(y, i):
|
if not self.token_is_whitespace(y, i):
|
||||||
return tokens[i]
|
return tokens[i]
|
||||||
return None
|
return None
|
||||||
def get_rightmost_token(self, y):
|
def get_rightmost_token(self, y):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
i = len(tokens) - 1
|
i = len(tokens) - 1
|
||||||
for j in range(0, len(tokens)):
|
for j in xrange(0, len(tokens)):
|
||||||
if not self.token_is_whitespace(y, i - j):
|
if not self.token_is_whitespace(y, i - j):
|
||||||
return tokens[i - j]
|
return tokens[i - j]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_nonws_tokens(self, y):
|
def get_nonws_tokens(self, y):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
if not self.token_is_whitespace(y, i):
|
if not self.token_is_whitespace(y, i):
|
||||||
yield tokens[i]
|
yield tokens[i]
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
def get_nons_tokens(self, y):
|
def get_nons_tokens(self, y):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
if not self.token_is_space(y, i):
|
if not self.token_is_space(y, i):
|
||||||
yield tokens[i]
|
yield tokens[i]
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
@ -133,7 +133,7 @@ class StackTabber(Tabber):
|
||||||
while y <= target:
|
while y <= target:
|
||||||
currlvl = self.get_curr_level()
|
currlvl = self.get_curr_level()
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
for i in range(0, len(tokens)):
|
for i in xrange(0, len(tokens)):
|
||||||
currlvl = self._handle_token(currlvl, y, i)
|
currlvl = self._handle_token(currlvl, y, i)
|
||||||
self.lines[y] = currlvl
|
self.lines[y] = currlvl
|
||||||
self.record[y] = tuple(self.markers)
|
self.record[y] = tuple(self.markers)
|
||||||
|
@ -189,7 +189,7 @@ class StackTabber(Tabber):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
def _peek_until(self, *names):
|
def _peek_until(self, *names):
|
||||||
for i in range(1, len(self.markers) + 1):
|
for i in xrange(1, len(self.markers) + 1):
|
||||||
x = self.markers[-i]
|
x = self.markers[-i]
|
||||||
if x.name in names:
|
if x.name in names:
|
||||||
return x
|
return x
|
||||||
|
@ -325,7 +325,7 @@ class StackTabber2(Tabber):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
def _peek_until(self, *names):
|
def _peek_until(self, *names):
|
||||||
for i in range(1, len(self.stack) + 1):
|
for i in xrange(1, len(self.stack) + 1):
|
||||||
x = self.stack[-i]
|
x = self.stack[-i]
|
||||||
if x.name in names:
|
if x.name in names:
|
||||||
return x
|
return x
|
||||||
|
@ -342,7 +342,7 @@ class StackTabber2(Tabber):
|
||||||
while end > 0 and self._is_ignored(tokens[end]):
|
while end > 0 and self._is_ignored(tokens[end]):
|
||||||
end -= 1
|
end -= 1
|
||||||
|
|
||||||
for i in range(0, end + 1 - start):
|
for i in xrange(0, end + 1 - start):
|
||||||
t = tokens[start + i]
|
t = tokens[start + i]
|
||||||
if self._is_ignored(t):
|
if self._is_ignored(t):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -455,7 +455,7 @@ class Window(object):
|
||||||
self.goto(Point(0, 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 _ in range(0, n):
|
for _ in xrange(0, n):
|
||||||
if x == len(self.buffer.lines[y]):
|
if x == len(self.buffer.lines[y]):
|
||||||
y += 1
|
y += 1
|
||||||
x = 0
|
x = 0
|
||||||
|
|
Loading…
Reference in New Issue