parent
5f99e1f8fb
commit
7fc0d762d7
|
@ -194,6 +194,7 @@ class Application(object):
|
|||
method.DATATYPES['method'] = completer.MethodCompleter()
|
||||
method.DATATYPES['register'] = completer.RegisterCompleter()
|
||||
method.DATATYPES['mode'] = completer.ModeCompleter()
|
||||
method.DATATYPES['token'] = completer.TokenCompleter()
|
||||
|
||||
# set up curses
|
||||
self.win = curses.newwin(self.y, self.x, 0, 0)
|
||||
|
@ -245,7 +246,7 @@ class Application(object):
|
|||
|
||||
# NOTE: this is not an optimal packing, but it's fast and easy to
|
||||
# understand. i encourage someone else to write something better.
|
||||
numcols = self.bufferlist.slots[n].width // (maxlen + 2)
|
||||
numcols = max(self.bufferlist.slots[n].width // (maxlen + 2), 1)
|
||||
numrows = clen - ((clen // numcols) * (numcols - 1))
|
||||
for i in range(0, numrows):
|
||||
names = []
|
||||
|
@ -387,7 +388,8 @@ class Application(object):
|
|||
return self.mini_buffer
|
||||
def mini_buffer_is_open(self):
|
||||
return self.mini_buffer is not None
|
||||
def open_mini_buffer(self, prompt, callback, method=None, tabber=None, modename=None):
|
||||
def open_mini_buffer(self, prompt, callback, method=None, tabber=None,
|
||||
modename=None, startvalue=None):
|
||||
if self.mini_buffer_is_open():
|
||||
self.close_mini_buffer()
|
||||
self.mini_prompt = prompt
|
||||
|
@ -395,6 +397,8 @@ class Application(object):
|
|||
try:
|
||||
w = self.x - 1 - len(self.mini_prompt) - 1
|
||||
window.Window(self.mini_buffer, self, height=1, width=w)
|
||||
if startvalue:
|
||||
self.mini_buffer.set_data(startvalue)
|
||||
self.mini_active = True
|
||||
except minibuffer.MiniBufferError:
|
||||
self.mini_buffer = None
|
||||
|
|
14
completer.py
14
completer.py
|
@ -90,6 +90,20 @@ class ShellCompleter(Completer):
|
|||
else:
|
||||
return self.command_completer.get_candidates(s)
|
||||
|
||||
class TokenCompleter(Completer):
|
||||
def get_candidates(self, s, w=None):
|
||||
w2 = w.buffer.method.old_window
|
||||
t = w2.get_token2()
|
||||
h = w2.get_highlighter()
|
||||
candidates = {}
|
||||
for line in h.tokens:
|
||||
for t2 in line:
|
||||
if t2 is t:
|
||||
continue
|
||||
elif t2.string.startswith(s):
|
||||
candidates[t2.string] = 1
|
||||
return candidates.keys()
|
||||
|
||||
class MethodCompleter(Completer):
|
||||
def get_candidates(self, s, w=None):
|
||||
return [n for n in w.application.methods if n.startswith(s)]
|
||||
|
|
|
@ -68,9 +68,8 @@ class Argument(object):
|
|||
p = self.prompt + "(%s) " % (d)
|
||||
else:
|
||||
p = self.prompt
|
||||
app.open_mini_buffer(p, return_value, method, tabber)
|
||||
if starting_value:
|
||||
app.mini_buffer.set_data(starting_value)
|
||||
app.open_mini_buffer(p, return_value, method=method, tabber=tabber,
|
||||
startvalue=starting_value)
|
||||
|
||||
class Method(object):
|
||||
_is_method = True
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import os, commands, re, sets, tempfile
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
|
||||
import buffer, default, dirutil, regex, util, window
|
||||
import buffer, completer, default, dirutil, regex, util, window
|
||||
import mode.mini
|
||||
from point import Point
|
||||
|
||||
|
@ -82,7 +82,7 @@ class GetToken(Method):
|
|||
else:
|
||||
w.set_error('Token: %r (%s)' % (token.string, token.fqname()))
|
||||
|
||||
class TokenComplete(Method):
|
||||
class TokenComplete2(Method):
|
||||
'''Complete token names based on other tokens in the buffer'''
|
||||
def _prune_candidates(self, t, minlen, candidates):
|
||||
if not candidates:
|
||||
|
@ -131,7 +131,6 @@ class TokenComplete(Method):
|
|||
w.buffer.delete(p1, p2)
|
||||
w.insert_string(p1, result)
|
||||
|
||||
#mode.mini.use_completion_window(w.application, result, candidates)
|
||||
if not candidates:
|
||||
w.set_error("No completion: %r" % result)
|
||||
elif len(candidates) == 1:
|
||||
|
@ -141,6 +140,43 @@ class TokenComplete(Method):
|
|||
else:
|
||||
w.set_error("Partial completion: %r" % candidates)
|
||||
|
||||
|
||||
class TokenComplete(Method):
|
||||
'''Complete token names based on other tokens in the buffer'''
|
||||
def _execute(self, w, **vargs):
|
||||
self.old_window = w
|
||||
tabber = completer.TokenCompleter()
|
||||
t = w.get_token2()
|
||||
if t is None:
|
||||
w.set_error("No token to complete!")
|
||||
return
|
||||
elif regex.reserved_token_names.match(t.name):
|
||||
w.set_error("Will not complete reserved token")
|
||||
return
|
||||
|
||||
class Dummy(object): pass
|
||||
dw = Dummy()
|
||||
dw.buffer = Dummy()
|
||||
dw.buffer.method = self
|
||||
(s2, exists, complete) = tabber.tab_string(t.string, dw)
|
||||
|
||||
p1 = Point(t.x, t.y)
|
||||
p2 = Point(t.end_x(), t.y)
|
||||
def callback(s):
|
||||
w.buffer.delete(p1, p2)
|
||||
w.insert_string(p1, s)
|
||||
w.application.close_mini_buffer()
|
||||
|
||||
if exists and complete:
|
||||
w.set_error("Unique completion: %r" % s2)
|
||||
callback(s2)
|
||||
return
|
||||
else:
|
||||
if exists:
|
||||
pass
|
||||
w.application.open_mini_buffer("Foog: ", callback, method=self,
|
||||
tabber=tabber, startvalue=s2)
|
||||
|
||||
class OpenConsole(Method):
|
||||
'''Evaluate python expressions (for advanced use and debugging only)'''
|
||||
def execute(self, w, **vargs):
|
||||
|
|
46
mode/perl.py
46
mode/perl.py
|
@ -117,10 +117,11 @@ class PerlGrammar(Grammar):
|
|||
RegionRule(r'quoted', r'qw? *(?P<delim>[^ #])', Grammar, r'%(delim)s'),
|
||||
|
||||
PatternRule(r'perl_function', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?= *\()"),
|
||||
PatternRule(r'perl_namespace', r"(?:[a-zA-Z_][a-zA-Z_0-9]*\:\:)+(?:[a-zA-Z_][a-zA-Z_0-9]*)?"),
|
||||
PatternRule(r'perl_class', r"(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*(?=->)"),
|
||||
|
||||
# some basic stuff
|
||||
PatternRule(r'delimiter', r"->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"),
|
||||
PatternRule(r'delimiter', r"::|->|=>|(?<!:):(?!=:)|[,;=\?(){}\[\]\(\)]"),
|
||||
PatternRule(r'operator', r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
||||
PatternRule(r'operator', r"\+\+|\+|<=>|<>|<<|<=|<|-|>>|>=|>|\*\*|\*|&&|&|\|\||\||/|\^|==|//|~|=~|!~|!=|%|!|\.|x(?![a-zA-Z_])"),
|
||||
PatternRule(r'noperator', r"(?:xor|or|not|ne|lt|le|gt|ge|eq|cmp|and)(?![a-zA-Z_])"),
|
||||
|
@ -610,27 +611,28 @@ class Perl(mode.Fundamental):
|
|||
'pod.end': ('red', 'default', 'bold'),
|
||||
|
||||
# basic stuff
|
||||
'escaped': ('magenta', 'default', 'bold'),
|
||||
'null': ('default', 'default', 'bold'),
|
||||
'sub': ('cyan', 'default', 'bold'),
|
||||
'prototype': ('magenta', 'default', 'bold'),
|
||||
'operator': ('default', 'default', 'bold'),
|
||||
'noperator': ('magenta', 'default', 'bold'),
|
||||
'endblock': ('red', 'default', 'bold'),
|
||||
'perl_keyword': ('magenta', 'default', 'bold'),
|
||||
'cast': ('yellow', 'default', 'bold'),
|
||||
'scalar': ('yellow', 'default', 'bold'),
|
||||
'array': ('yellow', 'default', 'bold'),
|
||||
'deref': ('yellow', 'default', 'bold'),
|
||||
'perl_hash': ('yellow', 'default', 'bold'),
|
||||
'hash_key': ('green', 'default', 'bold'),
|
||||
'perl_function': ('cyan', 'default', 'bold'),
|
||||
'perl_builtin': ('magenta', 'default', 'bold'),
|
||||
'perl_label': ('cyan', 'default', 'bold'),
|
||||
'package': ('cyan', 'default', 'bold'),
|
||||
'perl_class': ('cyan', 'default', 'bold'),
|
||||
'use': ('cyan', 'default', 'bold'),
|
||||
'require': ('cyan', 'default', 'bold'),
|
||||
'escaped': ('magenta', 'default', 'bold'),
|
||||
'null': ('default', 'default', 'bold'),
|
||||
'sub': ('cyan', 'default', 'bold'),
|
||||
'prototype': ('magenta', 'default', 'bold'),
|
||||
'operator': ('default', 'default', 'bold'),
|
||||
'noperator': ('magenta', 'default', 'bold'),
|
||||
'endblock': ('red', 'default', 'bold'),
|
||||
'perl_keyword': ('magenta', 'default', 'bold'),
|
||||
'cast': ('yellow', 'default', 'bold'),
|
||||
'scalar': ('yellow', 'default', 'bold'),
|
||||
'array': ('yellow', 'default', 'bold'),
|
||||
'deref': ('yellow', 'default', 'bold'),
|
||||
'perl_hash': ('yellow', 'default', 'bold'),
|
||||
'hash_key': ('green', 'default', 'bold'),
|
||||
'perl_function': ('cyan', 'default', 'bold'),
|
||||
'perl_namespace': ('cyan', 'default', 'bold'),
|
||||
'perl_builtin': ('magenta', 'default', 'bold'),
|
||||
'perl_label': ('cyan', 'default', 'bold'),
|
||||
'package': ('cyan', 'default', 'bold'),
|
||||
'perl_class': ('cyan', 'default', 'bold'),
|
||||
'use': ('cyan', 'default', 'bold'),
|
||||
'require': ('cyan', 'default', 'bold'),
|
||||
|
||||
# heredoc/evaldoc
|
||||
'heredoc.start': ('green', 'default', 'bold'),
|
||||
|
|
Loading…
Reference in New Issue