Changes between Version 11 and Version 12 of CodingGuidelines/VIM


Ignore:
Timestamp:
Jul 8, 2010, 11:19:11 AM (14 years ago)
Author:
pulkomandy
Comment:

Update the regexps with more finetuned ones (avoids some false positives and checks some more things), and detailed the help text on how to use it.

Legend:

Unmodified
Added
Removed
Modified
  • CodingGuidelines/VIM

    v11 v12  
    33
    44{{{
     5
     6
     7:fu FuncHaikuCheck()
     8                call matchadd('Search', '\%>80v.\+', -1) " line with more than 80 chars
     9        call matchadd('Search', '0\s* \s*', -1)        " probably wrong indenting
     10        call matchadd('Search', '\(for\|if\|select\|while\)(', -1)
     11                "keyword without space after it
     12        call matchadd('Search', '[a-zA-Z0-9][,=>+\-*;][a-zA-Z0-9]', -1)
     13                "operator without space around it (without false positive on
     14                "templated<type>)
     15        call matchadd('Search', '^[^#].*[^<][a-zA-Z0-9]*/[a-zA-Z0-9]', -1)
     16                "operator without space around it (without false positive on
     17                "#include <dir/file.h>)
     18        call matchadd('Search', '^[^/]\{2}.*[^*][=/+\- ]$', -1)
     19                "operator at end of line (without false positives on /* and */, nor
     20                "char*\nClass::method())
     21        call matchadd('Search', '\s$', -1) "Spaces at end of line
     22        call matchadd('Search', ',\S', -1) " Missing space after comma
     23:endfu
     24}}}
     25
     26== Calling the scrip ==
     27
     28The obvious way to enable the script is to do it by hand :
     29{{{
     30:call FuncHaikuCheck()
     31}}}
     32
     33It is also possible to make it run on every opened file (this is a bit annoying when using vim for something else than Haiku or C++ files)
     34{{{
    535" autocmd that will set up the w:created variable (vim tip 1598)
    636" so we can run the check only once per window
    737autocmd VimEnter * autocmd WinEnter * let w:created=1
    8 
    9 :fu FuncHaikuCheck()
    10         call matchadd('Search', '\%>80v.\+', -1) " line with more than 80 chars
    11         call matchadd('Search', '  ', -1)        " probably wrong indenting
    12         call matchadd('Search', '\(for\|if\|select\|while\)(', -1) "keyword without space after it
    13         call matchadd('Search', '[a-zA-Z0-9][,=>/+\-*;][a-zA-Z0-9]', -1) "operator without space around it (without template_d<t_ype>)
    14         call matchadd('Search', '[^*][=/+\- ]$', -1) "operator at end of line (without false positives on char*\nclass::method(), /* and */)
    15 :endfu
    1638
    1739" call the function on all opened files
     
    2042}}}
    2143
     44The last option is to define a keyboard shortcut to enable it (control+F3 in this example) :
     45{{{
     46map <C-F3> :call FuncHaikuCheck()<CR>
     47}}}
     48
    2249These rules have been ported to a standalone python program see the Style Checker Tools paragraph in the [http://www.haiku-os.org/development/coding-guidelines Haiku coding guidelines] and  [http://dev.haiku-os.org/browser/haiku/trunk/src/tools/checkstyle/ src/tools/checkstyle/]