diff --git a/README.md b/README.md index d779a13..3895f3a 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,15 @@ ## Features -* no softwrapping in the quickfix window, -* no relative numbers in the quickfix window, -* quickfix buffers are hidden from `:ls` and buffer navigation, -* optional Ack.vim inspired mappings, -* optional mappings for `:cnext`, `:cprevious`, `:lnext`, `:lprevious` - that wrap around the beginning an end of the list, -* optional mapping for jumping to and from the location/quickfix window, -* filter/restore the list, -* perform commands on each line in the list, -* perform commands on each file in the list, +* no soft-wrapping, +* no relative numbers, +* quickfix buffers hidden from `:ls` and buffer navigation, +* Ack.vim-inspired mappings, +* wrapping mappings for `:cnext`, `:cprevious`, `:lnext`, `:lprevious`, +* jump to and from the location/quickfix window with a single mapping +* filter/restore the list +* perform commands on each line in the list +* perform commands on each file in the list * open the location/quickfix window automatically after `:make`, `:grep`, `:lvimgrep` and friends if there are valid locations/errors * quit Vim if the last window is a location/quickfix window @@ -46,6 +45,7 @@ on Windows. ## TODO +* Ask #vim's opinion. * Export more options? * Add a gifcast to the README? @@ -54,4 +54,7 @@ on Windows. * Use `` mappings. * Add proper attribution for a few features. * Write a proper `help` file. +`` mappings. +* Add proper attribution for a few features. +* Write a proper `help` file. * Ask #vim's opinion. diff --git a/after/ftplugin/qf.vim b/after/ftplugin/qf.vim index 672e1aa..99b4e69 100644 --- a/after/ftplugin/qf.vim +++ b/after/ftplugin/qf.vim @@ -1,6 +1,6 @@ " vim-qf - Tame the quickfix window " Maintainer: romainl -" 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() +" :Filter foo +command! -buffer -nargs=1 Filter call qf#FilterList() " 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, ) " do something on each file in the location/quickfix list " usage: -" :Dofile %s/^/--- +" :Dofile %s/^/--- command! -buffer -nargs=1 Dofile call qf#DoList(0, ) " quit Vim if the last window is a quickfix window autocmd qf BufEnter if winnr('$') < 2 | q | endif +autocmd qf BufWinEnter call qf#ReuseTitle() let &cpo = s:save_cpo diff --git a/autoload/qf.vim b/autoload/qf.vim index 2abc2c6..f576ddd 100644 --- a/autoload/qf.vim +++ b/autoload/qf.vim @@ -1,6 +1,6 @@ " vim-qf - Tame the quickfix window " Maintainer: romainl -" 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 diff --git a/doc/qf.txt b/doc/qf.txt index 8d983f7..d220ffa 100644 --- a/doc/qf.txt +++ b/doc/qf.txt @@ -10,10 +10,9 @@ Help on using vim-qf *qf* *vim-qf 2. Installation ............................... |qf-installation| 3. Configuration .............................. |qf-configuration| 4. Usage ...................................... |qf-usage| - 5. Sample config .............................. |qf-sample| - 6. Acknowledgements ........................... |qf-acknowledgements| - 7. TODO ....................................... |qf-todo| - 8. DONE ....................................... |qf-done| + 5. Acknowledgements ........................... |qf-acknowledgements| + 6. TODO ....................................... |qf-todo| + 7. DONE ....................................... |qf-done| ============================================================================== 1. INTRODUCTION *qf-intro* @@ -153,7 +152,8 @@ is focused: *:Filter* Removes every item that doesn't match with the supplied argument, - either in the filename or in the description. + either in the filename or in the description. Note: no regular + expressions. Example: > @@ -180,37 +180,7 @@ is focused: :Dofile norm @q < ============================================================================== - 5. SAMPLE CONFIG *qf-sample* - -Here is a sample "all-inclusive" congig: > - - " use Ack.vim mappings - let g:qf_mapping_ack_style = 1 - - " 'synchronize' the statusline with our own - let g:qf_statusline = {} - let g:qf_statusline.before = '%<\ ' - let g:qf_statusline.after = '\ %f%=%l\/%-6L\ \ \ \ \ ' - - " wrapping mappings for convenience - nmap QfCprevious - nmap QfCnext - nmap QfLprevious - nmap QfLnext - - " switch to/from the location/quickfix window - nmap ç QfSwitch - - " press '§' to filter the list with the filename under the cursor - " press '' to restore the list - augroup vimqf - autocmd! - autocmd FileType qf nnoremap § :Filter - autocmd FileType qf nnoremap :Restore - augroup END -< -============================================================================== - 6. ACKNOWLEGEMENTS *qf-acknowledgements* + 5. ACKNOWLEGEMENTS *qf-acknowledgements* The "Ack.vim-inspired mappings" are adapted from Ack.vim: @@ -234,13 +204,13 @@ a proper plugin come from Barry Arthur's Area 41 plugin: - https://github.com/dahu/Area-41 ============================================================================== - 7. TODO *qf-todo* + 6. TODO *qf-todo* - Export more options? - Add a gifcast to the README? ============================================================================== - 8. DONE *qf-done* + 7. DONE *qf-done* - Use mappings. - Add proper attribution for a few features. diff --git a/plugin/qf.vim b/plugin/qf.vim index 47c16ac..8a00661 100644 --- a/plugin/qf.vim +++ b/plugin/qf.vim @@ -1,6 +1,6 @@ " vim-qf - Tame the quickfix window " Maintainer: romainl -" Version: 0.0.3 +" Version: 0.0.2 " License: Vim License (see :help license) " Location: plugin/qf.vim " Website: https://github.com/romainl/vim-qf @@ -19,12 +19,12 @@ let s:save_cpo = &cpo set cpo&vim " and go up and down the quickfix list and wrap around -nnoremap QfCprevious :call qf#WrapCommand('up', 'c') -nnoremap QfCnext :call qf#WrapCommand('down', 'c') +nnoremap QfCprevious :call qf#WrapCommand('up', 'c') +nnoremap QfCnext :call qf#WrapCommand('down', 'c') " and go up and down the location list and wrap around -nnoremap QfLprevious :call qf#WrapCommand('down', 'l') -nnoremap QfLnext :call qf#WrapCommand('up', 'l') +nnoremap QfLprevious :call qf#WrapCommand('down', 'l') +nnoremap QfLnext :call qf#WrapCommand('up', 'l') " jump to and from the location/quickfix window nnoremap QfSwitch &filetype == "qf" ? "p" : "b"