From 4f32a207195440c39d66394da451862f2e92ce92 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 28 Dec 2018 21:47:01 +1300 Subject: New version handles :lhelpgrep --- plugin/quickfix_auto_open.vim | 47 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'plugin') 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 " 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('')) + 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 -- cgit v1.2.3