scrooloose/syntastic — pull request #256 by powerman (2012-05-24 10:02:49+00:00)
Title: Workaround bug in vim related to E855

There is a bug in current Vim (7.3.515) and older triggered by
autocommands. Vim patch 7.3.449 (Autocommands caused command to abort)
tried to fix it, but it's either wrong or incomplete and doesn't work.

Example case which trigger this bug is trying to do :lclose in autocommand
executed while closing location-list, which happens because of this:

autocmd BufWinLeave * if empty(&bt) | lclose | endif

Too see this bug it's enough to set

let g:syntastic_auto_loc_list=1

then open file with syntax error and try to :wq
If there no other tabs (:tabnew), then you'll get error:

E855 Autocommands caused command to abort

but if there are some tabs then vim will crash with segfault.
Vim versions before 7.3.449 behave differently without tabs and all crash
with tabs.

First issue is &bt inside BufWinLeave may be different from the buffer
being unloaded (this is documented behaviour for BufWinLeave), so it
should be replaced with: getbufvar(0+expand(''), '&bt').

This is bug in syntastic, but fixing it solve overall issue only
partially - now bug doesn't triggered on :lclose and :q inside
location-list window, but :q inside main file window (when location-list
open) still result in same E855 or segfault, which is bug in Vim.

To workaround bug in Vim I've change logic to close location-list window:
instead of closing it on BufWinLeave, it's closed on BufEnter in
location-list window if it's only buffer in current window.