diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-28 21:47:01 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-28 21:50:10 +1300 |
commit | 4f32a207195440c39d66394da451862f2e92ce92 (patch) | |
tree | 3e36709b6d4b602f80e3b8208c845cca1d9bc974 | |
parent | First version (diff) | |
download | vim-quickfix-auto-open-4f32a207195440c39d66394da451862f2e92ce92.tar.gz vim-quickfix-auto-open-4f32a207195440c39d66394da451862f2e92ce92.zip |
New version handles :lhelpgrep
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | doc/quickfix_auto_open.txt | 13 | ||||
-rw-r--r-- | plugin/quickfix_auto_open.vim | 47 |
3 files changed, 58 insertions, 17 deletions
@@ -1,18 +1,21 @@ quickfix\_auto\_open.vim ======================== -This is a tiny plugin packaging of hooks to automatically open the quickfix and -location lists when a command that changes their contents is run. +This is a tiny plugin packaging of hooks to automatically open relevant +quickfix and location lists when a command that changes their contents is run. Credits ------- -This is just a plugin repackaging of a fragment from romainl's "minivimrc" -project on GitHub: <https://github.com/romainl/minivimrc> +The original commands that do essentially all of this come from Romain +Lafourcade (romainl)'s "minivimrc" project on GitHub: +<https://github.com/romainl/minivimrc> + +Tom Ryder (tejr) extended them just a bit to handle the slightly different +behavior of `:lhelpgrep`, and packaged and documented them for this +distribution. License ------- Distributed under the same terms as Vim itself, probably. See `:help license`. - -[1]: https://sanctum.geek.nz/ diff --git a/doc/quickfix_auto_open.txt b/doc/quickfix_auto_open.txt index c9fc24b..745d882 100644 --- a/doc/quickfix_auto_open.txt +++ b/doc/quickfix_auto_open.txt @@ -1,9 +1,9 @@ -*quickfix_auto_open.txt* For Vim version 7.0 Last change: 2018 Jul 24 +*quickfix_auto_open.txt* For Vim version 7.0 Last change: 2018 Dec 28 DESCRIPTION *quickfix_auto_open* -This is a tiny plugin packaging of hooks to automatically open the quickfix -and location lists when a command that changes their contents is run. +This is a tiny plugin packaging of hooks to automatically open relevant +quickfix and location lists when a command that changes their contents is run. REQUIREMENTS *quickfix_auto_open-requirements* @@ -12,10 +12,13 @@ This plugin is only available if 'compatible' is not set. It also requires the AUTHOR *quickfix_auto_open-author* -Original commands were found in romainl's "minivimrc" project on GitHub: +The original commands that do essentially all of this come from Romain +Lafourcade (romainl)'s "minivimrc" project on GitHub: <https://github.com/romainl/minivimrc> -Plugin packaging and documentation by by Tom Ryder <tom@sanctum.geek.nz>. +Tom Ryder (tejr) extended them just a bit to handle the slightly different +behavior of |:lhelpgrep|, and packaged and documented them for this +distribution. LICENSE *quickfix_auto_open-license* diff --git a/plugin/quickfix_auto_open.vim b/plugin/quickfix_auto_open.vim index e2f111f..5ac821b 100644 --- a/plugin/quickfix_auto_open.vim +++ b/plugin/quickfix_auto_open.vim @@ -1,6 +1,6 @@ " " quickfix_auto_open.vim: Always pop open the quickfix list or location list -" when they're changed. Dispassionately stolen from romainl's minivimrc. +" when they're changed. " " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself @@ -8,15 +8,50 @@ if exists('g:loaded_quickfix_auto_open') || &compatible finish endif -if !exists('##QuickfixCmdPost') || !exists('##VimEnter') +if !has('autocmd') || v:version < 700 finish endif let g:loaded_quickfix_auto_open = 1 -" Always pop open quickfix and location lists when changed +" Open an appropriate quickfix or location list, depending on the command +function! s:Open(command) abort + + " The command starts with 'l', so we'll be opening a location list + if strpart(a:command, 0, 1) ==# 'l' + + " If the command is 'lhelpgrep', we'll need to switch to the help window + " to open its location list rather than the current window's + if a:command ==# 'lhelpgrep' + help + endif + + " Open location list if there's anything in it + lwindow + + " The command did not start with 'l', so we can just open the quickfix + " window, and we're done + else + cwindow + + endif + +endfunction + +" Set up hooks in self-clearing group augroup quickfix_auto_open autocmd! - autocmd QuickfixCmdPost [^l]* cwindow - autocmd QuickfixCmdPost l* lwindow - autocmd VimEnter * cwindow + + " Run whenever a command changes a quickfix or location list + if exists('##QuickFixCmdPost') + autocmd QuickFixCmdPost * + \ call s:Open(expand('<amatch>')) + endif + + " Run on Vim startup completion to open any quickfix list already present, + " with a blank command name + if exists('##VimEnter') + autocmd VimEnter * + \ call s:Open('') + endif + augroup END |