aboutsummaryrefslogtreecommitdiff
path: root/plugin/quickfix_auto_open.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-28 21:47:01 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-28 21:50:10 +1300
commit4f32a207195440c39d66394da451862f2e92ce92 (patch)
tree3e36709b6d4b602f80e3b8208c845cca1d9bc974 /plugin/quickfix_auto_open.vim
parentFirst version (diff)
downloadvim-quickfix-auto-open-4f32a207195440c39d66394da451862f2e92ce92.tar.gz
vim-quickfix-auto-open-4f32a207195440c39d66394da451862f2e92ce92.zip
New version handles :lhelpgrep
Diffstat (limited to 'plugin/quickfix_auto_open.vim')
-rw-r--r--plugin/quickfix_auto_open.vim47
1 files changed, 41 insertions, 6 deletions
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