-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Massive refactoring of the whole filter/restore mechanism.
- Loading branch information
Showing
5 changed files
with
195 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
" vim-qf - Tame the quickfix window | ||
" Maintainer: romainl <[email protected]> | ||
" Version: 0.0.3 | ||
" Version: 0.0.2 | ||
" License: Vim License (see :help license) | ||
" Location: after/ftplugin/qf.vim | ||
" Website: https://github.com/romainl/vim-qf | ||
|
@@ -24,14 +24,14 @@ setlocal number | |
" we don't want quickfix buffers to pop up when doing :bn or :bp | ||
set nobuflisted | ||
|
||
" are we in a location list or a quickfix list? | ||
let b:isLoc = len(getloclist(0)) > 0 ? 1 : 0 | ||
|
||
" customize the statusline | ||
if exists("g:qf_statusline") | ||
execute "setlocal statusline=" . g:qf_statusline.before . "%{w:quickfix_title}" . g:qf_statusline.after | ||
execute "setlocal statusline=" . g:qf_statusline.before . "%{qf#SetStatusline()}" . g:qf_statusline.after | ||
endif | ||
|
||
" are we in a location list or a quickfix list? | ||
let b:isLoc = len(getloclist(0)) > 0 ? 1 : 0 | ||
|
||
" force the quickfix window to be opened at the bottom | ||
" of the screen and take the full width | ||
wincmd J | ||
|
@@ -56,25 +56,26 @@ endif | |
|
||
" filter the location/quickfix list | ||
" usage: | ||
" :Filter foo | ||
command! -buffer -nargs=* Filter call qf#FilterList(<q-args>) | ||
" :Filter foo | ||
command! -buffer -nargs=1 Filter call qf#FilterList(<q-args>) | ||
|
||
" restore the location/quickfix list | ||
" usage: | ||
" :Restore | ||
" :Restore | ||
command! -buffer Restore call qf#RestoreList() | ||
|
||
" do something on each line in the location/quickfix list | ||
" usage: | ||
" :Doline s/^/--- | ||
" :Doline s/^/--- | ||
command! -buffer -nargs=1 Doline call qf#DoList(1, <q-args>) | ||
|
||
" do something on each file in the location/quickfix list | ||
" usage: | ||
" :Dofile %s/^/--- | ||
" :Dofile %s/^/--- | ||
command! -buffer -nargs=1 Dofile call qf#DoList(0, <q-args>) | ||
|
||
" quit Vim if the last window is a quickfix window | ||
autocmd qf BufEnter <buffer> if winnr('$') < 2 | q | endif | ||
autocmd qf BufWinEnter <buffer> call qf#ReuseTitle() | ||
|
||
let &cpo = s:save_cpo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
" vim-qf - Tame the quickfix window | ||
" Maintainer: romainl <[email protected]> | ||
" Version: 0.0.3 | ||
" Version: 0.0.2 | ||
" License: Vim License (see :help license) | ||
" Location: autoload/qf.vim | ||
" Website: https://github.com/romainl/vim-qf | ||
|
@@ -51,33 +51,174 @@ endfunction | |
|
||
" filter the current list | ||
function qf#FilterList(pat) | ||
call qf#AddList() | ||
call qf#AddTitle(w:quickfix_title) | ||
|
||
call qf#SetList(a:pat) | ||
|
||
call qf#SetTitle(a:pat) | ||
call qf#AddTitle(w:quickfix_title) | ||
endfunction | ||
|
||
" restore the original list | ||
function qf#RestoreList() | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
if !exists("b:locl") | ||
let b:locl = getloclist(0) | ||
let w:qf_title = w:quickfix_title | ||
let lists = getwinvar(winnr("#"), "qf_location_lists") | ||
if len(lists) > 0 | ||
call setloclist(0, getwinvar(winnr("#"), "qf_location_lists")[0], "r") | ||
let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0] | ||
else | ||
echo "No filter applied. Nothing to restore." | ||
endif | ||
call setloclist(0, filter(getloclist(0), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat")) | ||
else | ||
if !exists("b:qfl") | ||
let b:qfl = getqflist() | ||
let w:qf_title = w:quickfix_title | ||
if exists("g:qf_quickfix_lists") | ||
if len(g:qf_quickfix_lists) > 0 | ||
call setqflist(g:qf_quickfix_lists[0], "r") | ||
let w:quickfix_title = g:qf_quickfix_titles[0] | ||
else | ||
echo "No filter applied. Nothing to restore." | ||
endif | ||
endif | ||
call setqflist(filter(getqflist(), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat")) | ||
endif | ||
let w:quickfix_title = w:qf_title . "[filtered]" | ||
endif | ||
call qf#ResetLists() | ||
endfunction | ||
|
||
" restore the original list | ||
function qf#RestoreList() | ||
function qf#ResetLists() | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
call setwinvar(winnr("#"), "qf_location_lists", []) | ||
call setwinvar(winnr("#"), "qf_location_titles", []) | ||
else | ||
let g:qf_quickfix_lists = [] | ||
let g:qf_quickfix_titles = [] | ||
endif | ||
endif | ||
endfunction | ||
|
||
function qf#SetStatusline() | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
let titles = getwinvar(winnr("#"), "qf_location_titles") | ||
if len(titles) > 0 | ||
return titles[-1] | ||
else | ||
if exists("w:quickfix_title") | ||
return w:quickfix_title | ||
else | ||
return "" | ||
endif | ||
endif | ||
else | ||
if exists("g:qf_quickfix_titles") | ||
if len(g:qf_quickfix_titles) > 0 | ||
return g:qf_quickfix_titles[-1] | ||
else | ||
if exists("w:quickfix_title") | ||
return w:quickfix_title | ||
else | ||
return "" | ||
endif | ||
endif | ||
else | ||
if exists("w:quickfix_title") | ||
return w:quickfix_title | ||
else | ||
return "" | ||
endif | ||
endif | ||
endif | ||
endif | ||
endfunction | ||
|
||
function qf#SetList(pat) | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
call setloclist(0, filter(getloclist(0), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat"), "r") | ||
else | ||
call setqflist(filter(getqflist(), "bufname(v:val['bufnr']) =~ a:pat || v:val['text'] =~ a:pat"), "r") | ||
endif | ||
endif | ||
endfunction | ||
|
||
function qf#AddList() | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
let locations = getwinvar(winnr("#"), "qf_location_lists") | ||
if len(locations) > 0 | ||
call add(locations, getloclist(0)) | ||
call setwinvar(winnr("#"), "qf_location_lists", locations) | ||
else | ||
call setwinvar(winnr("#"), "qf_location_lists", [getloclist(0)]) | ||
endif | ||
else | ||
if exists("g:qf_quickfix_lists") | ||
let g:qf_quickfix_lists = add(g:qf_quickfix_lists, getqflist()) | ||
else | ||
let g:qf_quickfix_lists = [getqflist()] | ||
endif | ||
endif | ||
endif | ||
endfunction | ||
|
||
function qf#SetTitle(pat) | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0] . " [filter: '" . a:pat . "']" | ||
else | ||
if len(g:qf_quickfix_titles) > 0 | ||
let w:quickfix_title = g:qf_quickfix_titles[0] . " [filter: '" . a:pat . "']" | ||
else | ||
let w:quickfix_title = w:quickfix_title . " [filter: '" . a:pat . "']" | ||
endif | ||
endif | ||
endif | ||
endfunction | ||
|
||
function qf#AddTitle(title) | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
let titles = getwinvar(winnr("#"), "qf_location_titles") | ||
if len(titles) > 0 | ||
call add(titles, a:title) | ||
call setwinvar(winnr("#"), "qf_location_titles", titles) | ||
else | ||
call setwinvar(winnr("#"), "qf_location_titles", [a:title]) | ||
endif | ||
else | ||
if exists("g:qf_quickfix_titles") | ||
let g:qf_quickfix_titles = add(g:qf_quickfix_titles, a:title) | ||
else | ||
let g:qf_quickfix_titles = [a:title] | ||
endif | ||
endif | ||
endif | ||
endfunction | ||
|
||
function qf#ReuseTitle() | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 && exists("b:locl") | ||
call setloclist(0, b:locl) | ||
elseif b:isLoc != 1 && !exists("b:locl") | ||
call setqflist(b:qfl) | ||
if b:isLoc == 1 | ||
let titles = getwinvar(winnr("#"), "qf_location_titles") | ||
if len(titles) > 0 | ||
let w:quickfix_title = getwinvar(winnr("#"), "qf_location_titles")[0]" | ||
endif | ||
else | ||
if exists("g:qf_quickfix_titles") | ||
let w:quickfix_title = g:qf_quickfix_titles[0] | ||
endif | ||
endif | ||
endif | ||
endfunction | ||
|
||
" template | ||
function qf#FunctionName(argument) | ||
if exists("b:isLoc") | ||
if b:isLoc == 1 | ||
" do something | ||
else | ||
" do something else | ||
endif | ||
let w:quickfix_title = w:qf_title | ||
endif | ||
endfunction | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.