[BLines] Allow multi selection for building quickfix list

This commit is contained in:
mg979
2018-09-07 09:37:36 +02:00
committed by Junegunn Choi
parent 8224416813
commit aedd47be21

View File

@@ -258,6 +258,17 @@ function! s:warn(message)
return 0 return 0
endfunction endfunction
function! s:fill_quickfix(list, ...)
if len(a:list) > 1
call setqflist(a:list)
copen
wincmd p
if a:0
execute a:1
endif
endif
endfunction
function! fzf#vim#_uniq(list) function! fzf#vim#_uniq(list)
let visited = {} let visited = {}
let ret = [] let ret = []
@@ -377,6 +388,12 @@ function! s:buffer_line_handler(lines)
if len(a:lines) < 2 if len(a:lines) < 2
return return
endif endif
let qfl = []
for line in a:lines[1:]
let [ln, ltxt] = split(line, "\t")
call add(qfl, {'filename': expand('%'), 'lnum': str2nr(ln), 'text': ltxt})
endfor
call s:fill_quickfix(qfl, 'cfirst')
normal! m' normal! m'
let cmd = s:action_for(a:lines[0]) let cmd = s:action_for(a:lines[0])
if !empty(cmd) if !empty(cmd)
@@ -387,18 +404,18 @@ function! s:buffer_line_handler(lines)
normal! ^zz normal! ^zz
endfunction endfunction
function! s:buffer_lines() function! s:buffer_lines(query)
let linefmt = s:yellow(" %4d ", "LineNr")."\t%s" let linefmt = s:yellow(" %4d ", "LineNr")."\t%s"
return map(getline(1, "$"), 'printf(linefmt, v:key + 1, v:val)') return map(empty(a:query) ? getline(1, "$") : filter(getline(1, "$"), 'v:val =~ "'.a:query.'"'), 'printf(linefmt, v:key + 1, v:val)')
endfunction endfunction
function! fzf#vim#buffer_lines(...) function! fzf#vim#buffer_lines(...)
let [query, args] = (a:0 && type(a:1) == type('')) ? let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000] \ [a:1, a:000[1:]] : ['', a:000]
return s:fzf('blines', { return s:fzf('blines', {
\ 'source': s:buffer_lines(), \ 'source': s:buffer_lines(query),
\ 'sink*': s:function('s:buffer_line_handler'), \ 'sink*': s:function('s:buffer_line_handler'),
\ 'options': ['+m', '--tiebreak=index', '--prompt', 'BLines> ', '--ansi', '--extended', '--nth=2..', '--layout=reverse-list', '--tabstop=1', '--query', query] \ 'options': ['+m', '--tiebreak=index', '--multi', '--prompt', 'BLines> ', '--ansi', '--extended', '--nth=2..', '--layout=reverse-list', '--tabstop=1']
\}, args) \}, args)
endfunction endfunction
@@ -648,11 +665,7 @@ function! s:ag_handler(lines, with_column)
catch catch
endtry endtry
if len(list) > 1 call s:fill_quickfix(list)
call setqflist(list)
copen
wincmd p
endif
endfunction endfunction
" query, [[ag options], options] " query, [[ag options], options]
@@ -737,12 +750,7 @@ function! s:btags_sink(lines)
execute split(line, "\t")[2] execute split(line, "\t")[2]
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')}) call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
endfor endfor
if len(qfl) > 1 call s:fill_quickfix(qfl, 'cfirst')
call setqflist(qfl)
copen
wincmd p
cfirst
endif
normal! zz normal! zz
endfunction endfunction
@@ -799,12 +807,7 @@ function! s:tags_sink(lines)
finally finally
let [&magic, &wrapscan, &acd] = [magic, wrapscan, acd] let [&magic, &wrapscan, &acd] = [magic, wrapscan, acd]
endtry endtry
if len(qfl) > 1 call s:fill_quickfix(qfl, 'clast')
call setqflist(qfl)
copen
wincmd p
clast
endif
normal! zz normal! zz
endfunction endfunction