syntastic
syntastic copied to clipboard
SyntasticDisable / SyntasticDisableBuffer commands
While there is SyntasticToggleMode and there are settings to influence the maps for active/passive checking, I would sometimes like to have a command SyntasticDisable, which would basically turn on passive mode and (temporarily) ignore anything from the active map.
There should be a global command/switch (SyntasticDisable) and a buffer-local one, i.e. SyntasticDisableBuffer (and a buffer-local var switched by it).
This might be considered as a "really passive" mode, wrapping the g:syntastic_mode_map setting (for the global command).
My setting is to use "passive" by default, but enable certain file types:
let g:syntastic_mode_map = {
\'mode': 'passive',
\ 'active_filetypes': ['ruby', 'php', 'lua', 'python', 'sh', 'zsh'],
\ 'passive_filetypes': [] }
However, when working on certain/foreign projects this might get into the way.
There should be commands to re-enable (and possibly toggle) this then, too, of course.
(This was mentioned in https://github.com/scrooloose/syntastic/issues/689 already, and I've had requested it in https://github.com/scrooloose/syntastic/issues/101 - that's when the passive/active maps were added).
I suppose it would have been useful for mode to have three states rather than two, but it's too late to change that now.
Anyway, you can write your own SyntasticDisableToggle like this (not tested):
function! SyntasticDisableToggle()
if !exists('s:syntastic_disabled')
let s:syntastic_disabled = 0
endif
if !s:syntastic_disabled
let s:modemap_save = deepcopy(g:syntastic_mode_map)
let g:syntastic_mode_map['active_filetypes'] = []
let g:syntastic_mode_map['mode'] = 'passive'
let s:syntastic_disabled = 1
SyntasticReset
else
let g:syntastic_mode_map = deepcopy(s:modemap_save)
let s:syntastic_disabled = 0
endif
echo 'Syntastic ' . ['enabled', 'disabled'][s:syntastic_disabled]
endfunction
command! SyntasticDisableToggle call SyntasticDisableToggle()
You can also disable checks per buffer, by setting b:syntastic_mode to passive. It will take precedence over the global mode regardless of active_filetypes.
This works well, thanks!
Additionally, g:syntastic_auto_loc_list needs to be handled there, too - at least when it's 1.
I am setting it to 0 when disabling, and restore it when enabling.
Hmm. Why do you need to set g:syntastic_auto_loc_list to 0 when you "disable" syntastic as above? In what scenario does the error window open when you don't want it to do that?
It happens when Syntastic was run already.
I use the disabling after Syntastic might have flooded me with errors that are not relevant. But since it ran already, it will happily display them again.
It happens when Syntastic was run already.
Yes, I understand that. Still, in what scenario does the error window opens?
E.g. when writing the file again.
Does the problem go away if you add a SyntasticReset? I edited my answer above.
Yes, thanks!
btw: I've also added a echom "Syntastic disabled." (and the counterpart) for feedback.
Because a few of the files I work on at my job are hopelessly non-PSR compliant, I was looking for functionality to turn off Syntastic for the current buffer only. The 'SyntasticDisableToggle' solution outlined above works for me until I save, whereby the script variable 's:syntastic_disabled' is ignored and those non-PSR compliant files bog down all over again. This simplified approach works better for me:
"disable syntastic on a per buffer basis (some work files blow it up)
function! SyntasticDisableBuffer()
let b:syntastic_mode = "passive"
SyntasticReset
echo 'Syntastic disabled for this buffer'
endfunction
command! SyntasticDisableBuffer call SyntasticDisableBuffer()
Like the original disabling function, this has no affect on other buffers in the current session.
the script variable 's:syntastic_disabled' is ignored and those non-PSR compliant files bog down all over again.
@ssteele Please open Vim, run :h s:var, and read the first paragraph.
This simplified approach works better for me:
I believe you have reinvented a weak form of b:syntastic_skip_checks. :)
Awesome @lcd047 thanks for that!