We mainly use the same rules as the KDE-project. One exception is that we allow multiple statements and variables per line.
Tabs and Indentation
We expand tabs and use (
tabstop = 4 shiftwidth = 4 expandtab
which means that a tab is equal to 4 spaces and the next source code block is indented by 4 spaces.
Avoid trailing whitespaces:
There is a nice
which can remove trailing whitespaces on save using
autocmd BufEnter * EnableStripWhitespaceOnSave
Code Style Checking
We use the krazy Code Checker from
KDE to make sure that the style rules are not violated.
Here are some examples how to use this tool in practise
# run crazy to all on current folder and write reults to tofix.txt krazy2all --exclude copyright,includes --exclude-types cmake,python,kpartgui --extra crud,style,contractions --check-sets foss,c++ --export textedit | grep -v "Multiple statements on 1 line" | tee ~/tofix.txt # tofix.txt can be loaded using vim -q and use `:w | cn` to step through the list of style issues vim -q ~/tofix.txt
# checking single files only krazy2 --explain --exclude copyright,includes --exclude-types cmake,python,kpartgui --extra crud,style,contractions --check-sets foss,c++ freelist.c
Macro and Multiline Issues
If possible consider using the Do-While Multiline Macro Wrapping.
Astyle and Automatic Code Formatting
scripts/astyle-cmess executes the Artistic Style and some
It tries to fix code style issues automatically.