On 2010-03-10, Gary Johnson wrote:
> On 2010-03-10, epanda wrote:
> > I success to store both type of information of cppCheck by this
> > command but :
> > 
> >     silent exe '!cppCheck ' . a:dir . ' -a --enable=all --template gcc 1>
> > infos.txt 2> cppcheck.out'
> >         cfile cppcheck.out
> >     copen
> > 
> > 
> > Opening report in cppcheck.out when it is finished
> > progress infos.txt that I have to open asynchronously I think with
> > client/server feature....
> > 
> > If you know how do to it quickly, I need you help
> > thank you

Here's what I wound up doing.  It works well on Linux, and because
it lets vim deal with the stdout and stderr redirection, it should
work on Windows as well.

I wrote a function that basically does the following.

    " Save previous 'make' options.
    "
    let ef=&errorformat
    let mp=&makeprg

    " Set new 'make' options for running 'cppcheck'.
    "
    " Vim's default errorformat matches cppcheck's "--template gcc".
    "
    set errorformat&
    let &makeprg = "cppcheck --enable=all --verbose --template gcc $*"

    " Do it.
    "
    execute "make" args

    " Restore previous 'make' options.
    "
    let &makeprg=mp
    let &errorformat=ef

All the output of cppcheck goes to both the screen and the error
file.  The user sees all the errors as well as the progress
indications, just as when using :make or :grep (which I like), and
the 'errorformat' takes care of keeping the progress indications
out of the quickfix list.

The complete plugin file is attached.

Regards,
Gary

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
" Vim plugin for running cppcheck
" Maintainer:   Gary Johnson <garyjohn AT spocom DOT com>
" Last Change:  2010-03-10 14:03:55

" Adapted from c_lint.vim.

" Exit if this plugin has already been loaded.
"
if exists("loaded_cppcheck")
    finish 
endif 
let loaded_cppcheck = 1

" Set cpoptions to the vim default value for the duration of this file
" so that we can use the line-continuation mechanism even if the user
" has disabled it.
"
let s:save_cpo = &cpo
set cpo&vim

command! -bang -nargs=* -complete=file -bar CppCheck call CppCheck("<bang>", 
<f-args>)

function! CppCheck(bang, ...)

    " Check whether the buffer contains unsaved changes.
    "
    if &modified && (a:bang != "!")
        if &errorbells
            normal \<Esc>               " Generate a bell
        endif
        echohl ErrorMsg
        echo "No write since last change (use ! to override)"
        echohl None
        return
    endif

    " Save previous 'make' options.
    "
    let ef=&errorformat
    let mp=&makeprg

    " Set new 'make' options for running 'cppcheck'.
    "
    " Vim's default errorformat matches cppcheck's "--template gcc".
    "
    set errorformat&
    let &makeprg = "cppcheck --enable=all --verbose --template gcc $*"

    " Build argument list.
    "
    if a:0 == 0
        let args = expand("%")
    else
        let args = a:1
        let i = 2
        while i <= a:0
            execute "let args = args . \" \" . a:" . i
            let i = i + 1
        endwhile
    endif

    " Do it.
    "
    execute "make" args

    " Restore previous 'make' options.
    "
    let &makeprg=mp
    let &errorformat=ef

endfunction

" Restore cpoptions.
"
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: ts=8 sw=4

Reply via email to