Syntastic: Is there a way to get Syntastic working without saving the file.

Created on 3 Jun 2013  路  8Comments  路  Source: vim-syntastic/syntastic

Hi,
I have just installed Syntastic on MacVim and configured it to work with pyflakes. All critical config is in my .vimrc file, so the plugin works. However, I would like to be able to invoke the plugin check and the error display functions without saving the file. Well I did things like:

map :w:Errors
imap :w:Errors

Which are supposed to make the process seamless, but still this is saving the file. Is there a way to get this working without actually saving the changes to the file. I thought the passive mode is designed for this?

map :w:SyntasticToggleMode
imap :w:SyntasticToggleMode

So by switching the PASSIVE mode ON, I should be able to run the ":SyntasticCheck" and the ":Errors" manually, right? However that seems not to be able to update the results on the fly. The error reports and the signs are still there even after the mistakes are corrected. However once I run ":w", it all works again.

Any ideas? Thanks.

All 8 comments

This is the expected behaviour. Syntastic feeds the file as it is on disk to an external checker, then reads back the errors and shows them to you. If the contents of the current buffer in Vim are out of sync with the file on disk (that is, if you haven't written the file), the errors produced by the checks will also be out of synch.

On a tangentially related note, I'd suggest that the settings closest to what you want would be something like this:

let g:syntastic_mode_map={'mode': 'passive'}
let g:syntastic_always_populate_loc_list=1
let g:syntastic_check_on_wq=0
let g:syntastic_auto_loc_list=1

You'd then issue :SyntasticInfo to run the checks (but only after having written the file).

I think why @symbolix asks for that, or at least why i would like this to be possible; is in a Javascript environment. Popular Javascript build systems, like Grunt, often listen for file modifications, then automatically rebuild. When a build fails, because of a syntax error, such build process often exits. So to keep the build process running, you definitely want to know about syntax errors before you save the file. Therefore it would be very useful if Syntastic could check the buffer, not the file, automatically, after a few idle seconds...

@guilala Sorry, syntastic can't do this.

At some point I made an experiment in that direction, and nobody cared (cf. #1351). Reviving it would be easy, but that approach would only work for the (few) languages for which Vim has embedded interpreters: Perl, Python, Ruby, Lua, and perhaps TCL and MzScheme. Extending it to JavaScript wouldn't be possible without a major re-design of syntastic, and would only work with major limitations. Not going to happen, sorry.

@lcd047 I would really appreciate this behavior. Often, syntax errors depend on each other, so I have to save & re-check after fixing each error. How about automatically writing the buffer to a temporary file outside of the source tree and linting that?

@danijar Nope: many linters run checks against the full project rather than against a single file.

Hi, you may wanna try vim-auto-save ; it works for me on this need. IF WE CANNOT CHANGE THE SYNTASTIC, WE CAN TRY TO HACK THE VIM TO SAVE TO DISK AUTOMATICALLY:).

I code in Python recently and below is an example to go.

  1. get the vim, syntastic, pylint ready to go
  2. install Vundle to vim
  3. add Plugin '907th/vim-auto-save' between the call vundle#begin() and call vundle#end() lines in .vimrc
  4. run vim +PluginInstall +qall in command line
  5. add let g:auto_save = 1 to .vimrc, to enable the AutoSave on Vim startup
  6. open a Python script in Vim to test

I think it's a little strange that you say syntastic "can't do this". It seems like there should be any number of fairly straightforward solutions to the problem: e.g. save the file to a temporary directory, and run linting on that temporary directory.

@haberdashPI Did you read the thread above?

save the file to a temporary directory, and run linting on that temporary directory.

What file? As I said, many linters run checks against the full project rather than against a single file. You may try copying the entire project locally, but Vim has no concept of project.

But even if the actual checks are against a single file, that doesn't mean there is a single file involved. Consider f.i. #include <foo.h> in C. The file foo.h may not even be part of the project.

Sadly, a solution that save files locally to check them would be half-assed at best. _shrug_

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zoecarver picture zoecarver  路  8Comments

HabbaRazzer picture HabbaRazzer  路  5Comments

noprompt picture noprompt  路  5Comments

dunatotatos picture dunatotatos  路  6Comments

bitc picture bitc  路  3Comments