all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Michał Nazarewicz" <mina86@mina86.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: bug-cc-mode@gnu.org, Alan Mackenzie <acm@muc.de>, emacs-devel@gnu.org
Subject: Re: [PATCH] cc-mode: don't tread dir-local and file-local variables differently
Date: Mon, 1 Jun 2020 01:19:47 +0100	[thread overview]
Message-ID: <CA+pa1O3vd3hJAJ_KBnpe4tbAF6R63Arxc6PiYKS9h3-kCzLNUQ@mail.gmail.com> (raw)
In-Reply-To: <jwvmu5s6bwm.fsf-monnier+emacs@gnu.org>

>>> IIUC your example shows a different interaction between a global
>>> setting and file-vs-dir setting.  FWIW, I do find it surprising that
>>> file-local would be treated differently from dir-local when faced
>>> with a global setting.

>> They are treated consistently - where there are conflicting sources
>> for a particular parameter, that of the highest priority takes
>> precedence.

On Thu, 28 May 2020 at 03:21, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Maybe I misunderstood the example, but from the description I read
> there are 2 cases: one has "global + file-local" and the other has
> "global + dir-local".  So it seems those two cases should give the
> same result since the priority ordering for "global vs file-local" is
> the same as that for "global vs dir-local".
>
> Yet IIUC those two cases give different results, which would seem to
> imply that somewhere "global" takes precedence over either "file-local"
> or "dir-local", which I think would be wrong.

Correct.

The longer explanation is that if ‘c-file-style’ value comes from
a file-local variable, the specified style is set with DONT-OVERRIDE
equal nil.  If the value comes from a directory-local variable, the
style is set with DONT-OVERRIDE equal t.  In former case any global
customisation will be overridden; in the latter it won’t.

I’ve mentioned hooks earlier because it doesn’t matter if the value is
set via ‘setq-default’ in init.el, via customise or in one of cc-mode
hooks.  The end result is that a file-local ‘c-file-style’ will override
it while directory-local won’t.

On Tue, 26 May 2020 at 18:18, Alan Mackenzie <acm@muc.de> wrote:
> This was all worked out in 2009 in response to bug #3808.[1] I really
> don't think it a good idea to re-introduce bug #3808 by discarding
> its fix.

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3808

Whether that report was a bug in the first place is disputable.  In that
issue, user set ‘c-cleanup-list’ via customise; why that should take
precedence over directory-local variables remains a mystery.

Significant use-case for file- and directory-local variables is for
projects to codify their coding style.  To do that effectively, those
variables need to override user-defaults.

Other solutions to user’s issue exist.  Most don’t require introducing
inconsistency in how file- and directory-local variables behave in
cc-mode.  For example, with the following files:

* init.el:               (setq-default indent-tabs-mode nil c-basic-offset 4)
* /tmp/a/.dir-locals.el: ((nil . ((c-file-style . "python"))))
* /tmp/a/foo.cc          // empty
* /tmp/b/.dir-locals.el: ;; non-existent
* /tmp/b/foo.cc          // -*- c-file-style: "python" -*-

opening /tmp/a/foo.cc results in:
* c-basic-offset equal to 4 (coming from defaults in init.el file),
* indent-tabs-mode equal to t (coming from "python" style); and
opening /tmp/b/foo.cc results in:
* c-basic-offset equal to 8 (coming from  "python" style) and
* indent-tabs-mode equal to t (coming from "python" style).

Arguably the real problem bug #3808 exposed is that "gnu" style does not
set ‘c-cleanup-list’ to include `space-before-funcall`.

-- 
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»


  reply	other threads:[~2020-06-01  0:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200512194516.83180-1-mina86@mina86.com>
     [not found] ` <20200513184745.GA8857@ACM>
     [not found]   ` <CA+pa1O2gKba9iHpPbQCf6PibY4gg57gj2ZjC4oTy4277i5pTzg@mail.gmail.com>
     [not found]     ` <20200517142327.GA12554@ACM>
     [not found]       ` <CA+pa1O2Yoqg9Kjy-Eh7K6RUtpDXpSfWOEW5EWduZVBgY5LK8QQ@mail.gmail.com>
     [not found]         ` <20200525184412.GA8662@ACM>
2020-05-25 19:47           ` [PATCH] cc-mode: don't tread dir-local and file-local variables differently Michał Nazarewicz
2020-05-26  2:13             ` 조성빈
2020-05-26  2:28             ` Stefan Monnier
2020-05-26 17:18               ` Alan Mackenzie
2020-05-28  2:21                 ` Stefan Monnier
2020-06-01  0:19                   ` Michał Nazarewicz [this message]
2020-06-01 13:29                     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+pa1O3vd3hJAJ_KBnpe4tbAF6R63Arxc6PiYKS9h3-kCzLNUQ@mail.gmail.com \
    --to=mina86@mina86.com \
    --cc=acm@muc.de \
    --cc=bug-cc-mode@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.