From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5W7L-0006st-Od for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:28:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5W7K-0002CN-D8 for qemu-devel@nongnu.org; Thu, 18 Jun 2015 05:28:15 -0400 From: Markus Armbruster References: <1433424607-3429-1-git-send-email-berrange@redhat.com> Date: Thu, 18 Jun 2015 11:28:10 +0200 In-Reply-To: (Peter Maydell's message of "Thu, 4 Jun 2015 14:41:42 +0100") Message-ID: <87twu5z7px.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2] Add .dir-locals.el file to configure emacs coding style List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Trivial , John Snow , QEMU Developers Peter Maydell writes: > On 4 June 2015 at 14:30, Daniel P. Berrange wrote: >> Some default emacs setups indent by 2 spaces and uses tabs >> which is counter to the QEMU coding style rules. Adding a >> .dir-locals.el file in the top level of the GIT repo will >> inform emacs about the QEMU coding style, and so assist >> contributors in avoiding common style mistakes before >> they submit patches. >> >> Signed-off-by: Daniel P. Berrange >> --- >> .dir-locals.el | 2 ++ >> 1 file changed, 2 insertions(+) >> create mode 100644 .dir-locals.el >> >> diff --git a/.dir-locals.el b/.dir-locals.el >> new file mode 100644 >> index 0000000..3ac0cfc >> --- /dev/null >> +++ b/.dir-locals.el >> @@ -0,0 +1,2 @@ >> +((c-mode . ((c-file-style . "stroustrup") >> + (indent-tabs-mode . nil)))) > > My .emacs defines a style like this: > > (defconst qemu-c-style > '((indent-tabs-mode . nil) > (c-basic-offset . 4) > (tab-width . 8) > (c-comment-only-line-offset . 0) > (c-offsets-alist . ((statement-block-intro . +) > (substatement-open . 0) > (label . 0) > (statement-cont . +) > (innamespace . 0) > (inline-open . 0) > )) > (c-hanging-braces-alist . > ((brace-list-open) > (brace-list-intro) > (brace-list-entry) > (brace-list-close) > (brace-entry-open) > (block-close . c-snug-do-while) > ;; structs have hanging braces on open > (class-open . (after)) > ;; ditto if statements > (substatement-open . (after)) > ;; and no auto newline at the end > (class-close) > )) > ) > "QEMU C Programming Style") > > which is a superset of Stroustrup and gets a few more > corner cases right, I think. Trouble is I can't figure out how to get that into Emacs using nothing but files in the QEMU tree. From within the tree, we can file- and directory-local variables, and it just works as long as Emacs deems the variables safe. When not, Emacs prompts for confirmation. I'd rather not go there. Using an existing C style is a textbook example of safe local variables (literally, the Emacs manual does it). Adding simple customizations on top should be feasible. However, I can't see how I could define a new C style there without pushing the "local variables" feature well beyond its intended use, and triggering the confirmation prompts. If we take Dan's patch, every Emacs user who hasn't already configured a suitable style profits. Users who have may have to adjust their configuration to work with or around Dan's patch. "That action is best which procures the greatest happiness for the greatest numbers." Let's take Dan's patch. I can post a follow-up extending tab avoidance to files that don't use c-mode. Reviewed-by: Markus Armbruster