ignore-suffix for opening files

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-10-15 21:17:16 +00:00
parent 607495107e
commit f4b1044911
7 changed files with 71 additions and 24 deletions

View File

@ -80,6 +80,9 @@ class Application(object):
}
self.default_color = ('default', 'default',)
# xyz
self._load_config_defaults()
# initialize our colors
if curses.has_colors():
curses.start_color()
@ -189,15 +192,15 @@ class Application(object):
self.registers = {}
# initialize tab handlers
method.DATATYPES['path'] = completer.FileCompleter()
method.DATATYPES['path'] = completer.FileCompleter(self)
method.DATATYPES['buffer'] = completer.BufferCompleter(self)
method.DATATYPES['command'] = completer.CommandCompleter()
method.DATATYPES['shell'] = completer.ShellCompleter()
method.DATATYPES['config'] = completer.ConfigCompleter()
method.DATATYPES['method'] = completer.MethodCompleter()
method.DATATYPES['register'] = completer.RegisterCompleter()
method.DATATYPES['mode'] = completer.ModeCompleter()
method.DATATYPES['token'] = completer.TokenCompleter()
method.DATATYPES['command'] = completer.CommandCompleter(self)
method.DATATYPES['shell'] = completer.ShellCompleter(self)
method.DATATYPES['config'] = completer.ConfigCompleter(self)
method.DATATYPES['method'] = completer.MethodCompleter(self)
method.DATATYPES['register'] = completer.RegisterCompleter(self)
method.DATATYPES['mode'] = completer.ModeCompleter(self)
method.DATATYPES['token'] = completer.TokenCompleter(self)
# set up curses
self.win = curses.newwin(self.y, self.x, 0, 0)
@ -208,6 +211,9 @@ class Application(object):
curses.nonl()
curses.def_prog_mode()
def _load_config_defaults(self):
self.config['ignore-suffix'] = ['~', '-']
def completion_window_is_open(self):
n = self.complete_slot
if n is None:

View File

@ -18,6 +18,8 @@ def find_common_string(candidates):
return test
class Completer(object):
def __init__(self, application):
self.application = application
def get_candidates(self, s):
assert "Not implemented"
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)]
else:
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)):
c = candidates[i]
if os.path.isdir(os.path.realpath(c)):
@ -52,8 +69,6 @@ class FileCompleter(Completer):
return candidates
class BufferCompleter(Completer):
def __init__(self, application):
self.application = application
def get_candidates(self, s, w=None):
bl = self.application.bufferlist
candidates = [b.name() for b in bl.buffers if b.name().startswith(s)]
@ -77,18 +92,19 @@ class CommandCompleter(Completer):
return candidates
class ShellCompleter(Completer):
def __init__(self):
self.file_completer = FileCompleter()
self.command_completer = CommandCompleter()
def __init__(self, application):
Completer.__init__(self, application)
self.fc = FileCompleter(application)
self.cc = CommandCompleter(application)
def get_candidates(self, s, w=None):
if ' ' in s:
i = s.rindex(' ') + 1
base = 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]
else:
return self.command_completer.get_candidates(s)
return self.cc.get_candidates(s)
class TokenCompleter(Completer):
def get_candidates(self, s, w=None):

View File

@ -101,7 +101,7 @@ class GetToken(Method):
class TokenComplete(Method):
'''Complete token names based on other tokens in the buffer'''
_mini_prompt = 'Token Complete'
_tabber = completer.TokenCompleter()
_tabber = completer.TokenCompleter(None)
class Dummy(object): pass
def _complete(self, s):
dw = self.Dummy()

View File

@ -1,4 +1,4 @@
import math, os, string
import math, os, sets, string
import color, method
from lex import Lexer
from point import Point
@ -88,9 +88,13 @@ class Fundamental(Handler):
tabber = None
context = None
colors = {}
# config settings installed/modified by the mode
config = {}
lconfig = {}
dconfig = {}
lconfig = {}
sconfig = {}
actions = []
completers = {}
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
else:
app.token_colors[key] = val
# install configuration stuff
for (key, val) in cls.config.iteritems():
assert key not in app.config, "uh oh: %r" % key
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:
m = mcls()
if m.name in app.methods:

View File

@ -185,6 +185,9 @@ class C(mode.Fundamental):
'c.make-cmd': "make",
'c.make-rel-dir': True,
}
lconfig = {
'ignore-suffix': ['.o'],
}
actions = [CCheckSyntax, CMake]
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"

View File

@ -715,7 +715,7 @@ class Perl(mode.Fundamental):
PerlListFunctions, PerlOpenModule, PerlOpenModuleWord,
PerlSemanticComplete]
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) %(cursor)s/%(mark)s %(perc)s"

View File

@ -497,14 +497,17 @@ class Python(mode.Fundamental):
config = {
'python.lib': '.',
}
lconfig = {
'ignore-suffix': ['.pyc'],
}
actions = [PythonInitNames, PythonListNames, PythonGotoName,
PythonGotoFunction, PythonGotoClass, PythonCheckSyntax,
PythonDictCleanup, PythonSemanticComplete,
PythonInsertTripleSquotes, PythonInsertTripleDquotes]
completers = {
"pythonname": PythonNameCompleter(),
"pythonfunction": PythonFunctionCompleter(),
"pythonclass": PythonClassCompleter(),
"pythonname": PythonNameCompleter(None),
"pythonfunction": PythonFunctionCompleter(None),
"pythonclass": PythonClassCompleter(None),
}
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s]"