diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-04 13:57:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-04 13:57:52 +1200 |
commit | ec39dea7ae43434cc8fabc6f05cb2db81d816a67 (patch) | |
tree | 448e4c40375b9f2e6647ced62420547d0e1d7bb6 /autoload | |
parent | Simplify back to romainl's original commands (diff) | |
download | vim-quickfix-auto-open-ec39dea7ae43434cc8fabc6f05cb2db81d816a67.tar.gz vim-quickfix-auto-open-ec39dea7ae43434cc8fabc6f05cb2db81d816a67.zip |
Make :lhelpgrep work with a deferred autocmd
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/quickfix_auto_open.vim | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/autoload/quickfix_auto_open.vim b/autoload/quickfix_auto_open.vim new file mode 100644 index 0000000..5dfc582 --- /dev/null +++ b/autoload/quickfix_auto_open.vim @@ -0,0 +1,41 @@ +" Handle a quickfix command +function! quickfix_auto_open#(command) abort + + " The only difficult quickfix command to handle is :lhelpgrep, because it + " uses the location list not for the current window but for a :help window, + " creating a new one if necessary. Worse, that window creation doesn't + " happen until *after* this event has fired, so we have to defer the + " location list opening with a dynamic autocommand that self-destructs. + if a:command ==# 'lhelpgrep' + + " Expect a new window to pop up after this event has finished; hook into + " it to check its location and the presence of a location list, and open + " it up if so; then remove the hook + autocmd quickfix_auto_open BufEnter * + \ call s:Help(bufnr('%')) + \|autocmd! quickfix_auto_open BufEnter + + " All of the rest of the commands are really easy: + elseif a:command =~# '^l' + lwindow " Command started with 'l', open this window's location list + else + cwindow " Command didn't start with 'l', open this window's quickfix list + endif + +endfunction + +" If the buffer just entered is in a :help window with a location list with at +" least one item, pop it open +function! s:Help(bufnr) abort + + " Get buffer and window number + let bufnr = a:bufnr + let winnr = bufwinnr(bufnr) + + " Test buffer type and location list existence and non-zero contents + if getbufvar(bufnr, '&buftype') ==# 'help' + \ && len(getloclist(winnr)) > 0 + execute winnr.'windo lwindow' + endif + +endfunction |