Skip to content

Commit

Permalink
Merge pull request #74 from maralla/relative-filename
Browse files Browse the repository at this point in the history
Make filename completion relative to current file directory
  • Loading branch information
maralla committed Feb 6, 2017
2 parents 8e20217 + a677ae5 commit 8136383
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pythonx/completers/common/filename.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .utils import test_subseq, LIMIT


def find(input_data):
def find(current_dir, input_data):
path_dir = os.path.expanduser(os.path.expandvars(input_data))
if not path_dir:
return []
Expand All @@ -16,6 +16,9 @@ def find(input_data):
if not dirname:
dirname = '.'

if not os.path.isabs(dirname):
dirname = os.path.join(current_dir, dirname)

entries = []
for entry in os.listdir(dirname):
score = test_subseq(basename, entry)
Expand Down Expand Up @@ -68,7 +71,7 @@ def parse(self, base):
if not match:
return []
try:
items = find(match.group())
items = find(self.current_directory, match.group())
except Exception:
return []
return [item[0] for item in items]
2 changes: 2 additions & 0 deletions tests/test_filename.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import os.path
import completor

from completers.common import Filename # noqa
Expand All @@ -9,6 +10,7 @@ def test_get_completions(vim_mod):
filename = completor.get('filename')

vim_mod.vars = {}
vim_mod.funcs['expand'] = lambda _: os.path.join(os.getcwd(), 'tests')
data = list(set([item['menu'] for item in filename.get_completions('./')]))
assert data == ['[F]']

Expand Down

0 comments on commit 8136383

Please sign in to comment.