better filename completion

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-12-10 05:54:53 +00:00
parent 2ab43f264f
commit e67dc42f02
3 changed files with 5 additions and 14 deletions

View File

@ -51,12 +51,7 @@ class Completer(object):
class FileCompleter(Completer): class FileCompleter(Completer):
def get_candidates(self, s, w=None): def get_candidates(self, s, w=None):
s = util.expand_tilde(s) s = util.expand_tilde(s)
if s.startswith('~'): candidates = [util.normal_path(p) for p in glob.glob(s + '*')]
users = ['~%s' % (x[0]) for x in pwd.getpwall()]
candidates = [util.expand_tilde(user) for user in users if user.startswith(s)]
else:
candidates = glob.glob(s + '*')
candidates = [util.normal_path(p) for p in candidates]
# ignore some suffixes by default, unless the only possible completions # ignore some suffixes by default, unless the only possible completions
# ALL have ignored-suffixes, in which case just return them all. # ALL have ignored-suffixes, in which case just return them all.
@ -69,13 +64,9 @@ class FileCompleter(Completer):
break break
if ok: if ok:
candidates2.append(c) candidates2.append(c)
if candidates2: if candidates2:
candidates = candidates2 candidates = candidates2
for i in range(0, len(candidates)):
c = candidates[i]
if os.path.isdir(os.path.realpath(c)):
candidates[i] = c + '/'
return candidates return candidates
class BufferCompleter(Completer): class BufferCompleter(Completer):

View File

@ -31,8 +31,7 @@ def current_working_dir(w):
def path_dirname(w): def path_dirname(w):
if hasattr(w.buffer, 'path'): if hasattr(w.buffer, 'path'):
path = os.path.dirname(w.buffer.path) return util.normal_path(os.path.dirname(w.buffer.path))
return util.normal_path(path) + '/'
else: else:
return current_working_dir(w) return current_working_dir(w)

View File

@ -3,9 +3,10 @@ import os, pwd, regex
def normal_path(path): def normal_path(path):
path = os.path.realpath(path) path = os.path.realpath(path)
home = os.getenv('HOME') home = os.getenv('HOME')
isdir = os.path.isdir(path)
if path.startswith(home): if path.startswith(home):
path = path.replace(home, '~', 1) path = path.replace(home, '~', 1)
if os.path.isdir(path): if isdir and not path.endswith('/'):
return path + '/' return path + '/'
else: else:
return path return path