aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md9
-rw-r--r--VERSION2
-rw-r--r--autoload/quickfix_auto_open.vim41
-rw-r--r--doc/quickfix_auto_open.txt13
-rw-r--r--plugin/quickfix_auto_open.vim10
5 files changed, 58 insertions, 17 deletions
diff --git a/README.md b/README.md
index 6b6e180..672ad32 100644
--- a/README.md
+++ b/README.md
@@ -7,13 +7,12 @@ quickfix and location lists when a command that changes their contents is run.
Credits
-------
-The original commands that do essentially all of this come from Romain
-Lafourcade (romainl)'s "minivimrc" project on GitHub:
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. The original
+commands are 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.
+The only substantial changes to the original `autocmd` definitions are special
+handling for the unique behaviour of `:lhelpgrep:`.
License
-------
diff --git a/VERSION b/VERSION
index 3eefcb9..227cea2 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.0
+2.0.0
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
diff --git a/doc/quickfix_auto_open.txt b/doc/quickfix_auto_open.txt
index 553de9d..28fe342 100644
--- a/doc/quickfix_auto_open.txt
+++ b/doc/quickfix_auto_open.txt
@@ -1,4 +1,4 @@
-*quickfix_auto_open.txt* For Vim version 7.0 Last change: 2019 May 25
+*quickfix_auto_open.txt* For Vim version 7.0 Last change: 2019 Jun 4
DESCRIPTION *quickfix_auto_open*
@@ -7,13 +7,16 @@ quickfix and location lists when a command that changes their contents is run.
REQUIREMENTS *quickfix_auto_open-requirements*
-This plugin is only available if 'compatible' is not set. It also requires
-the |+autocmd| feature.
+This plugin is only available if 'compatible' is not set.
AUTHOR *quickfix_auto_open-author*
-The original commands are from Romain Lafourcade (romainl)'s "minivimrc"
-project on GitHub: <https://github.com/romainl/minivimrc>
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. The original
+commands are from Romain Lafourcade (romainl)'s "minivimrc" project on GitHub:
+<https://github.com/romainl/minivimrc>
+
+The only substantial changes to the original `autocmd` definitions are
+special handling for the unique behaviour of |:lhelpgrep:|.
LICENSE *quickfix_auto_open-license*
diff --git a/plugin/quickfix_auto_open.vim b/plugin/quickfix_auto_open.vim
index 73b3f4b..507dff3 100644
--- a/plugin/quickfix_auto_open.vim
+++ b/plugin/quickfix_auto_open.vim
@@ -10,13 +10,11 @@ if exists('loaded_quickfix_auto_open') || &compatible || v:version < 700
endif
let loaded_quickfix_auto_open = 1
-" Set up hooks in self-clearing group
+" Set up hooks for events that may yield a populated quickfix or location list
augroup quickfix_auto_open
autocmd!
+ autocmd QuickFixCmdPost *
+ \ call quickfix_auto_open#(expand('<amatch>'))
autocmd VimEnter *
- \ cwindow
- autocmd QuickFixCmdPost [^l]*
- \ cwindow
- autocmd QuickFixCmdPost l*
- \ lwindow
+ \ doautocmd quickfix_auto_open QuickFixCmdPost
augroup END