[fzf-complete-line] Exclude empty lines

This commit is contained in:
Junegunn Choi
2015-09-17 00:04:34 +09:00
parent 561cb901d1
commit 22c8a706c2
2 changed files with 7 additions and 5 deletions

View File

@@ -154,21 +154,23 @@ function! s:line_handler(lines)
normal! ^zz normal! ^zz
endfunction endfunction
function! fzf#vim#_lines() function! fzf#vim#_lines(all)
let cur = [] let cur = []
let rest = [] let rest = []
let buf = bufnr('') let buf = bufnr('')
for b in s:buflisted() for b in s:buflisted()
call extend(b == buf ? cur : rest, call extend(b == buf ? cur : rest,
\ filter(
\ map(getbufline(b, 1, "$"), \ map(getbufline(b, 1, "$"),
\ 'printf("[%s]\t%s:\t%s", s:blue(b), s:yellow(v:key + 1), v:val)')) \ '(!a:all && empty(v:val)) ? "" : printf("[%s]\t%s:\t%s", s:blue(b), s:yellow(v:key + 1), v:val)'),
\ 'a:all || !empty(v:val)'))
endfor endfor
return extend(cur, rest) return extend(cur, rest)
endfunction endfunction
function! fzf#vim#lines(...) function! fzf#vim#lines(...)
call s:fzf({ call s:fzf({
\ 'source': fzf#vim#_lines(), \ 'source': fzf#vim#_lines(1),
\ 'sink*': function('s:line_handler'), \ 'sink*': function('s:line_handler'),
\ 'options': '+m --tiebreak=index --prompt "Lines> " --ansi --extended --nth=3..'.s:expect() \ 'options': '+m --tiebreak=index --prompt "Lines> " --ansi --extended --nth=3..'.s:expect()
\}, a:000) \}, a:000)

View File

@@ -121,7 +121,7 @@ endfunction
function! fzf#vim#complete#line(...) function! fzf#vim#complete#line(...)
return fzf#vim#complete(extend({ return fzf#vim#complete(extend({
\ 'prefix': '^.*$', \ 'prefix': '^.*$',
\ 'source': fzf#vim#_lines(), \ 'source': fzf#vim#_lines(0),
\ 'options': '--tiebreak=index --ansi --nth 3..', \ 'options': '--tiebreak=index --ansi --nth 3..',
\ 'reducer': function('s:reduce_line')}, get(a:000, 0, g:fzf#vim#default_layout))) \ 'reducer': function('s:reduce_line')}, get(a:000, 0, g:fzf#vim#default_layout)))
endfunction endfunction