[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [Qemu-devel] [PATCH] Add .dir-locals.el file to confi

From: Markus Armbruster
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] Add .dir-locals.el file to configure emacs coding style
Date: Thu, 18 Jun 2015 10:36:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Michael Tokarev <address@hidden> writes:

> So, what is the consensus here?
> Everyone who talked wants the emacs mode, but everyone
> offers their own mode.
> I'd pick the stroustrup variant suggested by Marcus
> since it is shortest, but while being shortest, it
> is looks a bit "magical".

I don't think it's magical at all.  It uses .dir-locals exactly as
intended.  In fact, it's almost straight from the Emacs manual:

       The '.dir-locals.el' file should hold a specially-constructed list,
    which maps major mode names (symbols) to alists (*note
    (elisp)Association Lists::).  Each alist entry consists of a variable
    name and the directory-local value to assign to that variable, when the
    specified major mode is enabled.  Instead of a mode name, you can
    specify 'nil', which means that the alist applies to any mode; or you
    can specify a subdirectory name (a string), in which case the alist
    applies to all files in that subdirectory.

       Here's an example of a '.dir-locals.el' file:

         ((nil . ((indent-tabs-mode . t)
                  (fill-column . 80)))
          (c-mode . ((c-file-style . "BSD")
                     (subdirs . nil)))
           . ((nil . ((change-log-default-name
                       . "ChangeLog.local"))))))

    This sets 'indent-tabs-mode' and 'fill-column' for any file in the
    directory tree, and the indentation style for any C source file.  The
    special 'subdirs' element is not a variable, but a special keyword which
    indicates that the C mode settings are only to be applied in the current
    directory, not in any subdirectories.  Finally, it specifies a different
    'ChangeLog' file name for any file in the 'src/imported' subdirectory.

The .dir-locals.el snippet I suggested is a straighforward cherry-pick
from the above:

    ((c-mode . ((c-file-style . "stroustrup")
                (indent-tabs-mode . nil))))

Here's one that takes better care of tabs:

    ((nil . ((indent-tabs-mode . nil)))
     (makefile-mode ((indent-tabs-mode . t)))
     (c-mode . ((c-file-style . "stroustrup"))))

>                            On the other hand, variant
> from Peter Maydell (https://wiki.linaro.org/PeterMaydell/QemuEmacsStyle)
> explicitly defines everything.

I'm afraid putting this into the source tree isn't as easy, because it
involves defining a new style, which you're not supposed do in
.dir-locals.el (it's for directory local variables, not for defining
global constants and calling functions).

So users would have to put the style definition in their .emacs, and its
use in .dir-locals.el.  If we then commit the latter to the repository,
we screw everybody who hasn't added the former to his .emacs.  No go.

We could try something like

    ((nil . ((indent-tabs-mode . nil)))
     (makefile-mode ((indent-tabs-mode . t)))
     (c-mode . ((c-file-style . (if (assoc "qemu" c-style-alist)
                                    "qemu" "stroustrup")))))

but that triggers the "contains values that may not be safe" prompt, so
it's another no go.

Let's see what Peter's style adds to "stroustrup", to gauge how much
trouble getting it would be worth:

(defconst qemu-c-style
    ;; recommend to do indent-tabs-mode separately to cover other major modes
    (indent-tabs-mode . nil)
    ;; same as stroustrup
    (c-basic-offset . 4)
    ;; this is the default, and anyone changing it is nuts
    (tab-width . 8)
    ;; default
    (c-comment-only-line-offset . 0)
    ;; duplicate entry, the one below wins, this one has no effect
    (c-hanging-braces-alist . ((substatement-open before after)))
    (c-offsets-alist . ((statement-block-intro . +)
                        (substatement-open . 0)
                        (label . 0)
                        (statement-cont . +)
                        ;; up to here same as stroustrup
                        ;; except we don't have (substatement-label . 0)
                        ;; and thus default to (substatement-label . 2)
                        ;; stroustrup has + instead of 0
                        ;; C++ "namespace" blocks
                        ;; do we care to differ from stroustrup?
                        (innamespace . 0)
                        ;; stroustrup has + instead of 0
                        ;; Brace that opens an in-class inline method
                        ;; do we care to differ from stroustrup?
                        (inline-open . 0)
    ;; This isn't for indentation, it's for automatically inserting
    ;; newlines when you type braces in auto-newline minor mode.
    (c-hanging-braces-alist .
                             ;; same as stroustrup
                             ;; only qemu
                             ;; First line in an enum or static array list
                             ;; suppress auto-newlines there
                             ;; only qemu
                             ;; Subsequent lines in an enum or static array
                             ;; suppress auto-newlines there
                             ;; only qemu
                             ;; Close brace of an enum or static array list.
                             ;; suppress auto-newlines there
                             ;; same as stroustrup
                             ;; same as stroustrup
                             (block-close . c-snug-do-while)
                             ;; only qemu
                             ;; Brace that opens a class definition
                             ;; auto-newline after the brace
                             ;; stroustrup instead has
                             ;; (inexpr-class-open after)
                             ;; applies to anonymous inner classes in Java
                             (class-open . (after))
                             ;; same as stroustrup
                             (substatement-open . (after))
                             ;; only qemu
                             ;; Brace that opens a class definition
                             ;; suppress auto-newlines there
                             ;; stroustrup instead has
                             ;; (inexpr-class-close before)
                             ;; applies to anonymous inner classes in Java
                             ;; stroustrup additionally has
                             ;; A continuation of a C (or like) statement.
                             ;; (statement-cont)
                             ;; Brace that opens an "extern" block
                             ;; (extern-lang-open after)
                             ;; Likewise, C++ "namespace" block
                             ;; (namespace-open after)
                             ;; Likewise, CORBA IDL "module" block
                             ;; (module-open after)
                             ;; Likewise, CORBA CIDL "composition" block
                             ;; (composition-open after)
                             ;; Subsequent argument list lines when at
                             ;; least one argument follows on the same
                             ;; line as the arglist opening paren
                             ;; (arglist-cont-nonempty)
  "QEMU C Programming Style")

I can't find anything major.

Want me to post a formal patch adding my revised .dir-locals.el?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]