* dir-local vs major-mode setting
@ 2018-11-14 18:30 Stefan Monnier
2018-11-14 21:58 ` Phil Sainty
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2018-11-14 18:30 UTC (permalink / raw)
To: emacs-devel
If we have a dir-locals.el that says:
((nil . ((indent-tabs-mode . t))))
I think it would make sense to give this setting "lower priority" than
the setting of indent-tabs-mode that might be imposed by the major mode.
I.e. maybe it should be applied in kill-all-local-variables rather than
at the end of the major mode setup.
WDYT?
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dir-local vs major-mode setting
2018-11-14 18:30 dir-local vs major-mode setting Stefan Monnier
@ 2018-11-14 21:58 ` Phil Sainty
2018-11-14 22:19 ` Stefan Monnier
0 siblings, 1 reply; 8+ messages in thread
From: Phil Sainty @ 2018-11-14 21:58 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
On 2018-11-15 07:30, Stefan Monnier wrote:
> If we have a dir-locals.el that says:
>
> ((nil . ((indent-tabs-mode . t))))
>
> I think it would make sense to give this setting "lower priority"
> than the setting of indent-tabs-mode that might be imposed by the
> major mode.
The current priority order is sensible to me.
I use the major mode hooks to set my preferred behaviour for each
mode, and dir-local settings to override them in cases where I should
*not* be using the defaults (e.g. to enforce a particular project's
coding standards).
-Phil
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dir-local vs major-mode setting
2018-11-14 21:58 ` Phil Sainty
@ 2018-11-14 22:19 ` Stefan Monnier
2018-11-15 1:18 ` Phil Sainty
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2018-11-14 22:19 UTC (permalink / raw)
To: Phil Sainty; +Cc: emacs-devel
> I use the major mode hooks to set my preferred behaviour for each
> mode, and dir-local settings to override them in cases where I should
> *not* be using the defaults (e.g. to enforce a particular project's
> coding standards).
I'm thinking of a case where the project says "you should use TABs" so
it sets
((nil . ((indent-tabs-mode . t))))
in the .dir-locals.el file. But TABs in TeX files tend to behave funny,
so tex-mode.el sets indent-tabs-mode to nil. Assuming the
.dir-locals.el setting was meant for "the majority of the files" and
those aren't .tex files, it would make sense to favor the major
mode's setting for the few .tex files.
I guess sometimes you want one and sometimes you want the other.
So maybe to handle that case we'd want to introduce another wildcard
that works like the `nil` above but implies it's applied before running
the major mode's setup function.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dir-local vs major-mode setting
2018-11-14 22:19 ` Stefan Monnier
@ 2018-11-15 1:18 ` Phil Sainty
2018-11-15 3:00 ` Stefan Monnier
0 siblings, 1 reply; 8+ messages in thread
From: Phil Sainty @ 2018-11-15 1:18 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
On 2018-11-15 11:19, Stefan Monnier wrote:
> I'm thinking of a case where the project says "you should use TABs" so
> it sets
>
> ((nil . ((indent-tabs-mode . t))))
>
> in the .dir-locals.el file. But TABs in TeX files tend to behave
> funny, so tex-mode.el sets indent-tabs-mode to nil. Assuming the
> .dir-locals.el setting was meant for "the majority of the files"
> and those aren't .tex files, it would make sense to favor the major
> mode's setting for the few .tex files.
If the project is expected to contain .tex files then the above would
constitute a bug in the .dir-locals.el file (which should contain mode-
specific entries for exceptions to the global settings).
Users could either fix the .dir-locals.el file, or add their own
custom .dir-locals-2.el file with the necessary overrides.
They can also use `hack-local-variables-hook'.
> I guess sometimes you want one and sometimes you want the other.
> So maybe to handle that case we'd want to introduce another wildcard
> that works like the `nil` above but implies it's applied before running
> the major mode's setup function.
If a "hack certain local vars before running hooks" facility was added,
I wouldn't think it should be constrained to the nil case?
Perhaps add something like the string path syntax, under which you
can provide a complete dir-locals spec, which should run early. The
key might be a keyword like :early or some such.
-Phil
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dir-local vs major-mode setting
2018-11-15 1:18 ` Phil Sainty
@ 2018-11-15 3:00 ` Stefan Monnier
2018-11-15 3:12 ` Phil Sainty
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2018-11-15 3:00 UTC (permalink / raw)
To: Phil Sainty; +Cc: emacs-devel
> If the project is expected to contain .tex files then the above would
> constitute a bug in the .dir-locals.el file (which should contain mode-
> specific entries for exceptions to the global settings).
The whole point of `nil` is that it's not mode-specific.
>> I guess sometimes you want one and sometimes you want the other.
>> So maybe to handle that case we'd want to introduce another wildcard
>> that works like the `nil` above but implies it's applied before running
>> the major mode's setup function.
> If a "hack certain local vars before running hooks" facility was added,
> I wouldn't think it should be constrained to the nil case?
For the non-nil case, the need is much less severe: for any given major
mode, in 99% of the cases, an early setting will either have no effect
or have the same effect as a late setting.
This said, for parent major modes (e.g. prog-mode, text-mode), it can
still be useful in more than 1% of the cases, indeed.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dir-local vs major-mode setting
2018-11-15 3:00 ` Stefan Monnier
@ 2018-11-15 3:12 ` Phil Sainty
2018-11-15 3:27 ` Stefan Monnier
0 siblings, 1 reply; 8+ messages in thread
From: Phil Sainty @ 2018-11-15 3:12 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
On 2018-11-15 16:00, Stefan Monnier wrote:
>> If the project is expected to contain .tex files then the above would
>> constitute a bug in the .dir-locals.el file (which should contain
>> mode-
>> specific entries for exceptions to the global settings).
>
> The whole point of `nil` is that it's not mode-specific.
Sorry, I shouldn't have said "global" there; that was confusing.
I was referring to the nil case.
i.e. I would expect the .dir-locals.el to have, say:
((nil . ((indent-tabs-mode . t)))
(tex-mode . ((indent-tabs-mode . nil))))
So that tex-mode files don't use tabs, but other modes will.
However, I've also just noticed that Emacs 26.1 appears to have broken/
inverted the way that such overrides work.
https://emacs.stackexchange.com/a/46005/454
-Phil
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: dir-local vs major-mode setting
2018-11-15 3:12 ` Phil Sainty
@ 2018-11-15 3:27 ` Stefan Monnier
2018-11-16 9:36 ` Phil Sainty
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2018-11-15 3:27 UTC (permalink / raw)
To: emacs-devel
>>> If the project is expected to contain .tex files then the above would
>>> constitute a bug in the .dir-locals.el file (which should contain mode-
>>> specific entries for exceptions to the global settings).
>>
>> The whole point of `nil` is that it's not mode-specific.
>
> Sorry, I shouldn't have said "global" there; that was confusing.
> I was referring to the nil case.
>
> i.e. I would expect the .dir-locals.el to have, say:
>
> ((nil . ((indent-tabs-mode . t)))
> (tex-mode . ((indent-tabs-mode . nil))))
>
> So that tex-mode files don't use tabs, but other modes will.
But having to add
(tex-mode . ((indent-tabs-mode . nil)))
when the major mode normally does it for you is kind of a let-down.
IOW, I think .dir-locals.el should offer some way to say "for files in
this directory, behave as if var `foo` was `setq-default` to `bar`".
> However, I've also just noticed that Emacs 26.1 appears to have broken/
> inverted the way that such overrides work.
>
> https://emacs.stackexchange.com/a/46005/454
That looks like a bug.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-11-16 9:36 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-14 18:30 dir-local vs major-mode setting Stefan Monnier
2018-11-14 21:58 ` Phil Sainty
2018-11-14 22:19 ` Stefan Monnier
2018-11-15 1:18 ` Phil Sainty
2018-11-15 3:00 ` Stefan Monnier
2018-11-15 3:12 ` Phil Sainty
2018-11-15 3:27 ` Stefan Monnier
2018-11-16 9:36 ` Phil Sainty
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).