mirror of
https://github.com/junegunn/fzf.vim.git
synced 2026-08-12 19:06:54 +08:00
@@ -131,8 +131,9 @@ following exceptions:
|
|||||||
|
|
||||||
- `reducer` (funcref)
|
- `reducer` (funcref)
|
||||||
- Reducer transforms the output lines of fzf into a single string value
|
- Reducer transforms the output lines of fzf into a single string value
|
||||||
- `prefix` (string; default: `\k*$`)
|
- `prefix` (string or funcref; default: `\k*$`)
|
||||||
- Regular expression pattern to extract the completion prefix
|
- Regular expression pattern to extract the completion prefix
|
||||||
|
- Or a function to extract completion prefix
|
||||||
- Both `source` and `options` can be given as funcrefs that take the
|
- Both `source` and `options` can be given as funcrefs that take the
|
||||||
completion prefix as the argument and return the final value
|
completion prefix as the argument and return the final value
|
||||||
- `sink` or `sink*` are not allowed
|
- `sink` or `sink*` are not allowed
|
||||||
|
|||||||
+11
-3
@@ -672,9 +672,17 @@ function! fzf#vim#complete(...)
|
|||||||
let s:eol = col('.') == eol
|
let s:eol = col('.') == eol
|
||||||
let &ve = ve
|
let &ve = ve
|
||||||
|
|
||||||
let prefix = s:pluck(s:opts, 'prefix', '\k*$')
|
let Prefix = s:pluck(s:opts, 'prefix', '\k*$')
|
||||||
let s:query = col('.') == 1 ? '' :
|
if col('.') == 1
|
||||||
\ matchstr(getline('.')[0 : col('.')-2], prefix)
|
let s:query = ''
|
||||||
|
else
|
||||||
|
let full_prefix = getline('.')[0 : col('.')-2]
|
||||||
|
if type(Prefix) == s:TYPE.funcref
|
||||||
|
let s:query = call(Prefix, [full_prefix])
|
||||||
|
else
|
||||||
|
let s:query = matchstr(full_prefix, Prefix)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
let s:opts = s:eval(s:opts, 'source', s:query)
|
let s:opts = s:eval(s:opts, 'source', s:query)
|
||||||
let s:opts = s:eval(s:opts, 'options', s:query)
|
let s:opts = s:eval(s:opts, 'options', s:query)
|
||||||
|
|
||||||
|
|||||||
@@ -58,34 +58,54 @@ function! s:file_options(prefix)
|
|||||||
return printf('--prompt %s --query %s', shellescape(head), shellescape(tail))
|
return printf('--prompt %s --query %s', shellescape(head), shellescape(tail))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:fname_regex()
|
function! s:fname_prefix(str)
|
||||||
let isf = &isfname
|
let isf = &isfname
|
||||||
let pats = []
|
let white = []
|
||||||
|
let black = []
|
||||||
if isf =~ ',,,'
|
if isf =~ ',,,'
|
||||||
call add(pats, ',')
|
call add(white, ',')
|
||||||
let isf = substitute(isf, ',,,', ',', 'g')
|
let isf = substitute(isf, ',,,', ',', 'g')
|
||||||
endif
|
endif
|
||||||
|
if isf =~ ',^,,'
|
||||||
|
call add(black, ',')
|
||||||
|
let isf = substitute(isf, ',^,,', ',', 'g')
|
||||||
|
endif
|
||||||
|
|
||||||
for token in split(isf, ',')
|
for token in split(isf, ',')
|
||||||
if token =~ '[0-9]\+-[0-9]\+'
|
let target = white
|
||||||
let range = map(split(token, '-'), 'str2nr(v:val)')
|
if token[0] == '^'
|
||||||
for i in range(range[0], range[1])
|
let target = black
|
||||||
call add(pats, nr2char(i))
|
let token = token[1:]
|
||||||
endfor
|
endif
|
||||||
|
|
||||||
|
let ends = matchlist(token, '\(.\+\)-\(.\+\)')
|
||||||
|
if empty(ends)
|
||||||
|
call add(target, token)
|
||||||
else
|
else
|
||||||
call add(pats, token)
|
let ends = map(ends[1:2], "len(v:val) == 1 ? char2nr(v:val) : str2nr(v:val)")
|
||||||
|
for i in range(ends[0], ends[1])
|
||||||
|
call add(target, nr2char(i))
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
let pattern = escape(join(pats, ''), ']')
|
|
||||||
if pattern =~ '-'
|
let prefix = a:str
|
||||||
let pattern = substitute(pattern, '-', '', 'g').'-'
|
for offset in range(1, len(a:str))
|
||||||
endif
|
let char = a:str[len(a:str) - offset]
|
||||||
return '[\w'.pattern.']'
|
if (char =~ '\w' || index(white, char) >= 0) && index(black, char) < 0
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
let prefix = strpart(a:str, len(a:str) - offset + 1)
|
||||||
|
break
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return prefix
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:complete_file(command, extra_opts)
|
function! s:complete_file(command, extra_opts)
|
||||||
let s:file_cmd = a:command
|
let s:file_cmd = a:command
|
||||||
return fzf#vim#complete(extend({
|
return fzf#vim#complete(extend({
|
||||||
\ 'prefix': s:fname_regex().'*$',
|
\ 'prefix': function('s:fname_prefix'),
|
||||||
\ 'source': function('s:file_source'),
|
\ 'source': function('s:file_source'),
|
||||||
\ 'options': function('s:file_options')}, get(a:extra_opts, 0, g:fzf#vim#default_layout)))
|
\ 'options': function('s:file_options')}, get(a:extra_opts, 0, g:fzf#vim#default_layout)))
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user