Skip to content

Commit

Permalink
Fix #109 add g:deoplete#file#enable_buffer_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Dec 30, 2015
1 parent e9f7221 commit 58ab778
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doc/deoplete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ g:deoplete#omni#functions
b:deoplete_omni_functions
Buffer local variable of |g:deoplete#omni#functions|.

*g:deoplete#file#enable_buffer_path*
g:deoplete#file#enable_buffer_path
If it is 1, file source complete the files from the buffer
path instead of the current directory.

Default value: 1

*b:deoplete_file_enable_buffer_path*
b:deoplete_file_enable_buffer_path
Buffer local variable of |g:deoplete#file#enable_buffer_path|.

------------------------------------------------------------------------------
FUNCTIONS *deoplete-functions*

Expand Down
18 changes: 16 additions & 2 deletions rplugin/python3/deoplete/sources/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import re
from os.path import exists, dirname
from .base import Base
from deoplete.util import \
set_default, get_simple_buffer_config


class Source(Base):
Expand All @@ -39,6 +41,8 @@ def __init__(self, vim):
self.mark = '[F]'
self.min_pattern_length = 0

set_default(self.vim, 'g:deoplete#file#enable_buffer_path', 1)

def get_complete_position(self, context):
pos = context['input'].rfind('/')
return pos if pos < 0 else pos + 1
Expand Down Expand Up @@ -72,9 +76,19 @@ def __longest_path_that_exists(self, input_str):
return None

def __substitute_path(self, path):
m = re.match(r'\./', path)
buffer_path = get_simple_buffer_config(
self.vim,
'b:deoplete_file_enable_buffer_path',
'g:deoplete#file#enable_buffer_path')
m = re.match(r'(\.+)/', path)
if m:
return re.sub(r'^\.', self.vim.funcs.getcwd(), path)
h = self.vim.funcs.repeat(':h', len(m.group(1)))
return re.sub(r'^\.+',
self.vim.funcs.fnamemodify(
(self.vim.funcs.bufname('%')
if buffer_path
else self.vim.funcs.getcwd()), ':p' + h),
path)
m = re.match(r'~/', path)
if m and os.environ.get('HOME'):
return re.sub(r'^~', os.environ.get('HOME'), path)
Expand Down

0 comments on commit 58ab778

Please sign in to comment.