[ << Programming work ] | [Top][Contents][Index][ ? ] | [ Release work >> ] | ||
[ < Filenames ] | [ Up : Code style ] | [ Naming conventions > ] |
10.5.3 Indentation
Standard GNU coding style is used.
Indenting files with fixcc.py
(recommended)
LilyPond provides a python script that will adjust the indentation
and spacing on a .cc
or .hh
file to very near the
GNU standard:
scripts/auxiliar/fixcc.py FILENAME
This can be run on all files at once, but this is not recommended for normal contributors or developers.
scripts/auxiliar/fixcc.py \ $(find flower lily -name '*cc' -o -name '*hh' | grep -v /out) |
Indenting with emacs
The following hooks will produce indentation which is similar to
our official indentation as produced with fixcc.py
.
(add-hook 'c++-mode-hook '(lambda () (c-set-style "gnu") (setq indent-tabs-mode nil))
If you like using font-lock, you can also add this to your ‘.emacs’:
(setq font-lock-maximum-decoration t) (setq c++-font-lock-keywords-3 (append c++-font-lock-keywords-3 '(("\\b\\(a-zA-Z_?+_\\)\\b" 1 font-lock-variable-name-face) ("\\b\\(A-Z?+a-z_?+\\)\\b" 1 font-lock-type-face)) ))
Indenting with vim
Although emacs indentation is the GNU standard, acceptable indentation can usually be accomplished with vim. Some hints for vim are as follows:
A workable .vimrc:
set cindent set smartindent set autoindent set expandtab set softtabstop=2 set shiftwidth=2 filetype plugin indent on set incsearch set ignorecase smartcase set hlsearch set confirm set statusline=%F%m%r%h%w\ %{&ff}\ %Y\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ %04l,%04v\ %p%%\ [LEN=%L] set laststatus=2 set number " Remove trailing whitespace on write autocmd BufWritePre * :%s/\s\+$//e
With this ‘.vimrc’, files can be reindented automatically by
highlighting the lines to be indented in visual mode (use V to
enter visual mode) and pressing =
.
A ‘scheme.vim’ file will help improve the indentation. This one was suggested by Patrick McCarty. It should be saved in ‘~/.vim/after/syntax/scheme.vim’.
" Additional Guile-specific 'forms' syn keyword schemeSyntax define-public define*-public syn keyword schemeSyntax define* lambda* let-keywords* syn keyword schemeSyntax defmacro defmacro* define-macro syn keyword schemeSyntax defmacro-public defmacro*-public syn keyword schemeSyntax use-modules define-module syn keyword schemeSyntax define-method define-class " Additional LilyPond-specific 'forms' syn keyword schemeSyntax define-markup-command define-markup-list-command syn keyword schemeSyntax define-safe-public define-music-function syn keyword schemeSyntax def-grace-function " All of the above should influence indenting too set lw+=define-public,define*-public set lw+=define*,lambda*,let-keywords* set lw+=defmacro,defmacro*,define-macro set lw+=defmacro-public,defmacro*-public set lw+=use-modules,define-module set lw+=define-method,define-class set lw+=define-markup-command,define-markup-list-command set lw+=define-safe-public,define-music-function set lw+=def-grace-function " These forms should not influence indenting set lw-=if set lw-=set! " Try to highlight all ly: procedures syn match schemeFunc "ly:[^) ]\+"
[ << Programming work ] | [Top][Contents][Index][ ? ] | [ Release work >> ] | ||
[ < Filenames ] | [ Up : Code style ] | [ Naming conventions > ] |