parent
607495107e
commit
f4b1044911
|
@ -80,6 +80,9 @@ class Application(object):
|
||||||
}
|
}
|
||||||
self.default_color = ('default', 'default',)
|
self.default_color = ('default', 'default',)
|
||||||
|
|
||||||
|
# xyz
|
||||||
|
self._load_config_defaults()
|
||||||
|
|
||||||
# initialize our colors
|
# initialize our colors
|
||||||
if curses.has_colors():
|
if curses.has_colors():
|
||||||
curses.start_color()
|
curses.start_color()
|
||||||
|
@ -189,15 +192,15 @@ class Application(object):
|
||||||
self.registers = {}
|
self.registers = {}
|
||||||
|
|
||||||
# initialize tab handlers
|
# initialize tab handlers
|
||||||
method.DATATYPES['path'] = completer.FileCompleter()
|
method.DATATYPES['path'] = completer.FileCompleter(self)
|
||||||
method.DATATYPES['buffer'] = completer.BufferCompleter(self)
|
method.DATATYPES['buffer'] = completer.BufferCompleter(self)
|
||||||
method.DATATYPES['command'] = completer.CommandCompleter()
|
method.DATATYPES['command'] = completer.CommandCompleter(self)
|
||||||
method.DATATYPES['shell'] = completer.ShellCompleter()
|
method.DATATYPES['shell'] = completer.ShellCompleter(self)
|
||||||
method.DATATYPES['config'] = completer.ConfigCompleter()
|
method.DATATYPES['config'] = completer.ConfigCompleter(self)
|
||||||
method.DATATYPES['method'] = completer.MethodCompleter()
|
method.DATATYPES['method'] = completer.MethodCompleter(self)
|
||||||
method.DATATYPES['register'] = completer.RegisterCompleter()
|
method.DATATYPES['register'] = completer.RegisterCompleter(self)
|
||||||
method.DATATYPES['mode'] = completer.ModeCompleter()
|
method.DATATYPES['mode'] = completer.ModeCompleter(self)
|
||||||
method.DATATYPES['token'] = completer.TokenCompleter()
|
method.DATATYPES['token'] = completer.TokenCompleter(self)
|
||||||
|
|
||||||
# set up curses
|
# set up curses
|
||||||
self.win = curses.newwin(self.y, self.x, 0, 0)
|
self.win = curses.newwin(self.y, self.x, 0, 0)
|
||||||
|
@ -208,6 +211,9 @@ class Application(object):
|
||||||
curses.nonl()
|
curses.nonl()
|
||||||
curses.def_prog_mode()
|
curses.def_prog_mode()
|
||||||
|
|
||||||
|
def _load_config_defaults(self):
|
||||||
|
self.config['ignore-suffix'] = ['~', '-']
|
||||||
|
|
||||||
def completion_window_is_open(self):
|
def completion_window_is_open(self):
|
||||||
n = self.complete_slot
|
n = self.complete_slot
|
||||||
if n is None:
|
if n is None:
|
||||||
|
|
30
completer.py
30
completer.py
|
@ -18,6 +18,8 @@ def find_common_string(candidates):
|
||||||
return test
|
return test
|
||||||
|
|
||||||
class Completer(object):
|
class Completer(object):
|
||||||
|
def __init__(self, application):
|
||||||
|
self.application = application
|
||||||
def get_candidates(self, s):
|
def get_candidates(self, s):
|
||||||
assert "Not implemented"
|
assert "Not implemented"
|
||||||
def tab_string(self, s, w=None):
|
def tab_string(self, s, w=None):
|
||||||
|
@ -45,6 +47,21 @@ class FileCompleter(Completer):
|
||||||
candidates = [util.expand_tilde(user) for user in users if user.startswith(s)]
|
candidates = [util.expand_tilde(user) for user in users if user.startswith(s)]
|
||||||
else:
|
else:
|
||||||
candidates = glob.glob(s + '*')
|
candidates = glob.glob(s + '*')
|
||||||
|
|
||||||
|
# ignore some suffixes by default, unless the only possible completions
|
||||||
|
# ALL have ignored-suffixes, in which case just return them all.
|
||||||
|
cand2 = []
|
||||||
|
for c in candidates:
|
||||||
|
ok = True
|
||||||
|
for suffix in self.application.config['ignore-suffix']:
|
||||||
|
if c.endswith(suffix):
|
||||||
|
ok = False
|
||||||
|
break
|
||||||
|
if ok:
|
||||||
|
cand2.append(c)
|
||||||
|
if cand2:
|
||||||
|
candidates = cand2
|
||||||
|
|
||||||
for i in range(0, len(candidates)):
|
for i in range(0, len(candidates)):
|
||||||
c = candidates[i]
|
c = candidates[i]
|
||||||
if os.path.isdir(os.path.realpath(c)):
|
if os.path.isdir(os.path.realpath(c)):
|
||||||
|
@ -52,8 +69,6 @@ class FileCompleter(Completer):
|
||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
class BufferCompleter(Completer):
|
class BufferCompleter(Completer):
|
||||||
def __init__(self, application):
|
|
||||||
self.application = application
|
|
||||||
def get_candidates(self, s, w=None):
|
def get_candidates(self, s, w=None):
|
||||||
bl = self.application.bufferlist
|
bl = self.application.bufferlist
|
||||||
candidates = [b.name() for b in bl.buffers if b.name().startswith(s)]
|
candidates = [b.name() for b in bl.buffers if b.name().startswith(s)]
|
||||||
|
@ -77,18 +92,19 @@ class CommandCompleter(Completer):
|
||||||
return candidates
|
return candidates
|
||||||
|
|
||||||
class ShellCompleter(Completer):
|
class ShellCompleter(Completer):
|
||||||
def __init__(self):
|
def __init__(self, application):
|
||||||
self.file_completer = FileCompleter()
|
Completer.__init__(self, application)
|
||||||
self.command_completer = CommandCompleter()
|
self.fc = FileCompleter(application)
|
||||||
|
self.cc = CommandCompleter(application)
|
||||||
def get_candidates(self, s, w=None):
|
def get_candidates(self, s, w=None):
|
||||||
if ' ' in s:
|
if ' ' in s:
|
||||||
i = s.rindex(' ') + 1
|
i = s.rindex(' ') + 1
|
||||||
base = s[:i]
|
base = s[:i]
|
||||||
last = s[i:]
|
last = s[i:]
|
||||||
candidates = self.file_completer.get_candidates(last)
|
candidates = self.fc.get_candidates(last)
|
||||||
return [base + x for x in candidates]
|
return [base + x for x in candidates]
|
||||||
else:
|
else:
|
||||||
return self.command_completer.get_candidates(s)
|
return self.cc.get_candidates(s)
|
||||||
|
|
||||||
class TokenCompleter(Completer):
|
class TokenCompleter(Completer):
|
||||||
def get_candidates(self, s, w=None):
|
def get_candidates(self, s, w=None):
|
||||||
|
|
|
@ -101,7 +101,7 @@ class GetToken(Method):
|
||||||
class TokenComplete(Method):
|
class TokenComplete(Method):
|
||||||
'''Complete token names based on other tokens in the buffer'''
|
'''Complete token names based on other tokens in the buffer'''
|
||||||
_mini_prompt = 'Token Complete'
|
_mini_prompt = 'Token Complete'
|
||||||
_tabber = completer.TokenCompleter()
|
_tabber = completer.TokenCompleter(None)
|
||||||
class Dummy(object): pass
|
class Dummy(object): pass
|
||||||
def _complete(self, s):
|
def _complete(self, s):
|
||||||
dw = self.Dummy()
|
dw = self.Dummy()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import math, os, string
|
import math, os, sets, string
|
||||||
import color, method
|
import color, method
|
||||||
from lex import Lexer
|
from lex import Lexer
|
||||||
from point import Point
|
from point import Point
|
||||||
|
@ -88,9 +88,13 @@ class Fundamental(Handler):
|
||||||
tabber = None
|
tabber = None
|
||||||
context = None
|
context = None
|
||||||
colors = {}
|
colors = {}
|
||||||
config = {}
|
|
||||||
lconfig = {}
|
# config settings installed/modified by the mode
|
||||||
dconfig = {}
|
config = {}
|
||||||
|
dconfig = {}
|
||||||
|
lconfig = {}
|
||||||
|
sconfig = {}
|
||||||
|
|
||||||
actions = []
|
actions = []
|
||||||
completers = {}
|
completers = {}
|
||||||
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s"
|
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s"
|
||||||
|
@ -110,8 +114,23 @@ class Fundamental(Handler):
|
||||||
raise Exception, s
|
raise Exception, s
|
||||||
else:
|
else:
|
||||||
app.token_colors[key] = val
|
app.token_colors[key] = val
|
||||||
|
|
||||||
|
# install configuration stuff
|
||||||
for (key, val) in cls.config.iteritems():
|
for (key, val) in cls.config.iteritems():
|
||||||
|
assert key not in app.config, "uh oh: %r" % key
|
||||||
app.config[key] = val
|
app.config[key] = val
|
||||||
|
for (key, val) in cls.lconfig.iteritems():
|
||||||
|
app.config.setdefault(key, [])
|
||||||
|
for val2 in val:
|
||||||
|
app.config[key].append(val2)
|
||||||
|
for (key, val) in cls.sconfig.iteritems():
|
||||||
|
app.config.setdefault(key, sets.Set())
|
||||||
|
app.config[key].add(val)
|
||||||
|
for (key, d) in cls.dconfig.iteritems():
|
||||||
|
app.config.setdefault(key, {})
|
||||||
|
for (subkey, val) in d.iteritems():
|
||||||
|
app.config[key][subkey] = val
|
||||||
|
|
||||||
for mcls in cls.actions:
|
for mcls in cls.actions:
|
||||||
m = mcls()
|
m = mcls()
|
||||||
if m.name in app.methods:
|
if m.name in app.methods:
|
||||||
|
|
|
@ -185,6 +185,9 @@ class C(mode.Fundamental):
|
||||||
'c.make-cmd': "make",
|
'c.make-cmd': "make",
|
||||||
'c.make-rel-dir': True,
|
'c.make-rel-dir': True,
|
||||||
}
|
}
|
||||||
|
lconfig = {
|
||||||
|
'ignore-suffix': ['.o'],
|
||||||
|
}
|
||||||
actions = [CCheckSyntax, CMake]
|
actions = [CCheckSyntax, CMake]
|
||||||
|
|
||||||
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
|
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
|
||||||
|
|
|
@ -715,7 +715,7 @@ class Perl(mode.Fundamental):
|
||||||
PerlListFunctions, PerlOpenModule, PerlOpenModuleWord,
|
PerlListFunctions, PerlOpenModule, PerlOpenModuleWord,
|
||||||
PerlSemanticComplete]
|
PerlSemanticComplete]
|
||||||
completers = {
|
completers = {
|
||||||
'perlfunction': PerlFunctionCompleter(),
|
'perlfunction': PerlFunctionCompleter(None),
|
||||||
}
|
}
|
||||||
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
|
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
|
||||||
#format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s"
|
#format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s"
|
||||||
|
|
|
@ -497,14 +497,17 @@ class Python(mode.Fundamental):
|
||||||
config = {
|
config = {
|
||||||
'python.lib': '.',
|
'python.lib': '.',
|
||||||
}
|
}
|
||||||
|
lconfig = {
|
||||||
|
'ignore-suffix': ['.pyc'],
|
||||||
|
}
|
||||||
actions = [PythonInitNames, PythonListNames, PythonGotoName,
|
actions = [PythonInitNames, PythonListNames, PythonGotoName,
|
||||||
PythonGotoFunction, PythonGotoClass, PythonCheckSyntax,
|
PythonGotoFunction, PythonGotoClass, PythonCheckSyntax,
|
||||||
PythonDictCleanup, PythonSemanticComplete,
|
PythonDictCleanup, PythonSemanticComplete,
|
||||||
PythonInsertTripleSquotes, PythonInsertTripleDquotes]
|
PythonInsertTripleSquotes, PythonInsertTripleDquotes]
|
||||||
completers = {
|
completers = {
|
||||||
"pythonname": PythonNameCompleter(),
|
"pythonname": PythonNameCompleter(None),
|
||||||
"pythonfunction": PythonFunctionCompleter(),
|
"pythonfunction": PythonFunctionCompleter(None),
|
||||||
"pythonclass": PythonClassCompleter(),
|
"pythonclass": PythonClassCompleter(None),
|
||||||
}
|
}
|
||||||
|
|
||||||
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s]"
|
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s]"
|
||||||
|
|
Loading…
Reference in New Issue