2015-09-06 00:58:45 +09:00
|
|
|
" Copyright (c) 2015 Junegunn Choi
|
|
|
|
"
|
|
|
|
" MIT License
|
|
|
|
"
|
|
|
|
" Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
" a copy of this software and associated documentation files (the
|
|
|
|
" "Software"), to deal in the Software without restriction, including
|
|
|
|
" without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
" distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
" permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
" the following conditions:
|
|
|
|
"
|
|
|
|
" The above copyright notice and this permission notice shall be
|
|
|
|
" included in all copies or substantial portions of the Software.
|
|
|
|
"
|
|
|
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
let s:cpo_save = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
function! fzf#vim#complete#word(...)
|
|
|
|
return fzf#vim#complete(extend({
|
|
|
|
\ 'source': 'cat /usr/share/dict/words'},
|
|
|
|
\ get(a:000, 0, g:fzf#vim#default_layout)))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" ----------------------------------------------------------------------------
|
|
|
|
" <plug>(fzf-complete-path)
|
|
|
|
" <plug>(fzf-complete-file)
|
|
|
|
" <plug>(fzf-complete-file-ag)
|
|
|
|
" ----------------------------------------------------------------------------
|
|
|
|
function! s:file_split_prefix(prefix)
|
|
|
|
let expanded = expand(a:prefix)
|
|
|
|
return isdirectory(expanded) ?
|
|
|
|
\ [expanded,
|
|
|
|
\ substitute(a:prefix, '/*$', '/', ''),
|
|
|
|
\ ''] :
|
|
|
|
\ [fnamemodify(expanded, ':h'),
|
|
|
|
\ substitute(fnamemodify(a:prefix, ':h'), '/*$', '/', ''),
|
|
|
|
\ fnamemodify(expanded, ':t')]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:file_source(prefix)
|
|
|
|
let [dir, head, tail] = s:file_split_prefix(a:prefix)
|
|
|
|
return printf(
|
|
|
|
\ "cd %s && ".s:file_cmd." | sed 's:^:%s:'",
|
|
|
|
\ shellescape(dir), empty(a:prefix) || a:prefix == tail ? '' : head)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:file_options(prefix)
|
|
|
|
let [_, head, tail] = s:file_split_prefix(a:prefix)
|
|
|
|
return printf('--prompt %s --query %s', shellescape(head), shellescape(tail))
|
|
|
|
endfunction
|
|
|
|
|
2015-09-11 12:01:14 +09:00
|
|
|
function! s:fname_prefix(str)
|
2015-09-11 11:03:43 +09:00
|
|
|
let isf = &isfname
|
2015-09-11 12:01:14 +09:00
|
|
|
let white = []
|
|
|
|
let black = []
|
2015-09-11 11:03:43 +09:00
|
|
|
if isf =~ ',,,'
|
2015-09-11 12:01:14 +09:00
|
|
|
call add(white, ',')
|
2015-09-11 11:03:43 +09:00
|
|
|
let isf = substitute(isf, ',,,', ',', 'g')
|
|
|
|
endif
|
2015-09-11 12:01:14 +09:00
|
|
|
if isf =~ ',^,,'
|
|
|
|
call add(black, ',')
|
|
|
|
let isf = substitute(isf, ',^,,', ',', 'g')
|
|
|
|
endif
|
|
|
|
|
2015-09-11 11:03:43 +09:00
|
|
|
for token in split(isf, ',')
|
2015-09-11 12:01:14 +09:00
|
|
|
let target = white
|
|
|
|
if token[0] == '^'
|
|
|
|
let target = black
|
|
|
|
let token = token[1:]
|
|
|
|
endif
|
|
|
|
|
|
|
|
let ends = matchlist(token, '\(.\+\)-\(.\+\)')
|
|
|
|
if empty(ends)
|
|
|
|
call add(target, token)
|
2015-09-11 11:03:43 +09:00
|
|
|
else
|
2015-09-11 12:01:14 +09:00
|
|
|
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
|
2015-09-11 11:03:43 +09:00
|
|
|
endif
|
|
|
|
endfor
|
2015-09-11 12:01:14 +09:00
|
|
|
|
|
|
|
let prefix = a:str
|
|
|
|
for offset in range(1, len(a:str))
|
|
|
|
let char = a:str[len(a:str) - offset]
|
|
|
|
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
|
2015-09-11 11:03:43 +09:00
|
|
|
endfunction
|
|
|
|
|
2015-09-12 02:52:43 +09:00
|
|
|
function! fzf#vim#complete#path(command, ...)
|
2015-09-06 00:58:45 +09:00
|
|
|
let s:file_cmd = a:command
|
|
|
|
return fzf#vim#complete(extend({
|
2015-09-11 12:01:14 +09:00
|
|
|
\ 'prefix': function('s:fname_prefix'),
|
2015-09-06 00:58:45 +09:00
|
|
|
\ 'source': function('s:file_source'),
|
2015-09-12 02:52:43 +09:00
|
|
|
\ 'options': function('s:file_options')}, get(a:000, 0, g:fzf#vim#default_layout)))
|
2015-09-06 00:58:45 +09:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" ----------------------------------------------------------------------------
|
|
|
|
" <plug>(fzf-complete-line)
|
|
|
|
" <plug>(fzf-complete-buffer-line)
|
|
|
|
" ----------------------------------------------------------------------------
|
|
|
|
function! s:reduce_line(lines)
|
|
|
|
return join(split(a:lines[0], '\t\zs')[2:], '')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fzf#vim#complete#line(...)
|
|
|
|
return fzf#vim#complete(extend({
|
|
|
|
\ 'prefix': '^.*$',
|
2015-09-17 00:04:34 +09:00
|
|
|
\ 'source': fzf#vim#_lines(0),
|
2015-09-06 00:58:45 +09:00
|
|
|
\ 'options': '--tiebreak=index --ansi --nth 3..',
|
|
|
|
\ 'reducer': function('s:reduce_line')}, get(a:000, 0, g:fzf#vim#default_layout)))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fzf#vim#complete#buffer_line(...)
|
|
|
|
call fzf#vim#complete(extend({
|
|
|
|
\ 'prefix': '^.*$',
|
|
|
|
\ 'source': s:uniq(getline(1, '$'))}, get(a:000, 0, g:fzf#vim#default_layout)))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let &cpo = s:cpo_save
|
|
|
|
unlet s:cpo_save
|
|
|
|
|