branch : pmacs2
This commit is contained in:
moculus 2007-10-22 00:19:47 +00:00
parent ea3426f235
commit e1ad655912
2 changed files with 1 additions and 58 deletions

View File

@ -874,62 +874,6 @@ class IndentBlock(Method):
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')
class CodeComplete(Method):
'''Complete based on tokenized strings'''
def execute(self, w, **vargs):
cursor = w.logical_cursor()
if len(w.buffer.lines[cursor.y]) == 0:
return
bounds = w.get_word_bounds()
if bounds is None:
return
(p1, p2) = bounds
buffer = w.buffer
word = buffer.get_substring(p1, p2)
app = w.application
highlighter = buffer.highlights[w.mode.name()]
tokens = highlighter.tokens
seen = {}
sofar = None
for group in tokens:
for token in group:
s = token.string
if s == word:
continue
elif s.startswith(word):
seen[s] = True
if sofar is None:
sofar = s
else:
l = min(len(s), len(sofar))
i = len(word)
while i < l:
if s[i] == sofar[i]:
i += 1
else:
break
sofar = s[:i]
seen_keys = seen.keys()
num_seen = len(seen_keys)
if word == sofar:
w.application.set_error('No completion possible: %r' % word)
pass
elif sofar:
w.buffer.delete(p1, p2)
w.buffer.insert_string(p1, sofar)
if num_seen == 1:
w.application.set_error('Unique!')
else:
w.application.set_error('Ambiguous: %r' % seen_keys)
else:
w.application.set_error('No completion found: %r' % word)
pass
class OpenConsole(Method): class OpenConsole(Method):
'''Evaluate python expressions (for advanced use and debugging only)''' '''Evaluate python expressions (for advanced use and debugging only)'''
def execute(self, w, **vargs): def execute(self, w, **vargs):

View File

@ -166,7 +166,7 @@ class Fundamental(Handler):
self.add_bindings('justify-left', ('C-c b',)) self.add_bindings('justify-left', ('C-c b',))
self.add_bindings('indent-block', ('C-c >',)) self.add_bindings('indent-block', ('C-c >',))
self.add_bindings('unindent-block', ('C-c <',)) self.add_bindings('unindent-block', ('C-c <',))
self.add_bindings('code-complete', ('M-c',)) self.add_bindings('token-complete', ('M-c', 'C-c c'))
self.add_bindings('shell-cmd', ('C-c !',)) self.add_bindings('shell-cmd', ('C-c !',))
self.add_bindings('open-aes-file', ('C-c a',)) self.add_bindings('open-aes-file', ('C-c a',))
self.add_bindings('open-console', ('M-e',)) self.add_bindings('open-console', ('M-e',))
@ -179,7 +179,6 @@ class Fundamental(Handler):
self.add_bindings('grep', ('C-c g',)) self.add_bindings('grep', ('C-c g',))
self.add_bindings('pipe', ('C-c p',)) self.add_bindings('pipe', ('C-c p',))
self.add_bindings('view-buffer-parent', ('C-c .',)) self.add_bindings('view-buffer-parent', ('C-c .',))
self.add_bindings('token-complete', ('C-c c',))
# unbound actions # unbound actions
self.add_action(method.GetToken()) self.add_action(method.GetToken())