diff options
author | obrien <obrien@FreeBSD.org> | 2008-03-13 18:52:46 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2008-03-13 18:52:46 +0000 |
commit | f8c1190baa7d68cb6f8d7d2938712ba4eea1dc41 (patch) | |
tree | 5f62b950895853ad3f759495b6d8fc430f1266b9 | |
parent | eb28d343694630e2b05e86c536d472e1be22ba2e (diff) | |
download | FreeBSD-src-f8c1190baa7d68cb6f8d7d2938712ba4eea1dc41.zip FreeBSD-src-f8c1190baa7d68cb6f8d7d2938712ba4eea1dc41.tar.gz |
Vim function to style(9).
Issue ':call FreeBSD_Style()' while editing a file.
Submitted by: scf
-rw-r--r-- | tools/tools/editing/freebsd.vim | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/tools/editing/freebsd.vim b/tools/tools/editing/freebsd.vim new file mode 100644 index 0000000..4ec27ad --- /dev/null +++ b/tools/tools/editing/freebsd.vim @@ -0,0 +1,68 @@ +" Copyright (c) 2007-2008 Sean C. Farley <scf@FreeBSD.org> +" All rights reserved. +" +" Redistribution and use in source and binary forms, with or without +" modification, are permitted provided that the following conditions +" are met: +" 1. Redistributions of source code must retain the above copyright +" notice, this list of conditions and the following disclaimer, +" without modification, immediately at the beginning of the file. +" 2. Redistributions in binary form must reproduce the above copyright +" notice, this list of conditions and the following disclaimer in the +" documentation and/or other materials provided with the distribution. +" +" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +" +" $FreeBSD$ + +" This is a plugin for Vim (tested with Vim v7.1) to follow the FreeBSD style(9) +" indentation. It registers a macro (see below) for changing a buffer's +" indentation rules but does not change the indentation of existing code. + +" Load only once. +if exists('loaded_FreeBSD') + finish +endif +let loaded_FreeBSD = 1 + + +" FreeBSD mapping to switch current buffer to style(9). This is generally '\f'. +nmap <silent> <Leader>f :call FreeBSD_Style()<CR> + + +" Ignore indents caused by parentheses in FreeBSD style. +function! IgnoreParenIndent() + let indent = cindent(v:lnum) + + if indent > 4000 + if cindent(v:lnum - 1) > 4000 + return indent(v:lnum - 1) + else + return indent(v:lnum - 1) + 4 + endif + else + return (indent) + endif +endfun + + +" Follow the FreeBSD style(9). +function! FreeBSD_Style() + setlocal cindent + setlocal cinoptions=(4200,u4200,+0.5s,*500,t0,U4200 + setlocal indentexpr=IgnoreParenIndent() + setlocal indentkeys=0{,0},0),:,0#,!^F,o,O,e + setlocal noexpandtab + setlocal shiftwidth=8 + setlocal tabstop=8 + setlocal textwidth=80 +endfun |