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):
def get_candidates(self, s, w=None):
s = util.expand_tilde(s)
if s.startswith('~'):
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]
candidates = [util.normal_path(p) for p in glob.glob(s + '*')]
# ignore some suffixes by default, unless the only possible completions
# ALL have ignored-suffixes, in which case just return them all.
@ -69,13 +64,9 @@ class FileCompleter(Completer):
break
if ok:
candidates2.append(c)
if 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
class BufferCompleter(Completer):

View File

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

View File

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