tags:

views:

69

answers:

1

What are the plugnins for vim/gvim that can report about bad formatting esp C++ code and PLSQL code. Like:

  1. blank space after a line.
  2. line having character more than 80 (like 'match' does).
  3. void foo(int x,int y); then it will report forgot a space after ,
  4. And many more formatting errors like above.

Is there any standard practice for reporting the formatting of code before checking into CVS?

+4  A: 

In my case, I have a series of syntax rules defined to make such things easy to spot.

highlight ImproperSyntax ctermbg=red guibg=red
au BufWinEnter * syn match ImproperSyntax /\s\+$\| \+\ze\t/  "Spaces at the end of lines or BEFORE tabs
au Filetype cpp,c syn keyword ImproperSyntax dynamic_cast "disallowed keyword
au Filetype cpp,c syn match ImproperSyntax /[^\n]\%$/  display "Last line should be blank
au Filetype cpp,c syn match ImproperSyntax /\t/ display "No tabs!
au Filetype cpp,c syn match ImproperSyntax /,\S/ display "comma always has a space
au Filetype cpp,c syn match ImproperSyntax /\%80v.*$/ "Highlight any characters passed column 80

An additional trick you can use is to incorporate all of these into a function (or list/dictionary), and display them as an error either on the statusline (my preference), or to the user as an error.

Regarding checking into CVS... I'm not sure about CVS, but SVN and hg (and presumably most other version control systems) can be instructed to execute a series of 'pre-commit hooks', before allowing you to commit. One of those could easily be programmed to scan for this same behavior (possibly with some sort of override symbol as well).

jkerian
+1 for some useful vimscript. But why disallow dynamic_cast<>?
Johnsyweb
Embedded programming project, mostly done in "C with classes"-style C++. If you see a dynamic_cast in the codebase, someone doesn't understand what the casts do. (our code is littered with inappropriate reinterpret_cast, which I have on a less severe highlight color) I would personally prefer a few more normal language features being available, a heap would be nice, for example.
jkerian
I would be **much** more worried about people using `reinterpret_cast` than `dynamic_cast` (as that is more likely to highlight an misunderstanding of C++ casting). If I ever wanted to prevent the usage of `dynamic_cast`, I'd simply disable RTTI in my compiler options. But this is *way* off-topic for this answer!
Johnsyweb