tomtom / checksyntax_vim

Check a file's syntax when saving a file (php, ruby, tex ...) with vim
http://www.vim.org/scripts/script.php?script_id=1431
GNU General Public License v3.0
94 stars 9 forks source link

Support for unsaved files (via stdin or temporary files) #1

Closed blueyed closed 12 years ago

blueyed commented 13 years ago

I have found the following code in the vim wiki [1], which uses stdin to pass the buffer's content to the "php -l" process.

This method would certainly work with any other tool, because you could just create a real temporary file and pass this on.

I would say that an extra command should get used for this, like "CheckSyntaxUnsaved" (which is rather bad, but to get an idea).

    if !exists('*PHPsynCHK')
        function! PHPsynCHK()
            ccl
            let winnum = winnr() " get current window number
            let linenum = line('.')
            let colnum = col('.')
            silent execute "%!php -l -f /dev/stdin | sed 's/\\/dev\\/stdin/".bufname("%")."/g' >.vimerr; cat"
            silent cf .vimerr
            cw " open the error window if it contains error
            " return to the window with cursor set on the line of the first error (if any)
            execute winnum . "wincmd w"
            silent undo
            silent cf
            if 1 == len(getqflist())
                w
                call cursor(linenum, colnum)
            endif
        endfunction
    endif

Also please note that a method should be used which works on Windows, too, like using a temporary file or methods like "-" instead of "/dev/stdin".

1: http://vim.wikia.com/wiki/Runtime_syntax_check_for_php

tomtom commented 13 years ago

I couldn't get that to work.

The current version on github supports a modified property. So you should be able to do something like this:

    let g:checksyntax['php'].modified = 'php_modified'
    let g:checksyntax['php_modified'] = {
                \ 'exec': 'call checksyntax#PhpModified()',
                \ 'efm': '%*[^:]: %m in %f on line %l',
                \ 'okrx': 'No syntax errors detected in ',
                \ }

    " Based on http://vim.wikia.com/wiki/Runtime_syntax_check_for_php
    function! checksyntax#PhpModified() "{{{3
        ...
    endf

given that you can fill in the missing part for "..." :-)