parent
6847df5dff
commit
b431523ede
|
@ -494,7 +494,7 @@ class Application(object):
|
||||||
else:
|
else:
|
||||||
self.highlight_chars(slot.offset + count, px, px + slot.width)
|
self.highlight_chars(slot.offset + count, px, px + slot.width)
|
||||||
px += slot.width
|
px += slot.width
|
||||||
if x + slot.width >= len(line):
|
if x + slot.width >= len(w.buffer.lines[y]):
|
||||||
x = 0
|
x = 0
|
||||||
y += 1
|
y += 1
|
||||||
else:
|
else:
|
||||||
|
@ -584,7 +584,7 @@ class Application(object):
|
||||||
|
|
||||||
s_offset = max(x - token.x, 0)
|
s_offset = max(x - token.x, 0)
|
||||||
x_offset = max(token.x - x, 0)
|
x_offset = max(token.x - x, 0)
|
||||||
assert x_offset < slot.width
|
assert x_offset < slot.width, '%d < %d' % (x_offset, slot.width)
|
||||||
|
|
||||||
c = self._get_token_color(w, token)
|
c = self._get_token_color(w, token)
|
||||||
s = token.string[s_offset:]
|
s = token.string[s_offset:]
|
||||||
|
@ -644,11 +644,10 @@ class Application(object):
|
||||||
perc = "%2d%%" % (first.y*100 / len(b.lines))
|
perc = "%2d%%" % (first.y*100 / len(b.lines))
|
||||||
|
|
||||||
# XYZ: we should actually use more of the 'state' variables
|
# XYZ: we should actually use more of the 'state' variables
|
||||||
|
format = "----:%s-Fl %-18s (%s)--L%d--C%d--%s"
|
||||||
#format = "----:%s-Fl %-18s (%s)--L%d--C%d--%s"
|
status = format % (modflag, name, w.mode.name(), cursor.y+1, cursor.x+1, perc)
|
||||||
#status = format % (modflag, name, w.mode.name(), cursor.y+1, cursor.x+1, perc)
|
#format = "----:%s-Fl %-18s (%s)--L%d--C%d--%s--%s--%s"
|
||||||
format = "----:%s-Fl %-18s (%s)--L%d--C%d--%s--%s--%s"
|
#status = format % (modflag, name, w.mode.name(), cursor.y+1, cursor.x+1, w.first, w.last, perc)
|
||||||
status = format % (modflag, name, w.mode.name(), cursor.y+1, cursor.x+1, w.first, w.last, perc)
|
|
||||||
status = status[:slot.width + 1]
|
status = status[:slot.width + 1]
|
||||||
status += "-" * (slot.width - len(status) + 1)
|
status += "-" * (slot.width - len(status) + 1)
|
||||||
self.win.addnstr(slot.height + slot.offset, 0, status, slot.width + 1,
|
self.win.addnstr(slot.height + slot.offset, 0, status, slot.width + 1,
|
||||||
|
|
38
method.py
38
method.py
|
@ -14,10 +14,10 @@ DATATYPES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Argument:
|
class Argument:
|
||||||
def __init__(self, name, type=type(""), datatype=None, prompt=None, help="",
|
def __init__(self, name, typ=type(""), datatype=None, prompt=None, help="",
|
||||||
default=default.none, load_default=False):
|
default=default.none, load_default=False):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = type
|
self.type = typ
|
||||||
self.datatype = datatype
|
self.datatype = datatype
|
||||||
if prompt is None:
|
if prompt is None:
|
||||||
self.prompt = "%s: " % (name)
|
self.prompt = "%s: " % (name)
|
||||||
|
@ -38,8 +38,8 @@ class Argument:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def ask_for_value(self, method, w, **vargs):
|
def ask_for_value(self, method, w, **vargs):
|
||||||
assert w.application.mini_buffer_is_open() is False, \
|
app = w.application
|
||||||
"Recursive minibuffer antics"
|
assert app.mini_buffer_is_open() is False, "Recursive minibuffer antics"
|
||||||
vargs2 = vargs.copy()
|
vargs2 = vargs.copy()
|
||||||
assert callable(self.default), "default value func must be callable"
|
assert callable(self.default), "default value func must be callable"
|
||||||
if self.load_default:
|
if self.load_default:
|
||||||
|
@ -52,16 +52,16 @@ class Argument:
|
||||||
if d is not None and v == "":
|
if d is not None and v == "":
|
||||||
v = d
|
v = d
|
||||||
vargs2[self.name] = self.coerce_to_type(v)
|
vargs2[self.name] = self.coerce_to_type(v)
|
||||||
w.application.close_mini_buffer()
|
app.close_mini_buffer()
|
||||||
method.execute(w, **vargs2)
|
method.execute(w, **vargs2)
|
||||||
tabber = DATATYPES.get(self.datatype, None)
|
tabber = DATATYPES.get(self.datatype, None)
|
||||||
if d is not None:
|
if d is not None:
|
||||||
p = self.prompt + "(%s) " % (d)
|
p = self.prompt + "(%s) " % (d)
|
||||||
else:
|
else:
|
||||||
p = self.prompt
|
p = self.prompt
|
||||||
w.application.open_mini_buffer(p, return_value, method, tabber)
|
app.open_mini_buffer(p, return_value, method, tabber)
|
||||||
if starting_value:
|
if starting_value:
|
||||||
w.application.mini_buffer.set_data(starting_value)
|
app.mini_buffer.set_data(starting_value)
|
||||||
|
|
||||||
class Method:
|
class Method:
|
||||||
_is_method = True
|
_is_method = True
|
||||||
|
@ -149,7 +149,7 @@ class Search(Method):
|
||||||
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().offset(0, 0)
|
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: ',
|
||||||
|
@ -508,7 +508,6 @@ class InsertSpace(Method):
|
||||||
w.insert_string_at_cursor(' ')
|
w.insert_string_at_cursor(' ')
|
||||||
class InsertTab(Method):
|
class InsertTab(Method):
|
||||||
'''Insert tab into buffer, or tabbify line, depending on mode'''
|
'''Insert tab into buffer, or tabbify line, depending on mode'''
|
||||||
#XYZ
|
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
cursor = w.logical_cursor()
|
cursor = w.logical_cursor()
|
||||||
#i = w.mode.get_indentation_level(cursor.y)
|
#i = w.mode.get_indentation_level(cursor.y)
|
||||||
|
@ -528,8 +527,7 @@ class KillWhitespace(Method):
|
||||||
cursor = w.logical_cursor()
|
cursor = w.logical_cursor()
|
||||||
i = w.buffer.count_leading_whitespace(cursor.y)
|
i = w.buffer.count_leading_whitespace(cursor.y)
|
||||||
if i > 0:
|
if i > 0:
|
||||||
w.kill(Point(0, cursor.y),
|
w.kill(Point(0, cursor.y), Point(i, cursor.y))
|
||||||
Point(i, cursor.y))
|
|
||||||
|
|
||||||
# tabification
|
# tabification
|
||||||
class TabBuffer(Method):
|
class TabBuffer(Method):
|
||||||
|
@ -557,7 +555,7 @@ class CommentRegion(Method):
|
||||||
w.input_line = "Empty kill region"
|
w.input_line = "Empty kill region"
|
||||||
return
|
return
|
||||||
for y in range(p1.y, p2.y):
|
for y in range(p1.y, p2.y):
|
||||||
w.buffer.insert_string_at_cursor(Point(0, y), "#")
|
w.buffer.insert_string(Point(0, y), "#")
|
||||||
class UncommentRegion(Method):
|
class UncommentRegion(Method):
|
||||||
'''Remove a comment from every line in the current buffer'''
|
'''Remove a comment from every line in the current buffer'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
|
@ -573,7 +571,7 @@ class UncommentRegion(Method):
|
||||||
return
|
return
|
||||||
for y in range(p1.y, p2.y):
|
for y in range(p1.y, p2.y):
|
||||||
if w.buffer.lines[y].startswith("#"):
|
if w.buffer.lines[y].startswith("#"):
|
||||||
w.buffer.delete_string(Point(0, y), Point(1, y))
|
w.buffer.delete(Point(0, y), Point(1, y))
|
||||||
|
|
||||||
# wrapping/justifying/etc
|
# wrapping/justifying/etc
|
||||||
class WrapLine(Method):
|
class WrapLine(Method):
|
||||||
|
@ -674,7 +672,7 @@ class JustifyLeft(Method):
|
||||||
return
|
return
|
||||||
if this_line[i] != ' ':
|
if this_line[i] != ' ':
|
||||||
return
|
return
|
||||||
w.buffer.delete_string(Point(i, cursor.y), cursor)
|
w.buffer.delete(Point(i, cursor.y), cursor)
|
||||||
|
|
||||||
# undo/redo
|
# undo/redo
|
||||||
class Undo(Method):
|
class Undo(Method):
|
||||||
|
@ -782,8 +780,8 @@ class UnindentBlock(Method):
|
||||||
for i in range(0, len(lines)):
|
for i in range(0, len(lines)):
|
||||||
if lines[i].startswith(' '):
|
if lines[i].startswith(' '):
|
||||||
lines[i] = lines[i][4:]
|
lines[i] = lines[i][4:]
|
||||||
w.buffer.delete_string(Point(0, p1.y), Point(0, p2.y))
|
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
||||||
w.buffer.insert_string_at_cursor(Point(0, p1.y), '\n'.join(lines) + '\n')
|
w.buffer.insert_string(Point(0, p1.y), '\n'.join(lines) + '\n')
|
||||||
class IndentBlock(Method):
|
class IndentBlock(Method):
|
||||||
'''Add 4 spaces to each line in region'''
|
'''Add 4 spaces to each line in region'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
|
@ -800,8 +798,8 @@ class IndentBlock(Method):
|
||||||
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 range(0, len(lines)):
|
||||||
lines[i] = ' ' + lines[i]
|
lines[i] = ' ' + lines[i]
|
||||||
w.buffer.delete_string(Point(0, p1.y), Point(0, p2.y))
|
w.buffer.delete(Point(0, p1.y), Point(0, p2.y))
|
||||||
w.buffer.insert_string_at_cursor(Point(0, p1.y), '\n'.join(lines) + '\n')
|
w.buffer.insert_string(Point(0, p1.y), '\n'.join(lines) + '\n')
|
||||||
|
|
||||||
class CodeComplete(Method):
|
class CodeComplete(Method):
|
||||||
'''Complete based on tokenized strings'''
|
'''Complete based on tokenized strings'''
|
||||||
|
@ -846,7 +844,7 @@ class CodeComplete(Method):
|
||||||
seen_keys = seen.keys()
|
seen_keys = seen.keys()
|
||||||
num_seen = len(seen_keys)
|
num_seen = len(seen_keys)
|
||||||
if word == sofar:
|
if word == sofar:
|
||||||
#w.application.set_error('No completion possible: %r' % word)
|
w.application.set_error('No completion possible: %r' % word)
|
||||||
pass
|
pass
|
||||||
elif sofar:
|
elif sofar:
|
||||||
w.buffer.delete(p1, p2)
|
w.buffer.delete(p1, p2)
|
||||||
|
@ -856,7 +854,7 @@ class CodeComplete(Method):
|
||||||
else:
|
else:
|
||||||
w.application.set_error('Ambiguous: %r' % seen_keys)
|
w.application.set_error('Ambiguous: %r' % seen_keys)
|
||||||
else:
|
else:
|
||||||
#w.application.set_error('No completion found: %r' % word)
|
w.application.set_error('No completion found: %r' % word)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class OpenConsole(Method):
|
class OpenConsole(Method):
|
||||||
|
|
Loading…
Reference in New Issue