* Vimrc config with GNU formatting @ 2014-09-04 13:06 Yury Gribov 2014-09-04 13:22 ` Richard Biener 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov 0 siblings, 2 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-04 13:06 UTC (permalink / raw) To: GCC Patches; +Cc: Laurynas Biveinis, Jeff Law [-- Attachment #1: Type: text/plain, Size: 316 bytes --] Hi all, This patch adds a Vim config (.local.vimrc) to root folder. This would allow automatic setup of GNU formatting for C/C++/Java/Lex files in GCC (similar to what we already have for Emacs via .dir-locals.el). The formatting is borrowed from https://gcc.gnu.org/wiki/FormattingCodeForGCC Ok to commit? -Y [-- Attachment #2: local-vimrc-1.diff --] [-- Type: text/x-diff, Size: 1714 bytes --] commit dd961868f625f2f3b3ac9c4349284904cdd56ad1 Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Sep 4 16:55:44 2014 +0400 2014-09-04 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> * .local.vimrc: New file. diff --git a/.local.vimrc b/.local.vimrc new file mode 100644 index 0000000..58e6ad3 --- /dev/null +++ b/.local.vimrc @@ -0,0 +1,36 @@ +" Vim settings. +" +" To autorun install thinca's localrc plugin. Otherwise just source via +" :so .local.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() +" TODO: filter out non-GNU sources e.g. libsanitizer? +let l:fname = expand("%:p") +let l:ext = fnamemodify(l:fname, ":e") +let l:c_exts = [ 'c', 'h', 'cpp', 'cc', 'C', 'H', 'def', 'java', 'l' ] +if index(l:c_exts, l:ext) != -1 + setlocal cindent + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 + setlocal shiftwidth=2 + setlocal softtabstop=2 + setlocal textwidth=79 + setlocal fo-=ro fo+=cql +endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-04 13:06 Vimrc config with GNU formatting Yury Gribov @ 2014-09-04 13:22 ` Richard Biener 2014-09-04 20:23 ` Bernhard Reutner-Fischer 2014-09-05 15:04 ` Yury Gribov 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov 1 sibling, 2 replies; 44+ messages in thread From: Richard Biener @ 2014-09-04 13:22 UTC (permalink / raw) To: Yury Gribov; +Cc: GCC Patches, Laurynas Biveinis, Jeff Law On Thu, Sep 4, 2014 at 3:06 PM, Yury Gribov <y.gribov@samsung.com> wrote: > Hi all, > > This patch adds a Vim config (.local.vimrc) to root folder. This would allow > automatic setup of GNU formatting for C/C++/Java/Lex files in GCC (similar > to what we already have for Emacs via .dir-locals.el). The formatting is > borrowed from https://gcc.gnu.org/wiki/FormattingCodeForGCC > > Ok to commit? For some reason I use set shiftwidth=4 set tabstop=8 set autoindent set cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s I note some differences to your + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 ... + setlocal shiftwidth=2 Not that I can parse any of the above without looking up vim docs ;) Richard. > -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-04 13:22 ` Richard Biener @ 2014-09-04 20:23 ` Bernhard Reutner-Fischer 2014-09-05 15:10 ` Yury Gribov 2014-09-05 15:04 ` Yury Gribov 1 sibling, 1 reply; 44+ messages in thread From: Bernhard Reutner-Fischer @ 2014-09-04 20:23 UTC (permalink / raw) To: Richard Biener; +Cc: Yury Gribov, GCC Patches, Laurynas Biveinis, Jeff Law On Thu, Sep 04, 2014 at 03:22:15PM +0200, Richard Biener wrote: > On Thu, Sep 4, 2014 at 3:06 PM, Yury Gribov <y.gribov@samsung.com> wrote: > > Hi all, > > > > This patch adds a Vim config (.local.vimrc) to root folder. This would allow > > automatic setup of GNU formatting for C/C++/Java/Lex files in GCC (similar > > to what we already have for Emacs via .dir-locals.el). The formatting is > > borrowed from https://gcc.gnu.org/wiki/FormattingCodeForGCC > > > > Ok to commit? > > For some reason I use > > set shiftwidth=4 > set tabstop=8 > set autoindent > set cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s > > I note some differences to your > > + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 > ... > + setlocal shiftwidth=2 > > Not that I can parse any of the above without looking up vim docs ;) Yuri, Not sure from whom i borrowed this, perhaps even from you richi, but the gcc_style.vim pasted in the mail below seems to be floating around ;) https://gcc.gnu.org/ml/gcc-patches/2012-12/msg01228.html This automatically applies the "gcc style" if the first 25 lines of the file being opened contains the syndicated "This file is part of GCC" so should transparently not set GNU style on foreign stuff like sanitizer. HTH.. cheers, ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-04 20:23 ` Bernhard Reutner-Fischer @ 2014-09-05 15:10 ` Yury Gribov 2014-09-05 16:46 ` Bernhard Reutner-Fischer 2014-09-05 17:35 ` Segher Boessenkool 0 siblings, 2 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-05 15:10 UTC (permalink / raw) To: Bernhard Reutner-Fischer, Richard Biener Cc: GCC Patches, Laurynas Biveinis, Jeff Law On 09/05/2014 12:22 AM, Bernhard Reutner-Fischer wrote: > Not sure from whom i borrowed this, perhaps even from you richi, but the > gcc_style.vim pasted in the mail below seems to be floating around ;) > > https://gcc.gnu.org/ml/gcc-patches/2012-12/msg01228.html Nice! Interestingly enough this gives same results with my settings (or at least I was not able to spot any difference). Formatting of comments is still different though (mine are wrapped at 80-th column). Now I don't quite like the idea of plugin: * .local.vimrc setting is more compatible with what we already have for Emacs * gcc_style.vim won't work for new files (it requires GCC license agreement) * gcc_style.vim enables GNU style globally, for all projects IMHO localrc plugin is widespread enough that we can rely on it. > This automatically applies the "gcc style" if the first 25 lines of the > file being opened contains the syndicated "This file is part of GCC" so > should transparently not set GNU style on foreign stuff like sanitizer. But as I mentioned also disables formatting for all new files. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-05 15:10 ` Yury Gribov @ 2014-09-05 16:46 ` Bernhard Reutner-Fischer 2014-09-06 16:33 ` Yury Gribov 2014-09-05 17:35 ` Segher Boessenkool 1 sibling, 1 reply; 44+ messages in thread From: Bernhard Reutner-Fischer @ 2014-09-05 16:46 UTC (permalink / raw) To: Yury Gribov; +Cc: Richard Biener, GCC Patches, Laurynas Biveinis, Jeff Law On 5 September 2014 17:10, Yury Gribov <y.gribov@samsung.com> wrote: > Now I don't quite like the idea of plugin: > * .local.vimrc setting is more compatible with what we already have for > Emacs > * gcc_style.vim won't work for new files (it requires GCC license agreement) true > * gcc_style.vim enables GNU style globally, for all projects How come? Please explain? > > IMHO localrc plugin is widespread enough that we can rely on it. Sure. > >> This automatically applies the "gcc style" if the first 25 lines of the >> file being opened contains the syndicated "This file is part of GCC" so >> should transparently not set GNU style on foreign stuff like sanitizer. > > > But as I mentioned also disables formatting for all new files. Yes, you could if match(expand('%:p:h'), "gcc") != -1 or something like that but that's not pretty and robust either. So I suppose the localrc idea is fine cheers, ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-05 16:46 ` Bernhard Reutner-Fischer @ 2014-09-06 16:33 ` Yury Gribov 0 siblings, 0 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-06 16:33 UTC (permalink / raw) To: gcc-patches Bernhard Reutner-Fischer <rep.dot.nop <at> gmail.com> writes: > > * gcc_style.vim enables GNU style globally, for all projects > > How come? Please explain? My understanding was that maybe_gcc_style gets run on all opened files and this could cause problems with non-GCC projects. But given that you check for GCC comment it's probably not an issue. > > But as I mentioned also disables formatting for all new files. > > Yes, you could if match(expand('%:p:h'), "gcc") != -1 > or something like that but that's not pretty and robust either. Yeah, and we'll also want GNU coding style in GCC runtime libs (libbacktrace, etc.) so filtering may get quite messy. ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-05 15:10 ` Yury Gribov 2014-09-05 16:46 ` Bernhard Reutner-Fischer @ 2014-09-05 17:35 ` Segher Boessenkool 2014-09-06 15:40 ` Yury Gribov 1 sibling, 1 reply; 44+ messages in thread From: Segher Boessenkool @ 2014-09-05 17:35 UTC (permalink / raw) To: Yury Gribov Cc: Bernhard Reutner-Fischer, Richard Biener, GCC Patches, Laurynas Biveinis, Jeff Law On Fri, Sep 05, 2014 at 07:10:02PM +0400, Yury Gribov wrote: > Now I don't quite like the idea of plugin: Anything that will make this enabled automatically will meet a lot of resistance. Make something nice for contrib/ instead? Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-05 17:35 ` Segher Boessenkool @ 2014-09-06 15:40 ` Yury Gribov 2014-09-06 18:21 ` Trevor Saunders 2014-09-06 19:35 ` Segher Boessenkool 0 siblings, 2 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-06 15:40 UTC (permalink / raw) To: gcc-patches Segher Boessenkool <segher <at> kernel.crashing.org> writes: > On Fri, Sep 05, 2014 at 07:10:02PM +0400, Yury Gribov wrote: > > Now I don't quite like the idea of plugin: > > Anything that will make this enabled automatically will meet a lot of > resistance. Make something nice for contrib/ instead? Hm, isn't it already enabled by default for Emacs (in .dirs-local.el)? Also GNU coding style is a requirement for GCC so resisting it may not make sense... -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-06 15:40 ` Yury Gribov @ 2014-09-06 18:21 ` Trevor Saunders 2014-09-06 19:35 ` Segher Boessenkool 1 sibling, 0 replies; 44+ messages in thread From: Trevor Saunders @ 2014-09-06 18:21 UTC (permalink / raw) To: Yury Gribov; +Cc: gcc-patches On Sat, Sep 06, 2014 at 03:38:31PM +0000, Yury Gribov wrote: > Segher Boessenkool <segher <at> kernel.crashing.org> writes: > > On Fri, Sep 05, 2014 at 07:10:02PM +0400, Yury Gribov wrote: > > > Now I don't quite like the idea of plugin: > > > > Anything that will make this enabled automatically will meet a lot of > > resistance. Make something nice for contrib/ instead? > > Hm, isn't it already enabled by default for Emacs (in .dirs-local.el)? Also > GNU coding style is a requirement for GCC so resisting it may not make > sense... If you went the localrc route I think it would be kind of crazy for people to enable loading of local config files and then complain when projects make use of that, since that's the major use case for the plugin in the first place. Trev > > -Y > ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-06 15:40 ` Yury Gribov 2014-09-06 18:21 ` Trevor Saunders @ 2014-09-06 19:35 ` Segher Boessenkool 2014-09-07 4:18 ` Yuri Gribov 1 sibling, 1 reply; 44+ messages in thread From: Segher Boessenkool @ 2014-09-06 19:35 UTC (permalink / raw) To: Yury Gribov; +Cc: gcc-patches On Sat, Sep 06, 2014 at 03:38:31PM +0000, Yury Gribov wrote: > Segher Boessenkool <segher <at> kernel.crashing.org> writes: > > On Fri, Sep 05, 2014 at 07:10:02PM +0400, Yury Gribov wrote: > > > Now I don't quite like the idea of plugin: > > > > Anything that will make this enabled automatically will meet a lot of > > resistance. Make something nice for contrib/ instead? > > Hm, isn't it already enabled by default for Emacs (in .dirs-local.el)? That may well be. But Vim is not Emacs. > Also > GNU coding style is a requirement for GCC so resisting it may not make > sense... I'm not resisting GNU coding style. I am resisting scripts and/or other configuration things that make my editor do something else than what I tell it to do. If I type enter in insert mode, the cursor should go to column one in a newly opened line, not "helpfully" to e.g. four spaces in. Because I will bloody well type four spaces anyway. Etc. Not to mention the horrors it will do in a machine description file. This all should be opt-in. As it already is. If you can give some suggested config for other users, that's marvellous, it will probably be helpful to some. Changing the config for everyone is quite the opposite of helpful. Segher p.s. At least you're not forcing syntax hilighting on ;-) ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-06 19:35 ` Segher Boessenkool @ 2014-09-07 4:18 ` Yuri Gribov 2014-09-07 4:48 ` Yuri Gribov 2014-09-07 13:33 ` Segher Boessenkool 0 siblings, 2 replies; 44+ messages in thread From: Yuri Gribov @ 2014-09-07 4:18 UTC (permalink / raw) To: Segher Boessenkool; +Cc: GCC Patches Replying to all this time. On Sat, Sep 6, 2014 at 11:35 PM, Segher Boessenkool <segher@kernel.crashing.org> wrote: >> Hm, isn't it already enabled by default for Emacs (in .dirs-local.el)? > > That may well be. But Vim is not Emacs. Why is Vim special? As a developer I'd prefer the unified approach: either nuke both or move them to contrib or make them default. >> Also >> GNU coding style is a requirement for GCC so resisting it may not make >> sense... > > I'm not resisting GNU coding style. I am resisting scripts and/or other > configuration things that make my editor do something else than what I tell > it to do. If I type enter in insert mode, the cursor should go to column > one in a newly opened line, not "helpfully" to e.g. four spaces in. Two spaces in GNU standard. > Because > I will bloody well type four spaces anyway. Well, good luck with a deeply nested constructs where GNU wants a weird mix of tabs and spaces which developers get wrong every time (unless they remember to run sed on their patches which they normally don't). > Etc. Not to mention the horrors > it will do in a machine description file. Indenting is only enabled for C, C++ and Java and .def. Md's and other stuff is untouched (hmm, .md is interesting). > This all should be opt-in. As it already is. Not for other editors... > If you can give some suggested > config for other users, that's marvellous, it will probably be helpful to > some. Changing the config for everyone is quite the opposite of helpful. Let's see what other hackers say. > p.s. At least you're not forcing syntax hilighting on ;-) Noo, this is too personal. ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-07 4:18 ` Yuri Gribov @ 2014-09-07 4:48 ` Yuri Gribov 2014-09-07 13:33 ` Segher Boessenkool 1 sibling, 0 replies; 44+ messages in thread From: Yuri Gribov @ 2014-09-07 4:48 UTC (permalink / raw) To: Segher Boessenkool; +Cc: GCC Patches On Sun, Sep 7, 2014 at 8:18 AM, Yuri Gribov <tetra2005@gmail.com> wrote: > Replying to all this time. > > On Sat, Sep 6, 2014 at 11:35 PM, Segher Boessenkool > <segher@kernel.crashing.org> wrote: >>> Hm, isn't it already enabled by default for Emacs (in .dirs-local.el)? >> >> That may well be. But Vim is not Emacs. > > Why is Vim special? As a developer I'd prefer the unified approach: > either nuke both or move them to contrib or make them default. And of course the setting can be easily turned off on user's side by removing the config. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-07 4:18 ` Yuri Gribov 2014-09-07 4:48 ` Yuri Gribov @ 2014-09-07 13:33 ` Segher Boessenkool 1 sibling, 0 replies; 44+ messages in thread From: Segher Boessenkool @ 2014-09-07 13:33 UTC (permalink / raw) To: Yuri Gribov; +Cc: GCC Patches On Sun, Sep 07, 2014 at 08:18:39AM +0400, Yuri Gribov wrote: > >> Hm, isn't it already enabled by default for Emacs (in .dirs-local.el)? > > > > That may well be. But Vim is not Emacs. > > Why is Vim special? Because you are changing the editor behaviour for Vim users. Duh. > > This all should be opt-in. As it already is. > > Not for other editors... It seems since a few months it is not for Emacs, yes. I don't use emacs; I don't care. > > If you can give some suggested > > config for other users, that's marvellous, it will probably be helpful to > > some. Changing the config for everyone is quite the opposite of helpful. > > Let's see what other hackers say. Sure. > > p.s. At least you're not forcing syntax hilighting on ;-) > > Noo, this is too personal. That only changes the colours on my screen. You are proposing changing what my editor does when I press the basic editing keys. MUCH more personal! Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: Vimrc config with GNU formatting 2014-09-04 13:22 ` Richard Biener 2014-09-04 20:23 ` Bernhard Reutner-Fischer @ 2014-09-05 15:04 ` Yury Gribov 1 sibling, 0 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-05 15:04 UTC (permalink / raw) To: Richard Biener; +Cc: GCC Patches, Laurynas Biveinis, Jeff Law On 09/04/2014 05:22 PM, Richard Biener wrote: > For some reason I use > > set shiftwidth=4 > set tabstop=8 > set autoindent > set cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s > > I note some differences to your > > + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1 Ah, the vimfu. So the differences seem to boil down to 1) your config uses autoindent (mine does cindent) 2) my (well, Laurynas's) cinoptions additionally include >4,:2,=2,h2,+2,u0,w1,m1 3) your config sets tabstop whereas mine uses softtabstop 4) formatoptions cause autowrapping of comments at 80-th column I'm not sure about 1), but 2) allows: * case labels start under parent { * correct indent on line break (should be 2, not 4) which seem to match current GCC style. Also due to 3) issuing a tab expands to 2 spaces instead of real tab which is probably a Good Thing. Your settings beat mine at m1 though - it should be removed to allow vim to match closing ) with opening. So I'd say that in general proposed patch handles more cases (with removed m1). -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv2] Vimrc config with GNU formatting 2014-09-04 13:06 Vimrc config with GNU formatting Yury Gribov 2014-09-04 13:22 ` Richard Biener @ 2014-09-10 8:09 ` Yury Gribov 2014-09-10 8:17 ` Yury Gribov ` (3 more replies) 1 sibling, 4 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-10 8:09 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 789 bytes --] Hi all, This is a second version of patch which adds a Vim config (.local.vimrc) to root folder to allow automatic setup of GNU formatting for C/C++/Java/Lex GCC files. I've updated the code with comments from Richard and Bernhard (which fixed formatting of lonely closing bracket). The patch caused a lively debate with Segher who wanted .local.vimrc to not be enabled by default. We basically have two options: 1) put .local.vimrc to root (just like .dir-locals.el config for Emacs) 2) put both .local.vimrc and .dir-locals.el to contrib and add Makefile targets to create symlinks in root folder per user's request I personally prefer 2) because this would IMHO improve the quality of patches (e.g. no more silly tab-whitespace formatting bugs). Thoughts? Ok to commit? -Y [-- Attachment #2: local-vimrc-2.diff --] [-- Type: text/x-diff, Size: 1785 bytes --] commit 879cd3e9bdcab780a9b96aff759ef684e3597d0c Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Sep 4 16:55:44 2014 +0400 2014-09-10 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> * .local.vimrc: New file. diff --git a/.local.vimrc b/.local.vimrc new file mode 100644 index 0000000..98f3135 --- /dev/null +++ b/.local.vimrc @@ -0,0 +1,39 @@ +" Vim settings. +" +" To autorun install thinca's localrc plugin. Otherwise just source via +" :so .local.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") + let l:non_gnu_dirs = ['libsanitizer'] + if index(l:non_gnu_dirs, l:fname) != -1 + return + endif + let l:ext = fnamemodify(l:fname, ":e") + let l:c_exts = ['c', 'h', 'cpp', 'cc', 'C', 'H', 'def', 'java', 'l'] + 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,hs,p5,t0,+s,(0,u0,w1,m0 + setlocal textwidth=79 + setlocal fo-=ro fo+=cql + endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov @ 2014-09-10 8:17 ` Yury Gribov 2014-09-10 19:17 ` Segher Boessenkool ` (2 subsequent siblings) 3 siblings, 0 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-10 8:17 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump > I personally prefer 2) Sorry, I meant 1) of course that is enable vimrc config by default. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov 2014-09-10 8:17 ` Yury Gribov @ 2014-09-10 19:17 ` Segher Boessenkool 2014-09-11 4:47 ` Yury Gribov 2014-09-11 9:06 ` Richard Biener 2014-09-16 16:38 ` [PATCHv3] " Yury Gribov 3 siblings, 1 reply; 44+ messages in thread From: Segher Boessenkool @ 2014-09-10 19:17 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Wed, Sep 10, 2014 at 12:09:25PM +0400, Yury Gribov wrote: > The patch caused a lively debate with Segher who wanted .local.vimrc to > not be enabled > by default. No, that is not what I said. I am saying it is very anti-social to make people's editor behave differently from what they are used to. Wars have been started for much less. But there are more problems with your approach. First, you are encouraging the use of a plugin that is a gaping wide security hole. I do not think GCC should encourage this. Secondly, this is a very poor imitation of the mechanism Vim has for dealing with filetypes, namely, ftplugins. > We basically have two options: > 1) put .local.vimrc to root (just like .dir-locals.el config for Emacs) > 2) put both .local.vimrc and .dir-locals.el to contrib and add Makefile > targets > to create symlinks in root folder per user's request As I said before, Emacs is not Vim. The Emacs dir-locals file simply configures some settings for files with certain major modes in that dir. For example, ours says that c-mode files should use GNU style. This is quite harmless, and probably what most Emacs users want. Your script on the other hand does something totally different: it overrides a bunch of settings the user has made elsewhere. [Snipped some overly optimistic stuff about this all increasing the quality of posted patches. Hint: the most frequently made formatting error is forgetting to put two spaces at the end of a sentence. Which this script does not handle at all (I'm not saying it should, it is hard to do reliably). The patch itself however does introduce another one of these.] Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-10 19:17 ` Segher Boessenkool @ 2014-09-11 4:47 ` Yury Gribov 2014-09-11 9:14 ` pinskia 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-09-11 4:47 UTC (permalink / raw) To: gcc-patches Segher Boessenkool <segher <at> kernel.crashing.org> writes: > I am saying it is very anti-social to make > people's editor behave differently from what they are used to. > ... > The Emacs dir-locals file simply > configures some settings for files with certain major modes in that dir. > For example, ours says that c-mode files should use GNU style. This is > quite harmless, and probably what most Emacs users want. Hm, so autoformatting in Emacs is good because that's what most users want but autoformatting in Vim is bad because that's not what people are used to? > First, you are encouraging > the use of a plugin that is a gaping wide security hole. I don't think so. The comment mentions that user can either install a (rather widespread btw) plugin or just call config from his .vimrc. > Secondly, this is a very poor imitation of the mechanism Vim has for dealing > with filetypes, namely, ftplugins. I'm ready to accept technical suggestions on how to do the thing properly. So what exactly do you propose? > [Snipped some overly optimistic stuff about this all increasing the quality > of posted patches. Hint: the most frequently made formatting error is > forgetting to put two spaces at the end of a sentence. Dunno, I was relying on personal experience. And searching for "two|2 spaces" on http://gcc.gnu.org/ml/gcc-patches returns 2000 results whereas "eight|8 spaces" only 700. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-11 4:47 ` Yury Gribov @ 2014-09-11 9:14 ` pinskia 2014-09-11 9:35 ` Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: pinskia @ 2014-09-11 9:14 UTC (permalink / raw) To: Yury Gribov; +Cc: gcc-patches > On Sep 10, 2014, at 9:47 PM, Yury Gribov <tetra2005@gmail.com> wrote: > > Segher Boessenkool <segher <at> kernel.crashing.org> writes: >> I am saying it is very anti-social to make >> people's editor behave differently from what they are used to. >> ... >> The Emacs dir-locals file simply >> configures some settings for files with certain major modes in that > dir. >> For example, ours says that c-mode files should use GNU style. This > is >> quite harmless, and probably what most Emacs users want. > > Hm, so autoformatting in Emacs is good because that's what most users > want but autoformatting in Vim is bad because that's not what people are > used to? I don't like auto formatting in any editor. Though I don't use emacs, I use vim. I think using auto formatting is cheating and not understanding why coding styles exists. And some folks already have to deal with two more formatting styles already: Linux kernel and gnu. So if you add auto formatting to one, some folks are going to get confused. Thanks, Andrew > >> First, you are encouraging >> the use of a plugin that is a gaping wide security hole. > > I don't think so. The comment mentions that user can either install a > (rather widespread btw) plugin or just call config from his .vimrc. > >> Secondly, this is a very poor imitation of the mechanism Vim has for > dealing >> with filetypes, namely, ftplugins. > > I'm ready to accept technical suggestions on how to do the thing > properly. So what exactly do you propose? > >> [Snipped some overly optimistic stuff about this all increasing the > quality >> of posted patches. Hint: the most frequently made formatting error is >> forgetting to put two spaces at the end of a sentence. > > Dunno, I was relying on personal experience. And searching for "two|2 > spaces" on http://gcc.gnu.org/ml/gcc-patches returns 2000 results > whereas "eight|8 spaces" only 700. > > -Y > ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-11 9:14 ` pinskia @ 2014-09-11 9:35 ` Yury Gribov 0 siblings, 0 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-11 9:35 UTC (permalink / raw) To: pinskia, Yury Gribov; +Cc: gcc-patches On 09/11/2014 01:14 PM, pinskia@gmail.com wrote: > I don't like auto formatting in any editor. Ok, so +1 for moving to contrib/. > And some folks already have to deal with two more formatting styles already: > Linux kernel and gnu. So if you add auto formatting to one, >some folks are going to get confused. This config will only turn on autoformatting for GCC sources. It's not going to influence other directories. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov 2014-09-10 8:17 ` Yury Gribov 2014-09-10 19:17 ` Segher Boessenkool @ 2014-09-11 9:06 ` Richard Biener 2014-09-11 9:18 ` Richard Biener 2014-09-16 16:38 ` [PATCHv3] " Yury Gribov 3 siblings, 1 reply; 44+ messages in thread From: Richard Biener @ 2014-09-11 9:06 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Wed, Sep 10, 2014 at 10:09 AM, Yury Gribov <y.gribov@samsung.com> wrote: > Hi all, > > This is a second version of patch which adds a Vim config (.local.vimrc) > to root folder to allow automatic setup of GNU formatting for C/C++/Java/Lex > GCC files. > > I've updated the code with comments from Richard and Bernhard (which fixed > formatting > of lonely closing bracket). > > The patch caused a lively debate with Segher who wanted .local.vimrc to not > be enabled > by default. We basically have two options: > 1) put .local.vimrc to root (just like .dir-locals.el config for Emacs) > 2) put both .local.vimrc and .dir-locals.el to contrib and add Makefile > targets > to create symlinks in root folder per user's request > I personally prefer 2) because this would IMHO improve the quality of > patches > (e.g. no more silly tab-whitespace formatting bugs). > > Thoughts? Ok to commit? It doesn't handle indenting switch/case correctly. I get switch (x) { case X: { int foo; ... that is, the { after the case label is wrongly indented. The same happens for { { } } we seem to get two soft-tabs here. Richard. > -Y > > > ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-11 9:06 ` Richard Biener @ 2014-09-11 9:18 ` Richard Biener 2014-09-11 10:10 ` Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Richard Biener @ 2014-09-11 9:18 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Thu, Sep 11, 2014 at 11:06 AM, Richard Biener <richard.guenther@gmail.com> wrote: > On Wed, Sep 10, 2014 at 10:09 AM, Yury Gribov <y.gribov@samsung.com> wrote: >> Hi all, >> >> This is a second version of patch which adds a Vim config (.local.vimrc) >> to root folder to allow automatic setup of GNU formatting for C/C++/Java/Lex >> GCC files. >> >> I've updated the code with comments from Richard and Bernhard (which fixed >> formatting >> of lonely closing bracket). >> >> The patch caused a lively debate with Segher who wanted .local.vimrc to not >> be enabled >> by default. We basically have two options: >> 1) put .local.vimrc to root (just like .dir-locals.el config for Emacs) >> 2) put both .local.vimrc and .dir-locals.el to contrib and add Makefile >> targets >> to create symlinks in root folder per user's request >> I personally prefer 2) because this would IMHO improve the quality of >> patches >> (e.g. no more silly tab-whitespace formatting bugs). >> >> Thoughts? Ok to commit? > > It doesn't handle indenting switch/case correctly. I get > > switch (x) > { > case X: > { > int foo; > ... > > that is, the { after the case label is wrongly indented. The same happens > for > { > { > } > } > > we seem to get two soft-tabs here. setlocal cinoptions=>s,n-s,{s,:s,=s,g0,hs,p5,t0,+s,(0,u0,w1,m0 does better but still oddly handles switch (x) { case X: { tree x; thus indents a brace two spaces too much (but the stmts are correctly indented). The following is handled fine: switch (x) { case X: foo (); Richard. > Richard. > >> -Y >> >> >> ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-11 9:18 ` Richard Biener @ 2014-09-11 10:10 ` Yury Gribov 2014-09-11 16:07 ` Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-09-11 10:10 UTC (permalink / raw) To: Richard Biener Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On 09/11/2014 01:18 PM, Richard Biener wrote: On Thu, Sep 11, 2014 at 11:06 AM, Richard Biener <richard.guenther@gmail.com> wrote: > >On Wed, Sep 10, 2014 at 10:09 AM, Yury Gribov<y.gribov@samsung.com> wrote: >> >>Hi all, >> >> >> >>This is a second version of patch which adds a Vim config (.local.vimrc) >> >>to root folder to allow automatic setup of GNU formatting for C/C++/Java/Lex >> >>GCC files. >> >> >> >>I've updated the code with comments from Richard and Bernhard (which fixed >> >>formatting >> >>of lonely closing bracket). >> >> >> >>The patch caused a lively debate with Segher who wanted .local.vimrc to not >> >>be enabled >> >>by default. We basically have two options: >> >>1) put .local.vimrc to root (just like .dir-locals.el config for Emacs) >> >>2) put both .local.vimrc and .dir-locals.el to contrib and add Makefile >> >>targets >> >>to create symlinks in root folder per user's request >> >>I personally prefer 2) because this would IMHO improve the quality of >> >>patches >> >>(e.g. no more silly tab-whitespace formatting bugs). >> >> >> >>Thoughts? Ok to commit? > > > >It doesn't handle indenting switch/case correctly. I get > > > > switch (x) > > { > > case X: > > { > > int foo; > >... > > > >that is, the { after the case label is wrongly indented. The same happens > >for > > { > > { > > } > > } > > > >we seem to get two soft-tabs here. > > setlocal cinoptions=>s,n-s,{s,:s,=s,g0,hs,p5,t0,+s,(0,u0,w1,m0 > > does better but still oddly handles Also fails for if (1) { x = 2; } ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-11 10:10 ` Yury Gribov @ 2014-09-11 16:07 ` Yury Gribov 2014-09-14 10:32 ` Alexander Monakov 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-09-11 16:07 UTC (permalink / raw) To: Richard Biener Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On 09/11/2014 02:10 PM, Yury Gribov wrote: > On 09/11/2014 01:18 PM, Richard Biener wrote: > On Thu, Sep 11, 2014 at 11:06 AM, Richard Biener > <richard.guenther@gmail.com> wrote: >> >On Wed, Sep 10, 2014 at 10:09 AM, Yury Gribov<y.gribov@samsung.com> >> wrote: >>> >>Hi all, >>> >> >>> >>This is a second version of patch which adds a Vim config >>> (.local.vimrc) >>> >>to root folder to allow automatic setup of GNU formatting for >>> C/C++/Java/Lex >>> >>GCC files. >>> >> >>> >>I've updated the code with comments from Richard and Bernhard >>> (which fixed >>> >>formatting >>> >>of lonely closing bracket). >>> >> >>> >>The patch caused a lively debate with Segher who wanted >>> .local.vimrc to not >>> >>be enabled >>> >>by default. We basically have two options: >>> >>1) put .local.vimrc to root (just like .dir-locals.el config for >>> Emacs) >>> >>2) put both .local.vimrc and .dir-locals.el to contrib and add >>> Makefile >>> >>targets >>> >>to create symlinks in root folder per user's request >>> >>I personally prefer 2) because this would IMHO improve the quality of >>> >>patches >>> >>(e.g. no more silly tab-whitespace formatting bugs). >>> >> >>> >>Thoughts? Ok to commit? >> > >> >It doesn't handle indenting switch/case correctly. I get >> > >> > switch (x) >> > { >> > case X: >> > { >> > int foo; >> >... >> > >> >that is, the { after the case label is wrongly indented. The same >> happens >> >for >> > { >> > { >> > } >> > } >> > >> >we seem to get two soft-tabs here. >> >> setlocal cinoptions=>s,n-s,{s,:s,=s,g0,hs,p5,t0,+s,(0,u0,w1,m0 >> >> does better but still oddly handles > > Also fails for > > if (1) > { > x = 2; > } Ok, it tooks some time. Basically we want brace symbol to behave differently in two contexts: 1) not add any additional offset when not following control flow operator: void f () { int x; { } } 2) but add shifttab otherwise: void f() { if (1) { } } My understanding is that {N looks too rigid and always adds the same amount to current indent. Thus we see parasitic whites in the first case. I wonder what would be the best way to handle this. We could just live with that (free {}'s are rare anyway) or I could try to hack a custom indentexpr (this will of course increase the complexity of patch). -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-11 16:07 ` Yury Gribov @ 2014-09-14 10:32 ` Alexander Monakov 2014-09-15 9:54 ` Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Alexander Monakov @ 2014-09-14 10:32 UTC (permalink / raw) To: Yury Gribov Cc: Richard Biener, GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Thu, 11 Sep 2014, Yury Gribov wrote: > Ok, it tooks some time. Basically we want brace symbol to behave differently > in two contexts: > > 1) not add any additional offset when not following control flow operator: > void > f () > { > int x; > { > } > } Note that GCC commonly uses custom iteration macros, e.g.: FOR_EACH_BB_FN(bb, fn) { do_stuff; } and cinoptions that get the braces-in-switch case wrong should get constructs like the above right. (to get gnu-style autoindent in Vim, I've been using http://www.vim.org/scripts/script.php?script_id=575 and would adjust braces in switch by hand if need arose; the script is probably very close to one of approaches posted in this thread, but I haven't checked) Alexander ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv2] Vimrc config with GNU formatting 2014-09-14 10:32 ` Alexander Monakov @ 2014-09-15 9:54 ` Yury Gribov 0 siblings, 0 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-15 9:54 UTC (permalink / raw) To: Alexander Monakov Cc: Richard Biener, GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On 09/14/2014 02:30 PM, Alexander Monakov wrote: > On Thu, 11 Sep 2014, Yury Gribov wrote: >> Ok, it tooks some time. Basically we want brace symbol to behave differently >> in two contexts: >> >> 1) not add any additional offset when not following control flow operator: >> void >> f () >> { >> int x; >> { >> } >> } > > Note that GCC commonly uses custom iteration macros, e.g.: > > FOR_EACH_BB_FN(bb, fn) > { > do_stuff; > } > > and cinoptions that get the braces-in-switch case wrong should get constructs > like the above right. Right, looks like a fair tradeoff. > (to get gnu-style autoindent in Vim, I've been using > http://www.vim.org/scripts/script.php?script_id=575 and would adjust braces in > switch by hand if need arose; the script is probably very close to one of > approaches posted in this thread, but I haven't checked) Thanks for sharing, these Vim configs just keep popping up. Here are results of quick analysis. Plugin's pros: * KR-style parameters are 4 chars instead of 5 (not sure that's important for GCC but matters in e.g. zlib so makes sense to borrow; I'll update next version of patch with this) * explicitly set f0 in cino (again makes sense to borrow) And cons: * sets formatting globally for all *.c files * only works for C sources and headers so e.g. won't work for libstdc++ * does not know about C++ formatting (e.g. public:, etc.) * continuation line is indented by 1 char instead of GCC's 2 And also some stuff which we probably don't care about: * plugin does not use softtabstop so Tab inserts a real tab character * better formatting of special type of comments: /* Start * Middle */ * sets up browsefilter on MS platforms -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv3] Vimrc config with GNU formatting 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov ` (2 preceding siblings ...) 2014-09-11 9:06 ` Richard Biener @ 2014-09-16 16:38 ` Yury Gribov 2014-09-16 21:59 ` Trevor Saunders 2014-09-17 17:08 ` [PATCHv4] " Yury Gribov 3 siblings, 2 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-16 16:38 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 775 bytes --] 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 [-- Attachment #2: local-vimrc-3.diff --] [-- Type: text/x-diff, Size: 3159 bytes --] commit 67219512dac9a5cc14eea8f157222a226044dd72 Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Sep 4 16:55:44 2014 +0400 2014-09-16 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> Vim config with GNU formatting. contrib/ * vimrc: New file. / * .gitignore: Added .local.vimrc. * Makefile.tpl (.local.vimrc): New target. * Makefile.in: Regenerate. diff --git a/.gitignore b/.gitignore index e9b56be..252b8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,8 @@ POTFILES TAGS TAGS.sub +.local.vimrc + .gdbinit .gdb_history diff --git a/Makefile.in b/Makefile.in index d6105b3..e573069 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) + # Installation targets. .PHONY: install uninstall diff --git a/Makefile.tpl b/Makefile.tpl index f7c7e38..d050694 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) + # Installation targets. .PHONY: install uninstall diff --git a/contrib/vimrc b/contrib/vimrc new file mode 100644 index 0000000..7287bd1 --- /dev/null +++ b/contrib/vimrc @@ -0,0 +1,43 @@ +" Code formatting settings for Vim. +" +" To enable this for GCC files by default, install thinca's localrc plugin +" and do +" $ make .local.vimrc +" Or if you dislike plugins, add autocmd in your .vimrc: +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/.local.vimrc +" Or just source file manually every time if you are masochist: +" :so .local.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() ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv3] Vimrc config with GNU formatting 2014-09-16 16:38 ` [PATCHv3] " Yury Gribov @ 2014-09-16 21:59 ` Trevor Saunders 2014-09-17 13:02 ` Segher Boessenkool 2014-09-17 17:08 ` [PATCHv4] " Yury Gribov 1 sibling, 1 reply; 44+ messages in thread From: Trevor Saunders @ 2014-09-16 21:59 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Mike Stump On Tue, Sep 16, 2014 at 08:38:58PM +0400, 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) fwiw, I think enabling it by default especially when that really means enable it if you've enabled the localrc plugin makes sense. I don't see how you can enable the localrc plugin and then complain when people use it for its designed purpose. However something in contrib/ is probably easier for new people to find than something on the wiki or something so better than doing nothing :) Thanks! Trev > * 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 > commit 67219512dac9a5cc14eea8f157222a226044dd72 > Author: Yury Gribov <y.gribov@samsung.com> > Date: Thu Sep 4 16:55:44 2014 +0400 > > 2014-09-16 Laurynas Biveinis <laurynas.biveinis@gmail.com> > Yury Gribov <y.gribov@samsung.com> > > Vim config with GNU formatting. > > contrib/ > * vimrc: New file. > > / > * .gitignore: Added .local.vimrc. > * Makefile.tpl (.local.vimrc): New target. > * Makefile.in: Regenerate. > > diff --git a/.gitignore b/.gitignore > index e9b56be..252b8b0 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -32,6 +32,8 @@ POTFILES > TAGS > TAGS.sub > > +.local.vimrc > + > .gdbinit > .gdb_history > > diff --git a/Makefile.in b/Makefile.in > index d6105b3..e573069 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) > + > # Installation targets. > > .PHONY: install uninstall > diff --git a/Makefile.tpl b/Makefile.tpl > index f7c7e38..d050694 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) > + > # Installation targets. > > .PHONY: install uninstall > diff --git a/contrib/vimrc b/contrib/vimrc > new file mode 100644 > index 0000000..7287bd1 > --- /dev/null > +++ b/contrib/vimrc > @@ -0,0 +1,43 @@ > +" Code formatting settings for Vim. > +" > +" To enable this for GCC files by default, install thinca's localrc plugin > +" and do > +" $ make .local.vimrc > +" Or if you dislike plugins, add autocmd in your .vimrc: > +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/.local.vimrc > +" Or just source file manually every time if you are masochist: > +" :so .local.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() ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv3] Vimrc config with GNU formatting 2014-09-16 21:59 ` Trevor Saunders @ 2014-09-17 13:02 ` Segher Boessenkool 2014-09-17 14:05 ` Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Segher Boessenkool @ 2014-09-17 13:02 UTC (permalink / raw) To: Trevor Saunders Cc: Yury Gribov, GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Mike Stump On Tue, Sep 16, 2014 at 05:58:58PM -0400, Trevor Saunders wrote: > fwiw, I think enabling it by default especially when that really means > enable it if you've enabled the localrc plugin makes sense. Enabling it by default means enabling it for all users. That is a really really bad plan; many of the options this script sets are user preferences. You can make Vim automatically adapt settings, but you cannot make the Vim user adapt to that. Of course Vim won't use this script by default anyway. It would be nice if there was some "modeline for this whole subtree" mechanism, but there is not. > I don't see > how you can enable the localrc plugin and then complain when people use > it for its designed purpose. Sure. If you have the localrc thing installed, anyone who can write files you can read can make your vim do *anything* (and I mean *anything*). It is a security disaster, that is, there is no security at all. It runs any script in the path from the file you open up to the root. There is no confirmation asked, no whitelist, no blacklist, no nothing. And no sandboxing either, of course. Did I mention /tmp? And writing to files? Or just opening a shell. The possibilities are endless! We should not encourage people to install this. Running it is reckless; telling other people to run it is irresponsible. > However something in contrib/ is probably > easier for new people to find than something on the wiki or something so > better than doing nothing :) Yup, just a bunch of recommended settings somewhere easy to find in contrib/ should be quite helpful to many people. Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv3] Vimrc config with GNU formatting 2014-09-17 13:02 ` Segher Boessenkool @ 2014-09-17 14:05 ` Yury Gribov 2014-09-17 14:10 ` Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-09-17 14:05 UTC (permalink / raw) To: Segher Boessenkool, Trevor Saunders Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Mike Stump On 09/17/2014 05:01 PM, Segher Boessenkool wrote: > You can make Vim automatically adapt settings, but you cannot make the Vim > user adapt to that. How about making Vim user adapt to GNU coding style though? Not that I want to start flame again. > Sure. If you have the localrc thing installed, anyone who can write files > you can read can make your vim do *anything* (and I mean *anything*). I thought that modern versions of localrc run .local.vimrc scripts in a sandbox? -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv3] Vimrc config with GNU formatting 2014-09-17 14:05 ` Yury Gribov @ 2014-09-17 14:10 ` Yury Gribov 0 siblings, 0 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-17 14:10 UTC (permalink / raw) To: Segher Boessenkool, Trevor Saunders Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Mike Stump >> Sure. If you have the localrc thing installed, anyone who can write >> files >> you can read can make your vim do *anything* (and I mean *anything*). > > I thought that modern versions of localrc run .local.vimrc scripts in a > sandbox? Ok, looks like Markus Braun's http://www.vim.org/scripts/script.php?script_id=441 does this. Thinca's plugin currently indeed allows arbitrary code execution. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv4] Vimrc config with GNU formatting 2014-09-16 16:38 ` [PATCHv3] " Yury Gribov 2014-09-16 21:59 ` Trevor Saunders @ 2014-09-17 17:08 ` Yury Gribov 2014-09-18 3:54 ` Segher Boessenkool 2014-10-02 17:14 ` [PATCHv5] " Yury Gribov 1 sibling, 2 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-17 17:08 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 935 bytes --] 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 [-- Attachment #2: local-vimrc-4.diff --] [-- Type: text/x-diff, Size: 3329 bytes --] commit fa7d6c68b0eb8763333aef6c22e4c88aa82db05e Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Sep 4 16:55:44 2014 +0400 2014-09-17 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@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() ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv4] Vimrc config with GNU formatting 2014-09-17 17:08 ` [PATCHv4] " Yury Gribov @ 2014-09-18 3:54 ` Segher Boessenkool 2014-09-18 8:39 ` Yury Gribov 2014-10-02 17:14 ` [PATCHv5] " Yury Gribov 1 sibling, 1 reply; 44+ messages in thread From: Segher Boessenkool @ 2014-09-18 3:54 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Wed, Sep 17, 2014 at 09:08:44PM +0400, Yury Gribov wrote: [ Use a proper mime type and target-disposition inline, as contribute.html tells you. Or use a saner email client; since you're using git, try git send-email perhaps? Thanks. ] > 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) > + This is another target than what the doc (in the script itself) mentions. It is not marked as phony. It should not _be_ phony; the two files should be separate targets. Why make links instead of copies? A user will likely want to edit his config. The way you use ";" is wrong (it continues if there is an error). You don't need the "cd" anyway, come to that. It's pretty silly to have a makefile target that only copies a file (that is never used by the makefile itself); just tell in the doc where to copy the file. > --- /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 No, we should *not* advertise an "enough rope" solution without mentioning it *will* kill you. Or not mention it at all. Esp. since your next option has all the same functionality and more. > +" Or install Markus Braun's localvimrc and do > +" $ make .lvimrc As said before, these targets won't work. > +" Or if you dislike plugins, add autocmd in your ~/.vimrc: > +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc There are many more reasons than just "dislike of plugins" to prefer something like this. For one thing, many Vim users will have many similar statements in their config _already_. > +" Or just source file manually every time if you are masochist: > +" :so path/to/gcc/contrib/vimrc How is that masochist? Typing that cino by hand though, now that would qualify ;-) Your list reads as a recommendation, telling the reader to only do the latter options if they are desperate/stupid/etc. While it really is the other way around: only lazy people or people who cannot configure their editor themselves want the do-stuff-behind-your-back solution. Just keep things neutral please. > + 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 If you write this as absolute numbers instead of as shift widths, you do not need to force sw and sts settings down people's throat. It might also be easier to read? Well I doubt that, but it will be slightly shorter at least. > + setlocal textwidth=79 The coding conventions say maximum line length is 80. 'tw' is a user preference as well, and this one is almost as annoying as cindent, if not more. > + setlocal formatoptions-=ro formatoptions+=cql Yet another user preference. Also mostly the default, except "l" -- which won't do anything if tw=0 as it should be. And you do not enable "t" (also on by default), so you do not want to wrap text anyway? Confused now. Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv4] Vimrc config with GNU formatting 2014-09-18 3:54 ` Segher Boessenkool @ 2014-09-18 8:39 ` Yury Gribov 2014-09-18 15:37 ` Mike Stump 2014-09-18 17:20 ` Segher Boessenkool 0 siblings, 2 replies; 44+ messages in thread From: Yury Gribov @ 2014-09-18 8:39 UTC (permalink / raw) To: Segher Boessenkool Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On 09/18/2014 07:52 AM, Segher Boessenkool wrote:>> +# Local Vim config >> + >> +vimrc: >> + (cd $(srcdir); $(LN_S) contrib/vimrc .local.vimrc; $(LN_S) contrib/vimrc .lvimrc) >> + > > This is another target than what the doc (in the script itself) mentions. Right, I've forgot to fix it before sending the patch. Too much experimenting in the evening... > It is not marked as phony. Noted. > It should not _be_ phony; the two files should > be separate targets. I've done that initially but that may look weird for the user. When typing 'make .local.vimrc' in GCC build directory one would expect .local.vimrc to be created at the root of build directory, not srcdir. > Why make links instead of copies? A user will likely > want to edit his config. I see your point. On the other hand fixing a bug in contrib/vimrc will not be propagated to .local.vimrc which looks like a major disadvantage (to me at least). > The way you use ";" is wrong (it continues if there > is an error). Agreed. Current Makefiles do use ";" in backticks and that drew me away. > You don't need the "cd" anyway, come to that. Noted. > It's pretty silly to have a makefile target that only copies a file (that > is never used by the makefile itself); just tell in the doc where to copy > the file. I personally prefer a Makefile target to simplify things. But let's wait for other people opinions on this. >> --- /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 > > No, we should *not* advertise an "enough rope" solution without mentioning > it *will* kill you. How about adding a disclaimer? E.g. "beware that Vim plugins are a GAPING SECURITY HOLE so use the at YOUR OWN RISK". (And note that Braun's plugin does use sandboxes). > Or not mention it at all. Esp. since your next option > has all the same functionality and more. It lacks very important functionality: user has to specify path to concrete GCC source tree when adding the autocmd. I have a dozen of trees on my box and I regularly rename, move or copy them. With plugins one doesn't have to bother fixing paths in ~/.vimrc which is important for productivity. >> +" Or if you dislike plugins, add autocmd in your ~/.vimrc: >> +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc > > There are many more reasons than just "dislike of plugins" to prefer > something like this. For one thing, many Vim users will have many > similar statements in their config _already_. So "if you don't want to use plugins"? >> +" Or just source file manually every time if you are masochist: >> +" :so path/to/gcc/contrib/vimrc > > How is that masochist? Typing that cino by hand though, now that would > qualify ;-) Note that user has to type source command for every newly opened file. This indeed looks inconvenient (to me again). > Just keep things neutral please. Trying to salt the boring docs a bit to attract reader's attention ;) >> + 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 > > If you write this as absolute numbers instead of as shift widths, you do not > need to force sw and sts settings down people's throat. It might also be > easier to read? Well I doubt that, but it will be slightly shorter at least. IMHO matching shiftwidth with GNU indent may be useful. E.g. Vim won't reindent when you start editing an empty line and user will have to insert indents manually. Also replacing offsets with numbers hides the fact that they are based on GNU shiftwidth. >> + setlocal textwidth=79 > > The coding conventions say maximum line length is 80. From https://www.gnu.org/prep/standards/html_node/Formatting.html : "Please keep the length of source lines to 79 characters or less, for maximum readability in the widest range of environments." > 'tw' is a user preference as well The config just follows the GNU coding standard. Now we rarely do violate textwidth in our codes, that's why I do formatoptions+=l below. >> + setlocal formatoptions-=ro formatoptions+=cql > > Yet another user preference. Also mostly the default, except "l" -- which > won't do anything if tw=0 as it should be. And you do not enable "t" (also > on by default), so you do not want to wrap text anyway? Confused now. Me as well, the original config author did it that way. IMHO +t makes sense here. -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv4] Vimrc config with GNU formatting 2014-09-18 8:39 ` Yury Gribov @ 2014-09-18 15:37 ` Mike Stump 2014-09-18 17:20 ` Segher Boessenkool 1 sibling, 0 replies; 44+ messages in thread From: Mike Stump @ 2014-09-18 15:37 UTC (permalink / raw) To: Yury Gribov Cc: Segher Boessenkool, GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders On Sep 18, 2014, at 1:40 AM, Yury Gribov <y.gribov@samsung.com> wrote: > How about adding a disclaimer? E.g. "beware that Vim plugins are a GAPING SECURITY HOLE > so use the at YOUR OWN RISK". (And note that Braun's plugin does use sandboxes). Building gcc features a security risk at least as big as a plugin for vim. And, yes, I’ve built gcc in a sandbox before. ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv4] Vimrc config with GNU formatting 2014-09-18 8:39 ` Yury Gribov 2014-09-18 15:37 ` Mike Stump @ 2014-09-18 17:20 ` Segher Boessenkool 2014-09-19 4:17 ` Yury Gribov 1 sibling, 1 reply; 44+ messages in thread From: Segher Boessenkool @ 2014-09-18 17:20 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Thu, Sep 18, 2014 at 12:40:08PM +0400, Yury Gribov wrote: > When typing 'make .local.vimrc' in GCC build directory one would expect > .local.vimrc to be created at the root of build directory, not srcdir. Yes, you would not expect it to do anything to your source dir, ever :-) > >> +" To enable this for GCC files by default, install thinca's vim-localrc > >> +" plugin and do > >> +" $ make .local.vimrc > > > > No, we should *not* advertise an "enough rope" solution without > mentioning > > it *will* kill you. > > How about adding a disclaimer? E.g. "beware that Vim plugins are a > GAPING SECURITY HOLE > so use the at YOUR OWN RISK". (And note that Braun's plugin does use > sandboxes). This *particular* plugin is suicidal. Most plugins are just fine. > > Or not mention it at all. Esp. since your next option > > has all the same functionality and more. > > It lacks very important functionality: user has to specify path > to concrete GCC source tree when adding the autocmd. I was talking about mbr's plugin here :-) > I have a dozen of trees on my box and I regularly rename, move or copy them. > With plugins one doesn't have to bother fixing paths in ~/.vimrc > which is important for productivity. And :au bufread ~/src/gcc/* ... works for me. To each their own. > >> +" Or if you dislike plugins, add autocmd in your ~/.vimrc: > >> +" :au BufNewFile,BufReadPost path/to/gcc/* :so > path/to/gcc/contrib/vimrc > > > > There are many more reasons than just "dislike of plugins" to prefer > > something like this. For one thing, many Vim users will have many > > similar statements in their config _already_. > > So "if you don't want to use plugins"? Just mention it as another option? Something like "You can add these options to your .vimrc; or you can :source this script file; or do either with an :autocmd; or use e.g. the <name of plugin here> plugin <some vim.org url>". Don't say "do X if Y"; let people decide for themselves what fits their situation best. > >> +" Or just source file manually every time if you are masochist: > >> +" :so path/to/gcc/contrib/vimrc > > > > How is that masochist? Typing that cino by hand though, now that would > > qualify ;-) > > Note that user has to type source command for every newly opened file. > This indeed looks inconvenient (to me again). Well for most people it is justt ":so contrib/vimrc". Or just ":lo" if you're talking about crazy people with views. > >> + setlocal > cinoptions=>2s,n-s,{s,^-s,:s,=s,g0,f0,hs,p2s,t0,+s,(0,u0,w1,m0 > > > > If you write this as absolute numbers instead of as shift widths, you > do not > > need to force sw and sts settings down people's throat. It might also be > > easier to read? Well I doubt that, but it will be slightly shorter > at least. > > IMHO matching shiftwidth with GNU indent may be useful. > E.g. Vim won't reindent when you start editing an empty line and user > will have to insert indents manually. > > Also replacing offsets with numbers hides the fact > that they are based on GNU shiftwidth. I have no idea what you mean with "matching with GNU indent", sorry. I was suggesting you could write it as :set cino=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 and you'd be independent of sw setting. The coding standard says "indent two spaces" etc. anyway. And yeah sw=2 does make sense for editing GCC, if you are used to sw=2 that is. The point is that the sw setting has nothing to do with what your text will look like, only with what keys you press. > >> + setlocal textwidth=79 > > > > The coding conventions say maximum line length is 80. > > From https://www.gnu.org/prep/standards/html_node/Formatting.html : > "Please keep the length of source lines to 79 characters or less, for > maximum readability in the widest range of environments." There is a doc on gcc.gnu.org as well, which describes many more details. > Now we rarely do violate textwidth in our codes, "rarely"? Ho hum. There are many worse formatting errors, of course. And how much do those matter _really_. > > And you do not enable "t" (also > > on by default), so you do not want to wrap text anyway? Confused now. > > Me as well, the original config author did it that way. IMHO +t makes > sense here. It is certainly more consistent. Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv4] Vimrc config with GNU formatting 2014-09-18 17:20 ` Segher Boessenkool @ 2014-09-19 4:17 ` Yury Gribov 2014-09-19 11:11 ` Segher Boessenkool 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-09-19 4:17 UTC (permalink / raw) To: Segher Boessenkool Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On 09/18/2014 09:20 PM, Segher Boessenkool wrote: > On Thu, Sep 18, 2014 at 12:40:08PM +0400, Yury Gribov wrote: >> When typing 'make .local.vimrc' in GCC build directory one would expect >> .local.vimrc to be created at the root of build directory, not srcdir. > > Yes, you would not expect it to do anything to your source dir, ever :-) But that's already the case for some other GCC targets e.g. "make TAGS". So I'm just following an established practice here. >>> Or not mention it at all. Esp. since your next option >>> has all the same functionality and more. >> >> It lacks very important functionality: user has to specify path >> to concrete GCC source tree when adding the autocmd. > > I was talking about mbr's plugin here :-) Ah, ok. Then I'll mention thinca's plugin as a secondary option with a disclaimer then. >>>> +" Or if you dislike plugins, add autocmd in your ~/.vimrc: >>>> +" :au BufNewFile,BufReadPost path/to/gcc/* :so >> path/to/gcc/contrib/vimrc >>> >>> There are many more reasons than just "dislike of plugins" to prefer >>> something like this. For one thing, many Vim users will have many >>> similar statements in their config _already_. >> >> So "if you don't want to use plugins"? > > Just mention it as another option? Something like > "You can add these options to your .vimrc; or you can :source this script > file; or do either with an :autocmd; or use e.g. the <name of plugin here> > plugin <some vim.org url>". Don't say "do X if Y"; let people decide for > themselves what fits their situation best. Ok. >>>> +" Or just source file manually every time if you are masochist: >>>> +" :so path/to/gcc/contrib/vimrc >>> >>> How is that masochist? Typing that cino by hand though, now that would >>> qualify ;-) >> >> Note that user has to type source command for every newly opened file. >> This indeed looks inconvenient (to me again). > > Well for most people it is justt ":so contrib/vimrc". Or just ":lo" if > you're talking about crazy people with views. For many people that would be a hassle (judging by my colleagues). > I was suggesting you could write it as > :set cino=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 > and you'd be independent of sw setting. > ... > And yeah sw=2 does make sense for editing GCC, if you are used to sw=2 > that is. The point is that the sw setting has nothing to do with what > your text will look like, only with what keys you press. Depending on whether you treat shiftwidth as "amount of spaces that is inserted when I press >" or "default indent for a particular class of files". For example with shiftwidth=2 user could (un)indent block of C code with < or > which seems to be useful. > The coding standard says > "indent two spaces" etc. anyway. That's what I meant by "matching with GNU indent". >>>> + setlocal textwidth=79 >>> >>> The coding conventions say maximum line length is 80. >> >> From https://www.gnu.org/prep/standards/html_node/Formatting.html : >> "Please keep the length of source lines to 79 characters or less, for >> maximum readability in the widest range of environments." > > There is a doc on gcc.gnu.org as well, which describes many more details. Indeed: "Lines shall be at most 80 columns" (from https://gcc.gnu.org/codingconventions.html#Line). -Y ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv4] Vimrc config with GNU formatting 2014-09-19 4:17 ` Yury Gribov @ 2014-09-19 11:11 ` Segher Boessenkool 0 siblings, 0 replies; 44+ messages in thread From: Segher Boessenkool @ 2014-09-19 11:11 UTC (permalink / raw) To: Yury Gribov Cc: GCC Patches, Laurynas Biveinis, Jeff Law, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On Fri, Sep 19, 2014 at 08:17:28AM +0400, Yury Gribov wrote: > > I was talking about mbr's plugin here :-) > > Ah, ok. Then I'll mention thinca's plugin as a secondary option with a > disclaimer then. Why? There are more plugins that also do the same thing, all more popular (on vim.org at least), all less dangerous (well, many are probably just as bad :-( ). > > I was suggesting you could write it as > > :set cino=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 > > and you'd be independent of sw setting. > > ... > > And yeah sw=2 does make sense for editing GCC, if you are used to sw=2 > > that is. The point is that the sw setting has nothing to do with what > > your text will look like, only with what keys you press. > > Depending on whether you treat shiftwidth as "amount of spaces that is > inserted when I press >" or "default indent for a particular class of > files". For example with shiftwidth=2 user could (un)indent block of C > code with < or > which seems to be useful. Vim treats it as the former (it has no concept of the latter). cindent uses it too, for that "s" thing, but you do not have to use it here anyway since our coding standard requires two spaces so we can just hardcode that in cino; and in that case, a user can use any sw he wants / is used to. Using "s" in cino is useful if you want the layout to change if you change the shiftwidth. But we don't. Segher ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv5] Vimrc config with GNU formatting 2014-09-17 17:08 ` [PATCHv4] " Yury Gribov 2014-09-18 3:54 ` Segher Boessenkool @ 2014-10-02 17:14 ` Yury Gribov 2014-10-13 10:33 ` [PATCHv5][PING] " Yury Gribov 1 sibling, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-10-02 17:14 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 1358 bytes --] On 09/17/2014 09:08 PM, Yury Gribov wrote: > 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? > > New vesion with support for another popular local .vimrc plugin. Hi all, Here is a new vesion of vimrc patch. Hope I got email settings right this time. Changes since v4: * fixed and enhanced docs * added support for .lvimrc in Makefile * minor fixes in cinoptions and formatoptions (reported by Segher) * removed shiftwidth settings (as it does not really relate to code formatting) -Y [-- Attachment #2: local-vimrc-5.diff --] [-- Type: text/x-patch, Size: 3602 bytes --] commit 3f560e9dd16a5e914b6f2ba82edffe13dfde944c Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Oct 2 15:50:52 2014 +0400 2014-10-02 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> Vim config with GNU formatting. contrib/ * vimrc: New file. / * .gitignore: Added .local.vimrc and .lvimrc. * Makefile.tpl (vimrc, .lvimrc, .local.vimrc): New targets. * 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..f3a34af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2384,6 +2384,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/Makefile.tpl b/Makefile.tpl index f7c7e38..b98930c 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -867,6 +867,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/contrib/vimrc b/contrib/vimrc new file mode 100644 index 0000000..34e8f35 --- /dev/null +++ b/contrib/vimrc @@ -0,0 +1,45 @@ +" Code formatting settings for Vim. +" +" To enable this for GCC files by default, you can either source this file +" in your .vimrc via autocmd: +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc +" or source the script manually for each newly opened file: +" :so contrib/vimrc +" You could also use numerous plugins that enable local vimrc e.g. +" mbr's localvimrc or thinca's vim-localrc (but note that the latter +" is much less secure). To install local vimrc config, run +" $ make vimrc +" from GCC build folder. +" +" 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 softtabstop=2 + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 + setlocal textwidth=80 + setlocal formatoptions-=ro formatoptions+=cqlt + endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv5][PING] Vimrc config with GNU formatting 2014-10-02 17:14 ` [PATCHv5] " Yury Gribov @ 2014-10-13 10:33 ` Yury Gribov 2014-10-21 15:24 ` [PATCHv5][PING^2] " Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-10-13 10:33 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 1485 bytes --] On 10/02/2014 09:14 PM, Yury Gribov wrote: > On 09/17/2014 09:08 PM, Yury Gribov wrote: > > 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? > > > > New vesion with support for another popular local .vimrc plugin. > > Hi all, > > Here is a new vesion of vimrc patch. Hope I got email settings right > this time. > > Changes since v4: > * fixed and enhanced docs > * added support for .lvimrc in Makefile > * minor fixes in cinoptions and formatoptions (reported by Segher) > * removed shiftwidth settings (as it does not really relate to code > formatting) > > -Y > [-- Attachment #2: local-vimrc-5.diff --] [-- Type: text/x-patch, Size: 3602 bytes --] commit 3f560e9dd16a5e914b6f2ba82edffe13dfde944c Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Oct 2 15:50:52 2014 +0400 2014-10-02 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> Vim config with GNU formatting. contrib/ * vimrc: New file. / * .gitignore: Added .local.vimrc and .lvimrc. * Makefile.tpl (vimrc, .lvimrc, .local.vimrc): New targets. * 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..f3a34af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2384,6 +2384,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/Makefile.tpl b/Makefile.tpl index f7c7e38..b98930c 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -867,6 +867,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/contrib/vimrc b/contrib/vimrc new file mode 100644 index 0000000..34e8f35 --- /dev/null +++ b/contrib/vimrc @@ -0,0 +1,45 @@ +" Code formatting settings for Vim. +" +" To enable this for GCC files by default, you can either source this file +" in your .vimrc via autocmd: +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc +" or source the script manually for each newly opened file: +" :so contrib/vimrc +" You could also use numerous plugins that enable local vimrc e.g. +" mbr's localvimrc or thinca's vim-localrc (but note that the latter +" is much less secure). To install local vimrc config, run +" $ make vimrc +" from GCC build folder. +" +" 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 softtabstop=2 + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 + setlocal textwidth=80 + setlocal formatoptions-=ro formatoptions+=cqlt + endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv5][PING^2] Vimrc config with GNU formatting 2014-10-13 10:33 ` [PATCHv5][PING] " Yury Gribov @ 2014-10-21 15:24 ` Yury Gribov 2014-11-06 10:31 ` [PATCHv5][PING^3] " Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-10-21 15:24 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 1583 bytes --] On 10/13/2014 02:26 PM, Yury Gribov wrote: > On 10/02/2014 09:14 PM, Yury Gribov wrote: >> On 09/17/2014 09:08 PM, Yury Gribov wrote: >> > 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? >> > >> > New vesion with support for another popular local .vimrc plugin. >> >> Hi all, >> >> Here is a new vesion of vimrc patch. Hope I got email settings right >> this time. >> >> Changes since v4: >> * fixed and enhanced docs >> * added support for .lvimrc in Makefile >> * minor fixes in cinoptions and formatoptions (reported by Segher) >> * removed shiftwidth settings (as it does not really relate to code >> formatting) >> >> -Y >> > [-- Attachment #2: local-vimrc-5.diff --] [-- Type: text/x-patch, Size: 3602 bytes --] commit 3f560e9dd16a5e914b6f2ba82edffe13dfde944c Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Oct 2 15:50:52 2014 +0400 2014-10-02 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> Vim config with GNU formatting. contrib/ * vimrc: New file. / * .gitignore: Added .local.vimrc and .lvimrc. * Makefile.tpl (vimrc, .lvimrc, .local.vimrc): New targets. * 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..f3a34af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2384,6 +2384,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/Makefile.tpl b/Makefile.tpl index f7c7e38..b98930c 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -867,6 +867,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/contrib/vimrc b/contrib/vimrc new file mode 100644 index 0000000..34e8f35 --- /dev/null +++ b/contrib/vimrc @@ -0,0 +1,45 @@ +" Code formatting settings for Vim. +" +" To enable this for GCC files by default, you can either source this file +" in your .vimrc via autocmd: +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc +" or source the script manually for each newly opened file: +" :so contrib/vimrc +" You could also use numerous plugins that enable local vimrc e.g. +" mbr's localvimrc or thinca's vim-localrc (but note that the latter +" is much less secure). To install local vimrc config, run +" $ make vimrc +" from GCC build folder. +" +" 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 softtabstop=2 + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 + setlocal textwidth=80 + setlocal formatoptions-=ro formatoptions+=cqlt + endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv5][PING^3] Vimrc config with GNU formatting 2014-10-21 15:24 ` [PATCHv5][PING^2] " Yury Gribov @ 2014-11-06 10:31 ` Yury Gribov 2014-11-28 18:00 ` [PATCHv5][PING^4] " Yury Gribov 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-11-06 10:31 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 1660 bytes --] On 10/21/2014 07:24 PM, Yury Gribov wrote: > On 10/13/2014 02:26 PM, Yury Gribov wrote: >> On 10/02/2014 09:14 PM, Yury Gribov wrote: >>> On 09/17/2014 09:08 PM, Yury Gribov wrote: >>> > 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? >>> > >>> > New vesion with support for another popular local .vimrc plugin. >>> >>> Hi all, >>> >>> Here is a new vesion of vimrc patch. Hope I got email settings right >>> this time. >>> >>> Changes since v4: >>> * fixed and enhanced docs >>> * added support for .lvimrc in Makefile >>> * minor fixes in cinoptions and formatoptions (reported by Segher) >>> * removed shiftwidth settings (as it does not really relate to code >>> formatting) [-- Attachment #2: local-vimrc-5.diff --] [-- Type: text/x-patch, Size: 3602 bytes --] commit 3f560e9dd16a5e914b6f2ba82edffe13dfde944c Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Oct 2 15:50:52 2014 +0400 2014-10-02 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> Vim config with GNU formatting. contrib/ * vimrc: New file. / * .gitignore: Added .local.vimrc and .lvimrc. * Makefile.tpl (vimrc, .lvimrc, .local.vimrc): New targets. * 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..f3a34af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2384,6 +2384,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/Makefile.tpl b/Makefile.tpl index f7c7e38..b98930c 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -867,6 +867,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/contrib/vimrc b/contrib/vimrc new file mode 100644 index 0000000..34e8f35 --- /dev/null +++ b/contrib/vimrc @@ -0,0 +1,45 @@ +" Code formatting settings for Vim. +" +" To enable this for GCC files by default, you can either source this file +" in your .vimrc via autocmd: +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc +" or source the script manually for each newly opened file: +" :so contrib/vimrc +" You could also use numerous plugins that enable local vimrc e.g. +" mbr's localvimrc or thinca's vim-localrc (but note that the latter +" is much less secure). To install local vimrc config, run +" $ make vimrc +" from GCC build folder. +" +" 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 softtabstop=2 + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 + setlocal textwidth=80 + setlocal formatoptions-=ro formatoptions+=cqlt + endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCHv5][PING^4] Vimrc config with GNU formatting 2014-11-06 10:31 ` [PATCHv5][PING^3] " Yury Gribov @ 2014-11-28 18:00 ` Yury Gribov 2014-12-08 21:46 ` Jeff Law 0 siblings, 1 reply; 44+ messages in thread From: Yury Gribov @ 2014-11-28 18:00 UTC (permalink / raw) To: GCC Patches Cc: Laurynas Biveinis, Jeff Law, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump [-- Attachment #1: Type: text/plain, Size: 1764 bytes --] On 11/06/2014 01:31 PM, Yury Gribov wrote: > On 10/21/2014 07:24 PM, Yury Gribov wrote: >> On 10/13/2014 02:26 PM, Yury Gribov wrote: >>> On 10/02/2014 09:14 PM, Yury Gribov wrote: >>>> On 09/17/2014 09:08 PM, Yury Gribov wrote: >>>> > 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? >>>> > >>>> > New vesion with support for another popular local .vimrc plugin. >>>> >>>> Hi all, >>>> >>>> Here is a new vesion of vimrc patch. Hope I got email settings right >>>> this time. >>>> >>>> Changes since v4: >>>> * fixed and enhanced docs >>>> * added support for .lvimrc in Makefile >>>> * minor fixes in cinoptions and formatoptions (reported by Segher) >>>> * removed shiftwidth settings (as it does not really relate to code >>>> formatting) > > [-- Attachment #2: local-vimrc-5.diff --] [-- Type: text/x-patch, Size: 3602 bytes --] commit 3f560e9dd16a5e914b6f2ba82edffe13dfde944c Author: Yury Gribov <y.gribov@samsung.com> Date: Thu Oct 2 15:50:52 2014 +0400 2014-10-02 Laurynas Biveinis <laurynas.biveinis@gmail.com> Yury Gribov <y.gribov@samsung.com> Vim config with GNU formatting. contrib/ * vimrc: New file. / * .gitignore: Added .local.vimrc and .lvimrc. * Makefile.tpl (vimrc, .lvimrc, .local.vimrc): New targets. * 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..f3a34af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2384,6 +2384,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/Makefile.tpl b/Makefile.tpl index f7c7e38..b98930c 100644 --- a/Makefile.tpl +++ b/Makefile.tpl @@ -867,6 +867,18 @@ mail-report-with-warnings.log: warning.log chmod +x $@ echo If you really want to send e-mail, run ./$@ now +# Local Vim config + +$(srcdir)/.local.vimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +$(srcdir)/.lvimrc: + $(LN_S) $(srcdir)/contrib/vimrc $@ + +vimrc: $(srcdir)/.local.vimrc $(srcdir)/.lvimrc + +.PHONY: vimrc + # Installation targets. .PHONY: install uninstall diff --git a/contrib/vimrc b/contrib/vimrc new file mode 100644 index 0000000..34e8f35 --- /dev/null +++ b/contrib/vimrc @@ -0,0 +1,45 @@ +" Code formatting settings for Vim. +" +" To enable this for GCC files by default, you can either source this file +" in your .vimrc via autocmd: +" :au BufNewFile,BufReadPost path/to/gcc/* :so path/to/gcc/contrib/vimrc +" or source the script manually for each newly opened file: +" :so contrib/vimrc +" You could also use numerous plugins that enable local vimrc e.g. +" mbr's localvimrc or thinca's vim-localrc (but note that the latter +" is much less secure). To install local vimrc config, run +" $ make vimrc +" from GCC build folder. +" +" 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 softtabstop=2 + setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,f0,h2,p4,t0,+2,(0,u0,w1,m0 + setlocal textwidth=80 + setlocal formatoptions-=ro formatoptions+=cqlt + endif +endfunction + +call SetStyle() ^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCHv5][PING^4] Vimrc config with GNU formatting 2014-11-28 18:00 ` [PATCHv5][PING^4] " Yury Gribov @ 2014-12-08 21:46 ` Jeff Law 0 siblings, 0 replies; 44+ messages in thread From: Jeff Law @ 2014-12-08 21:46 UTC (permalink / raw) To: Yury Gribov, GCC Patches Cc: Laurynas Biveinis, Segher Boessenkool, Richard Biener, Bernhard Reutner-Fischer, Trevor Saunders, Mike Stump On 11/28/14 10:26, Yury Gribov wrote: > > > commit 3f560e9dd16a5e914b6f2ba82edffe13dfde944c > Author: Yury Gribov<y.gribov@samsung.com> > Date: Thu Oct 2 15:50:52 2014 +0400 > > 2014-10-02 Laurynas Biveinis<laurynas.biveinis@gmail.com> > Yury Gribov<y.gribov@samsung.com> > > Vim config with GNU formatting. > > contrib/ > * vimrc: New file. > > / > * .gitignore: Added .local.vimrc and .lvimrc. > * Makefile.tpl (vimrc, .lvimrc, .local.vimrc): New targets. > * Makefile.in: Regenerate. OK, primarily because it's an improvement and not the default :-) Folks that want to use can explicitly opt-in. Jeff ^ permalink raw reply [flat|nested] 44+ messages in thread
end of thread, other threads:[~2014-12-08 21:46 UTC | newest] Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-09-04 13:06 Vimrc config with GNU formatting Yury Gribov 2014-09-04 13:22 ` Richard Biener 2014-09-04 20:23 ` Bernhard Reutner-Fischer 2014-09-05 15:10 ` Yury Gribov 2014-09-05 16:46 ` Bernhard Reutner-Fischer 2014-09-06 16:33 ` Yury Gribov 2014-09-05 17:35 ` Segher Boessenkool 2014-09-06 15:40 ` Yury Gribov 2014-09-06 18:21 ` Trevor Saunders 2014-09-06 19:35 ` Segher Boessenkool 2014-09-07 4:18 ` Yuri Gribov 2014-09-07 4:48 ` Yuri Gribov 2014-09-07 13:33 ` Segher Boessenkool 2014-09-05 15:04 ` Yury Gribov 2014-09-10 8:09 ` [PATCHv2] " Yury Gribov 2014-09-10 8:17 ` Yury Gribov 2014-09-10 19:17 ` Segher Boessenkool 2014-09-11 4:47 ` Yury Gribov 2014-09-11 9:14 ` pinskia 2014-09-11 9:35 ` Yury Gribov 2014-09-11 9:06 ` Richard Biener 2014-09-11 9:18 ` Richard Biener 2014-09-11 10:10 ` Yury Gribov 2014-09-11 16:07 ` Yury Gribov 2014-09-14 10:32 ` Alexander Monakov 2014-09-15 9:54 ` Yury Gribov 2014-09-16 16:38 ` [PATCHv3] " Yury Gribov 2014-09-16 21:59 ` Trevor Saunders 2014-09-17 13:02 ` Segher Boessenkool 2014-09-17 14:05 ` Yury Gribov 2014-09-17 14:10 ` Yury Gribov 2014-09-17 17:08 ` [PATCHv4] " Yury Gribov 2014-09-18 3:54 ` Segher Boessenkool 2014-09-18 8:39 ` Yury Gribov 2014-09-18 15:37 ` Mike Stump 2014-09-18 17:20 ` Segher Boessenkool 2014-09-19 4:17 ` Yury Gribov 2014-09-19 11:11 ` Segher Boessenkool 2014-10-02 17:14 ` [PATCHv5] " Yury Gribov 2014-10-13 10:33 ` [PATCHv5][PING] " Yury Gribov 2014-10-21 15:24 ` [PATCHv5][PING^2] " Yury Gribov 2014-11-06 10:31 ` [PATCHv5][PING^3] " Yury Gribov 2014-11-28 18:00 ` [PATCHv5][PING^4] " Yury Gribov 2014-12-08 21:46 ` Jeff Law
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).