aboutsummaryrefslogtreecommitdiff
path: root/plugin/quickfix_auto_open.vim
blob: 63195da19193601a91149b114dee73d03ac8c698 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"
" quickfix_auto_open.vim: Always pop open the quickfix list or location list
" when they're changed.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
"
if exists('loaded_quickfix_auto_open') || &compatible
  finish
endif
if !has('autocmd') || v:version < 700
  finish
endif
let loaded_quickfix_auto_open = 1

" 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'

    " I can't figure out anything sensible to do for the :lhelpgrep command,
    " but for all the other location window commands, :lwindow is sensible
    if a:command !=# 'lhelpgrep'
      lwindow
    endif

  " 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!

  " 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