aboutsummaryrefslogtreecommitdiff
path: root/autoload/quickfix_auto_open.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/quickfix_auto_open.vim')
-rw-r--r--autoload/quickfix_auto_open.vim41
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