|
From: Andreas A. <ar...@li...> - 2018-11-15 18:40:05
|
When editing source files, I prefer the editor (in my case Emacs) to know the project's basic formatting rules, so I can use auto-indentation, highlighting of whitespace formatting errors, and similar features. For instance, in the case of C source files in the Valgrind source tree, the editor should use an indentation width of 3 columns per level, and it should avoid tabs for indentation. There are multiple ways to tell the editor about this. One way is to change the editor's global settings, in which case the editor will apply them to all source files of all projects. Another way is to enrich source files with a special comment at the top, like this: /* -*- mode: C; c-basic-offset: 3; -*- */ (Which obviously just applies to the source file the comment appears in.) Another way is to place a configuration file at the top of the project's source tree. I have been using such a configuration file for Emacs, ".dir-locals.el", in my local Valgrind source tree for some time now, but it is probably a good idea to include this upstream. Thus I propose the patch below. Note that this is for Emacs only; other editors will probably require additional such files. For instance, https://editorconfig.org/ defines a generic format that seems to be supported by many editors, although Emacs and Vim currently require plugins for this to work. I shortly discussed this topic on IRC with Julian yesterday, and he was wondering about the c-file-style setting (see patch below). I'm not sure about that either; I just considered "Linux" to be the best fit here. If anybody knows a better approach, please let me know. -- >8 -- Subject: [PATCH] Add Emacs configuration file This adds a configuration file for Emacs, ".dir-locals.el", to the topmost directory of the Valgrind source tree. The file contains per-directory local variables. Its settings are applied whenever editing a source file in the Valgrind source tree. --- .dir-locals.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .dir-locals.el diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 000000000..b65c7a3fb --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,18 @@ +;; Emacs settings. + +( + ;; Format used to turn a bug number into a URL (when displaying it). + (nil . ((bug-reference-url-format . "http://bugs.kde.org/show_bug.cgi?id=%s"))) + + ;; Standard settings for editing C source files. + (c-mode . ( + ;; Apply the Linux style as a base. + (c-file-style . "linux") + ;; Use spaces instead of tabs for indentation. + (indent-tabs-mode . nil) + ;; Indent 3 columns per level. + (c-basic-offset . 3) + ;; Lines should be limited to 80 columns. + (fill-column . 80) + )) +) -- 2.17.0 |
|
From: Bart V. A. <bva...@ac...> - 2018-11-15 19:00:37
|
On Thu, 2018-11-15 at 19:39 +0100, Andreas Arnez wrote: > diff --git a/.dir-locals.el b/.dir-locals.el > new file mode 100644 > index 000000000..b65c7a3fb > --- /dev/null > +++ b/.dir-locals.el > @@ -0,0 +1,18 @@ > +;; Emacs settings. > + > +( > + ;; Format used to turn a bug number into a URL (when displaying it). > + (nil . ((bug-reference-url-format . "http://bugs.kde.org/show_bug.cgi?id=%s"))) > + > + ;; Standard settings for editing C source files. > + (c-mode . ( > + ;; Apply the Linux style as a base. > + (c-file-style . "linux") > + ;; Use spaces instead of tabs for indentation. > + (indent-tabs-mode . nil) > + ;; Indent 3 columns per level. > + (c-basic-offset . 3) > + ;; Lines should be limited to 80 columns. > + (fill-column . 80) > + )) > +) Although I think adding a .dir-locals.el file is a good idea, these settings do not match the current indentation for all source files. Some time ago I added the following to my ~/.emacs file (this may be incomplete): (dir-locals-set-class-variables 'valgrind '((c-mode . ((c-basic-offset . 3) (c-label-minimum-indentation . 0) (indent-tabs-mode . nil))))) (dir-locals-set-class-variables 'valgrind-test '((c-mode . ((c-basic-offset . 2) (c-label-minimum-indentation . 0) (indent-tabs-mode . nil))))) (dir-locals-set-directory-class (substitute-in-file-name "$HOME/software/valgrind.git/") 'valgrind) (dir-locals-set-directory-class (substitute-in-file-name "$HOME/software/valgrind.git/drd/tests/") 'valgrind-test) Bart. |
|
From: Andreas A. <ar...@li...> - 2018-11-16 09:52:26
|
On Thu, Nov 15 2018, Bart Van Assche wrote: > Although I think adding a .dir-locals.el file is a good idea, these settings > do not match the current indentation for all source files. Some time ago I > added the following to my ~/.emacs file (this may be incomplete): > > (dir-locals-set-class-variables > 'valgrind > '((c-mode . ((c-basic-offset . 3) > (c-label-minimum-indentation . 0) > (indent-tabs-mode . nil))))) > (dir-locals-set-class-variables > 'valgrind-test > '((c-mode . ((c-basic-offset . 2) > (c-label-minimum-indentation . 0) > (indent-tabs-mode . nil))))) > (dir-locals-set-directory-class (substitute-in-file-name "$HOME/software/valgrind.git/") 'valgrind) > (dir-locals-set-directory-class (substitute-in-file-name "$HOME/software/valgrind.git/drd/tests/") 'valgrind-test) Thanks for the info. OK, if the source files in drd/tests are supposed to follow a different style, then I suggest to add an appropriate .dir-locals.el to that directory as well. Does anybody know any other exceptions to the usual style? -- Andreas |
|
From: Mark W. <ma...@kl...> - 2018-11-16 10:29:31
|
On Fri, 2018-11-16 at 10:52 +0100, Andreas Arnez wrote: > Does anybody know any other exceptions to the usual style? The sources in coregrind/m_demangle/ comes from libiberty and follow normal GNU style (you normally don't edit it directly though, but are supposed to update it from upstream through the auxprogs/update- demangler script). Cheers, Mark |