On 09/16/2014 08:38 PM, Yury Gribov wrote:
Hi all,
This is the third version of the patch. A list of changes since last
version:
* move config to contrib so that it's _not_ enabled by default (current
score is 2/1 in favor of no Vim config by default)
* update Makefile.in to make .local.vimrc if developer asks for it
* disable autoformatting for flex files
* fix filtering of non-GNU sources (libsanitizer)
* added some small fixes in cinoptions based on feedback from community
As noted by Richard, the config does not do a good job of formatting
unbound {} blocks e.g.
void
foo ()
{
int x;
{
// I'm an example of bad bad formatting
}
}
but it seems to be the best we can get with Vim's cindent
(and I don't think anyone seriously considers writing a custom indentexpr).
Ok to commit?
-Y
New vesion with support for another popular local .vimrc plugin.
-Y
commit fa7d6c68b0eb8763333aef6c22e4c88aa82db05e
Author: Yury Gribov <y.gri...@samsung.com>
Date: Thu Sep 4 16:55:44 2014 +0400
2014-09-17 Laurynas Biveinis <laurynas.bivei...@gmail.com>
Yury Gribov <y.gri...@samsung.com>
Vim config with GNU formatting.
contrib/
* vimrc: New file.
/
* .gitignore: Added .local.vimrc and .lvimrc.
* Makefile.tpl (.local.vimrc): New target.
* Makefile.in: Regenerate.
diff --git a/.gitignore b/.gitignore
index e9b56be..ab97ac6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,6 +32,9 @@ POTFILES
TAGS
TAGS.sub
+.local.vimrc
+.lvimrc
+
.gdbinit
.gdb_history
diff --git a/Makefile.in b/Makefile.in
index d6105b3..1be75b7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -2384,6 +2384,11 @@ mail-report-with-warnings.log: warning.log
chmod +x $@
echo If you really want to send e-mail, run ./$@ now
+# Local Vim config
+
+vimrc:
+ (cd $(srcdir); $(LN_S) contrib/vimrc .local.vimrc; $(LN_S) contrib/vimrc .lvimrc)
+
# Installation targets.
.PHONY: install uninstall
diff --git a/Makefile.tpl b/Makefile.tpl
index f7c7e38..ee2321f 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -867,6 +867,11 @@ mail-report-with-warnings.log: warning.log
chmod +x $@
echo If you really want to send e-mail, run ./$@ now
+# Local Vim config
+
+vimrc:
+ (cd $(srcdir); $(LN_S) contrib/vimrc .local.vimrc; $(LN_S) contrib/vimrc .lvimrc)
+
# Installation targets.
.PHONY: install uninstall
diff --git a/contrib/vimrc b/contrib/vimrc
new file mode 100644
index 0000000..88e77a6
--- /dev/null
+++ b/contrib/vimrc
@@ -0,0 +1,45 @@
+" Code formatting settings for Vim.
+"
+" To enable this for GCC files by default, install thinca's vim-localrc
+" plugin and do
+" $ make .local.vimrc
+" Or install Markus Braun's localvimrc and do
+" $ make .lvimrc
+" Or if you dislike plugins, add autocmd in your ~/.vimrc:
+" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc
+" Or just source file manually every time if you are masochist:
+" :so path/to/gcc/contrib/vimrc
+"
+" Copyright (C) 2014 Free Software Foundation, Inc.
+"
+" This program is free software; you can redistribute it and/or modify
+" it under the terms of the GNU General Public License as published by
+" the Free Software Foundation; either version 3 of the License, or
+" (at your option) any later version.
+"
+" This program is distributed in the hope that it will be useful,
+" but WITHOUT ANY WARRANTY; without even the implied warranty of
+" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+" GNU General Public License for more details.
+"
+" You should have received a copy of the GNU General Public License
+" along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+function! SetStyle()
+ let l:fname = expand("%:p")
+ if stridx(l:fname, 'libsanitizer') != -1
+ return
+ endif
+ let l:ext = fnamemodify(l:fname, ":e")
+ let l:c_exts = ['c', 'h', 'cpp', 'cc', 'C', 'H', 'def', 'java']
+ if index(l:c_exts, l:ext) != -1
+ setlocal cindent
+ setlocal shiftwidth=2
+ setlocal softtabstop=2
+ setlocal cinoptions=>2s,n-s,{s,^-s,:s,=s,g0,f0,hs,p2s,t0,+s,(0,u0,w1,m0
+ setlocal textwidth=79
+ setlocal formatoptions-=ro formatoptions+=cql
+ endif
+endfunction
+
+call SetStyle()