emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] cc-mode: don't tread dir-local and file-local variables diff


From: Stefan Monnier
Subject: Re: [PATCH] cc-mode: don't tread dir-local and file-local variables differently
Date: Mon, 25 May 2020 22:28:15 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 1) /tmp/foo/.dir-locals.el exists and contains a single line:
>
>        ((nil . ((c-file-style . "bsd"))))
>
>    Opening an empty /tmp/foo/foo.c file results in ‘c-basic-offset’
>    being four and ‘c-file-style’ being "bsd".
>
> 2) /tmp/bar/.dir-locals.el does not exist but /tmp/bar/bar.c does and
>    contains a single line:
>
>        /* -*- c-file-style: "bsd" -*- */
>
>    Opening that file results in ‘c-basic-offset’ being eight and
>    ‘c-file-style’ being "bsd".  (Value of eight for the offset comes
>    from "bsd" style).

I haven't thought very deeply about those two cases, so I'm not sure
whether I'd consider it a problem or a feature.

> I maintain that in both cases ‘c-basic-offset’ should be the same.
> I further maintain that its value should be eight.  Alan disagrees and
> maintains that cc-mode-hook should overwrite settings in dir-local
> variables but should be overwritten by settings in file-local variables.

Not sure what `cc-mode-hook` has to do with it since your above example
didn't use it.

>> Just as it is sensible that a hook setting takes precedence over a
>> dir-local setting.
> No, it doesn’t.  dir-local and file-local configuration is both located
> closer to the file being open than settings specified in a hook.  Values
> in a hook apply to anything user opens anywhere.  dir-local and
> file-local variables are narrower in scope and thus should have higher
> priority.

A hook setting can perform any test it likes to adjust the setting to
any detail of the situation.  So it is definitely more specific than
a dir-locals.el setting which applies blindly to all files underneath.

> It’s highly relevant that c-file-style variable behave completely
> different whether it’s dir-local or file-local.

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.


        Stefan




reply via email to

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