* dir-locals.el take precedence over user's mode-hook changes
@ 2008-12-24 18:31 Stefan Monnier
2008-12-24 19:03 ` Dan Nicolaescu
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2008-12-24 18:31 UTC (permalink / raw)
To: emacs-devel
It seems that the dir-local.el settings are applied after the major mode
hook has been run.
That makes it pretty impossible for the user to override them, which is
problematic (I noticed it because I use a tab-width of 4 in my (Emacs)
ChangeLog files and now tab-width is back to 8).
I guess it's the same problem as the one of setting file-local
variables, but for directories it's even worse. We should provide some
way to override those settings.
Currently, I add a hook to hack-local-variables-hook from within my
mode-hook, which works but isn't the most obvious. So we should at
least document this workaround. Maybe we should also provide
an option inhibit-file-local-variables which contains a list of
variables that hack-local-variables would have to ignore.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-24 18:31 dir-locals.el take precedence over user's mode-hook changes Stefan Monnier
@ 2008-12-24 19:03 ` Dan Nicolaescu
2008-12-24 20:31 ` Tom Tromey
2008-12-25 4:49 ` Miles Bader
0 siblings, 2 replies; 16+ messages in thread
From: Dan Nicolaescu @ 2008-12-24 19:03 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> It seems that the dir-local.el settings are applied after the major mode
> hook has been run.
> That makes it pretty impossible for the user to override them, which is
> problematic (I noticed it because I use a tab-width of 4 in my (Emacs)
> ChangeLog files and now tab-width is back to 8).
>
> I guess it's the same problem as the one of setting file-local
> variables, but for directories it's even worse. We should provide some
> way to override those settings.
If the user really really wants to override the settings doesn't
rm .dir-locals.el
or
changing the contents of .dir-locals.el
work well enough?
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-24 19:03 ` Dan Nicolaescu
@ 2008-12-24 20:31 ` Tom Tromey
2008-12-24 20:52 ` Juri Linkov
2008-12-25 4:49 ` Miles Bader
1 sibling, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2008-12-24 20:31 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: Stefan Monnier, emacs-devel
>>>>> "Dan" == Dan Nicolaescu <dann@ics.uci.edu> writes:
Dan> If the user really really wants to override the settings doesn't
Dan> rm .dir-locals.el
Dan> or
Dan> changing the contents of .dir-locals.el
Dan> work well enough?
My intent was for projects to check these into version control.
So, removing them is not always ok.
As I recall you can set up your own local definition for a project to
override the project's file, though. This is somewhat inconvenient,
but it ought to work.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-24 20:31 ` Tom Tromey
@ 2008-12-24 20:52 ` Juri Linkov
2008-12-30 17:20 ` Stefan Monnier
0 siblings, 1 reply; 16+ messages in thread
From: Juri Linkov @ 2008-12-24 20:52 UTC (permalink / raw)
To: Tom Tromey; +Cc: Dan Nicolaescu, Stefan Monnier, emacs-devel
> Dan> If the user really really wants to override the settings doesn't
> Dan> rm .dir-locals.el
> Dan> or
> Dan> changing the contents of .dir-locals.el
> Dan> work well enough?
>
> My intent was for projects to check these into version control.
> So, removing them is not always ok.
>
> As I recall you can set up your own local definition for a project to
> override the project's file, though. This is somewhat inconvenient,
> but it ought to work.
I agree with Stefan that the current order of calling a hook and
setting local variables (either dired-local or file-local) is wrong.
Another problem with the current order is that it is impossible to use
`bug-reference-mode' on ChangeLog files. We already have a local variable
`bug-reference-url-format' set in Local Variables to the string
"http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
(BTW, this file-local variable should be moved to .dir-locals.el)
And when I try to enable `bug-reference-mode' using the following hook:
(add-hook 'change-log-mode-hook 'bug-reference-mode)
it never gets enabled because `bug-reference-mode' tests whether
a variable `bug-reference-url-format' is non-nil before enabling this mode,
and this variable is not yet set because it gets initialized later in
`hack-local-variables'.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-24 20:52 ` Juri Linkov
@ 2008-12-30 17:20 ` Stefan Monnier
2008-12-30 23:59 ` Juri Linkov
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2008-12-30 17:20 UTC (permalink / raw)
To: Juri Linkov; +Cc: Tom Tromey, Dan Nicolaescu, emacs-devel
> I agree with Stefan that the current order of calling a hook and
> setting local variables (either dired-local or file-local) is wrong.
Just to make things clear, I do not think the current order is
necessarily wrong. I think either order will sometimes be right
sometimes be wrong, depending on the intention. E.g. it's often right
for file-local settings to take precedence over "mode-local" settings
(set by mode hook).
So rather than "just" switch the order, we need to find a way for the
user to be able to cleanly specify which behavior he wants on a case by
case basis.
> `bug-reference-url-format' set in Local Variables to the string
> "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
> (BTW, this file-local variable should be moved to .dir-locals.el)
Could you explain why you think it should be in dir-locals rather than
in the file?
> And when I try to enable `bug-reference-mode' using the following hook:
> (add-hook 'change-log-mode-hook 'bug-reference-mode)
> it never gets enabled because `bug-reference-mode' tests whether
> a variable `bug-reference-url-format' is non-nil before enabling this mode,
> and this variable is not yet set because it gets initialized later in
> `hack-local-variables'.
Please report this bug.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-30 17:20 ` Stefan Monnier
@ 2008-12-30 23:59 ` Juri Linkov
2008-12-31 1:43 ` Stefan Monnier
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Juri Linkov @ 2008-12-30 23:59 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Tom Tromey, Dan Nicolaescu, emacs-devel
> So rather than "just" switch the order, we need to find a way for the
> user to be able to cleanly specify which behavior he wants on a case by
> case basis.
Maybe something like
;; Pre-Local Variables:
;; End:
for variables set before mode hook or
;; Post-Local Variables:
;; End:
after mode hook.
>> `bug-reference-url-format' set in Local Variables to the string
>> "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
>> (BTW, this file-local variable should be moved to .dir-locals.el)
>
> Could you explain why you think it should be in dir-locals rather than
> in the file?
In the Emacs tree we have more than 50 ChangeLog files and counting.
Many ChangeLog entries refer to the bug database and repeat the same
setting:
;; bug-reference-url-format: "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
Since this setting is project-wide it is better to have it in one place.
So e.g. later after changing the url only one place needs to be changing.
>> And when I try to enable `bug-reference-mode' using the following hook:
>> (add-hook 'change-log-mode-hook 'bug-reference-mode)
>> it never gets enabled because `bug-reference-mode' tests whether
>> a variable `bug-reference-url-format' is non-nil before enabling this mode,
>> and this variable is not yet set because it gets initialized later in
>> `hack-local-variables'.
>
> Please report this bug.
Done. (Bug#1744)
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-30 23:59 ` Juri Linkov
@ 2008-12-31 1:43 ` Stefan Monnier
2008-12-31 1:54 ` Dan Nicolaescu
2008-12-31 16:39 ` Richard M Stallman
2 siblings, 0 replies; 16+ messages in thread
From: Stefan Monnier @ 2008-12-31 1:43 UTC (permalink / raw)
To: Juri Linkov; +Cc: Tom Tromey, Dan Nicolaescu, emacs-devel
>> So rather than "just" switch the order, we need to find a way for the
>> user to be able to cleanly specify which behavior he wants on a case by
>> case basis.
> Maybe something like
> ;; Pre-Local Variables:
> ;; End:
> for variables set before mode hook or
> ;; Post-Local Variables:
> ;; End:
> after mode hook.
Hmm... interesting. I was thinking of doing it in the .emacs instead,
since often the preference depends also on what is placed on the
mode-hook, and the mode-hook is under the control of the end user,
whereas the dir-locals and file-variables may be under the control of
someone else.
>> Could you explain why you think it should be in dir-locals rather than
>> in the file?
> In the Emacs tree we have more than 50 ChangeLog files and counting.
Indeed, makes sense. Sorry for not thinking.
>> Please report this bug.
> Done. (Bug#1744)
Thank you,
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-30 23:59 ` Juri Linkov
2008-12-31 1:43 ` Stefan Monnier
@ 2008-12-31 1:54 ` Dan Nicolaescu
2008-12-31 12:28 ` Juri Linkov
2008-12-31 16:39 ` Richard M Stallman
2 siblings, 1 reply; 16+ messages in thread
From: Dan Nicolaescu @ 2008-12-31 1:54 UTC (permalink / raw)
To: Juri Linkov; +Cc: Tom Tromey, Stefan Monnier, emacs-devel
Juri Linkov <juri@jurta.org> writes:
> > So rather than "just" switch the order, we need to find a way for the
> > user to be able to cleanly specify which behavior he wants on a case by
> > case basis.
>
> Maybe something like
>
> ;; Pre-Local Variables:
> ;; End:
>
> for variables set before mode hook or
>
> ;; Post-Local Variables:
> ;; End:
>
> after mode hook.
>
> >> `bug-reference-url-format' set in Local Variables to the string
> >> "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
> >> (BTW, this file-local variable should be moved to .dir-locals.el)
> >
> > Could you explain why you think it should be in dir-locals rather than
> > in the file?
>
> In the Emacs tree we have more than 50 ChangeLog files and counting.
> Many ChangeLog entries refer to the bug database and repeat the same
> setting:
>
> ;; bug-reference-url-format: "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
>
> Since this setting is project-wide it is better to have it in one place.
> So e.g. later after changing the url only one place needs to be changing.
>
> >> And when I try to enable `bug-reference-mode' using the following hook:
> >> (add-hook 'change-log-mode-hook 'bug-reference-mode)
It would be even nicer to be able to turn on this minor mode in
.dir-locals.el which together with setting bug-reference-url-format to
the right value, would make this feature work for everyone by default
with not .emacs changes.
Same goes about being able to turn on minor modes in using "Local Variables".
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-31 1:54 ` Dan Nicolaescu
@ 2008-12-31 12:28 ` Juri Linkov
2008-12-31 16:17 ` Dan Nicolaescu
0 siblings, 1 reply; 16+ messages in thread
From: Juri Linkov @ 2008-12-31 12:28 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: Tom Tromey, Stefan Monnier, emacs-devel
> > >> And when I try to enable `bug-reference-mode' using the following hook:
> > >> (add-hook 'change-log-mode-hook 'bug-reference-mode)
>
> It would be even nicer to be able to turn on this minor mode in
> .dir-locals.el which together with setting bug-reference-url-format to
> the right value, would make this feature work for everyone by default
> with not .emacs changes.
> Same goes about being able to turn on minor modes in using "Local Variables".
It's already possible to turn on minor modes in "Local Variables" using the
`mode' tag:
;; bug-reference-url-format: "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
;; mode: bug-reference
and I can confirm that with the right order as above it correctly enables
bug-reference-mode minor mode. It also works with .dir-locals.el like
((change-log-mode .
((add-log-time-zone-rule . t)
(fill-column . 74)
(bug-reference-url-format .
"http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s")
(mode . bug-reference))))
This might be suitable for the Emacs project. But I can't say if it is
acceptable as a general solution. If yes, then we should document the fact
that setting `bug-reference-url-format' in "Local Variables" also requires
enabling the corresponding minor mode later in the same place.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-31 12:28 ` Juri Linkov
@ 2008-12-31 16:17 ` Dan Nicolaescu
2008-12-31 17:27 ` Stefan Monnier
0 siblings, 1 reply; 16+ messages in thread
From: Dan Nicolaescu @ 2008-12-31 16:17 UTC (permalink / raw)
To: Juri Linkov; +Cc: Tom Tromey, Stefan Monnier, emacs-devel
Juri Linkov <juri@jurta.org> writes:
> > > >> And when I try to enable `bug-reference-mode' using the following hook:
> > > >> (add-hook 'change-log-mode-hook 'bug-reference-mode)
> >
> > It would be even nicer to be able to turn on this minor mode in
> > .dir-locals.el which together with setting bug-reference-url-format to
> > the right value, would make this feature work for everyone by default
> > with not .emacs changes.
> > Same goes about being able to turn on minor modes in using "Local Variables".
>
> It's already possible to turn on minor modes in "Local Variables" using the
> `mode' tag:
>
> ;; bug-reference-url-format: "http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=%s"
> ;; mode: bug-reference
Unfortunately this does not work, it would turn the mode off if it's
already turned on.
If you have in your .emacs:
(add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
(defun my-emacs-lisp-mode-hook () (auto-fill-mode 1))
And add to an elisp file:
;; Local Variables:
;; mode: auto-fill
;; End:
auto-fill-mode will not be turned on for that elisp file.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-31 16:17 ` Dan Nicolaescu
@ 2008-12-31 17:27 ` Stefan Monnier
2008-12-31 21:41 ` Dan Nicolaescu
0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2008-12-31 17:27 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: Juri Linkov, Tom Tromey, emacs-devel
> Unfortunately this does not work, it would turn the mode off if it's
> already turned on.
> If you have in your .emacs:
> (add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
> (defun my-emacs-lisp-mode-hook () (auto-fill-mode 1))
> And add to an elisp file:
> ;; Local Variables:
> ;; mode: auto-fill
> ;; End:
> auto-fill-mode will not be turned on for that elisp file.
Yes, that's a more general problem. I'd be inclined to change it so
that the minor mode is unconditionally turned ON rather than toggled.
Stefan
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-31 17:27 ` Stefan Monnier
@ 2008-12-31 21:41 ` Dan Nicolaescu
2008-12-31 23:50 ` Chetan Pandya
0 siblings, 1 reply; 16+ messages in thread
From: Dan Nicolaescu @ 2008-12-31 21:41 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Juri Linkov, Tom Tromey, emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > Unfortunately this does not work, it would turn the mode off if it's
> > already turned on.
>
> > If you have in your .emacs:
>
> > (add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
> > (defun my-emacs-lisp-mode-hook () (auto-fill-mode 1))
>
> > And add to an elisp file:
>
> > ;; Local Variables:
> > ;; mode: auto-fill
> > ;; End:
>
> > auto-fill-mode will not be turned on for that elisp file.
>
> Yes, that's a more general problem. I'd be inclined to change it so
> that the minor mode is unconditionally turned ON rather than toggled.
Please do that, this is a long standing issue...
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-31 21:41 ` Dan Nicolaescu
@ 2008-12-31 23:50 ` Chetan Pandya
2009-01-03 0:45 ` Juri Linkov
0 siblings, 1 reply; 16+ messages in thread
From: Chetan Pandya @ 2008-12-31 23:50 UTC (permalink / raw)
To: Stefan Monnier, Dan Nicolaescu; +Cc: Juri Linkov, Tom Tromey, emacs-devel
--- On Wed, 12/31/08, Dan Nicolaescu <dann@ics.uci.edu> wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> > > Unfortunately this does not work, it would turn the mode off if
> > > it's already turned on.
> >
> > > If you have in your .emacs:
> >
> > > (add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
> > > (defun my-emacs-lisp-mode-hook ()
> (auto-fill-mode 1))
> >
> > > And add to an elisp file:
> >
> > > ;; Local Variables:
> > > ;; mode: auto-fill
> > > ;; End:
> >
> > > auto-fill-mode will not be turned on for that elisp file.
> >
> > Yes, that's a more general problem. I'd be inclined to change it so
> > that the minor mode is unconditionally turned ON rather than toggled.
>
> Please do that, this is a long standing issue...
Isn't this going against what the documentation says? Minor modes are supposed to be preferences and the user may or may not want those modes turned on automatically.
It looks like the first mode line entry is treated as major mode and the subsequent ones as minor mode. Specifying this in the local variables section has the potential to set the major mode twice - first using set-auto-mode and then when the local variables section is processed.
Given the problem with bug-reference-mode and such, it makes sense to change the way settings are processed.
I have some ideas on this, but WDYT? (Obviously, there is a question of compatibility with existing behavior, but that doesn't seem to be a big issue with other features).
Chetan
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-31 23:50 ` Chetan Pandya
@ 2009-01-03 0:45 ` Juri Linkov
0 siblings, 0 replies; 16+ messages in thread
From: Juri Linkov @ 2009-01-03 0:45 UTC (permalink / raw)
To: pandyacus; +Cc: Tom Tromey, Dan Nicolaescu, Stefan Monnier, emacs-devel
>> > > auto-fill-mode will not be turned on for that elisp file.
>> >
>> > Yes, that's a more general problem. I'd be inclined to change it so
>> > that the minor mode is unconditionally turned ON rather than toggled.
>>
>> Please do that, this is a long standing issue...
>
> Isn't this going against what the documentation says? Minor modes are
> supposed to be preferences and the user may or may not want those
> modes turned on automatically.
This is not going against the documentation that says in
(info "(emacs) Specifying File Variables"):
You can use the `mode' "variable" to set minor modes as well as the
major modes; in fact, you can use it more than once, first to set the
major mode and then to set minor modes which are specific to particular
buffers. But most minor modes should not be specified in the file at
all, because they represent user preferences.
First, it says "to *set* minor modes" instead "to *toggle* minor modes".
So it is safe to fix the behavior according to the documentation
to set minor modes unconditionally.
Second, it says that *most* minor modes should not be specified
in the file. However, it is justified to set bug-reference-mode
as a directory-wide setting for a project.
--
Juri Linkov
http://www.jurta.org/emacs/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-30 23:59 ` Juri Linkov
2008-12-31 1:43 ` Stefan Monnier
2008-12-31 1:54 ` Dan Nicolaescu
@ 2008-12-31 16:39 ` Richard M Stallman
2 siblings, 0 replies; 16+ messages in thread
From: Richard M Stallman @ 2008-12-31 16:39 UTC (permalink / raw)
To: Juri Linkov; +Cc: tromey, dann, monnier, emacs-devel
Maybe something like
;; Pre-Local Variables:
;; End:
for variables set before mode hook or
;; Post-Local Variables:
;; End:
after mode hook.
If we want to put such a feature in the file, this is a clean spec for
it. However, putting it in the file has the consequence that it
specifies the same ordering for all users who visit the file. Is that
ok? We would need to look at use cases.
I also wonder whether the need for such a feature is enough to justify
the complexity it would add to the Emacs Manual.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: dir-locals.el take precedence over user's mode-hook changes
2008-12-24 19:03 ` Dan Nicolaescu
2008-12-24 20:31 ` Tom Tromey
@ 2008-12-25 4:49 ` Miles Bader
1 sibling, 0 replies; 16+ messages in thread
From: Miles Bader @ 2008-12-25 4:49 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: Stefan Monnier, emacs-devel
Dan Nicolaescu <dann@ics.uci.edu> writes:
> If the user really really wants to override the settings doesn't
> rm .dir-locals.el
> or
> changing the contents of .dir-locals.el
> work well enough?
They're often part of a source tree, which is typically something you
don't want to muck with for such "local" reasons.
-Miles
--
"I distrust a research person who is always obviously busy on a task."
--Robert Frosch, VP, GM Research
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2009-01-03 0:45 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-24 18:31 dir-locals.el take precedence over user's mode-hook changes Stefan Monnier
2008-12-24 19:03 ` Dan Nicolaescu
2008-12-24 20:31 ` Tom Tromey
2008-12-24 20:52 ` Juri Linkov
2008-12-30 17:20 ` Stefan Monnier
2008-12-30 23:59 ` Juri Linkov
2008-12-31 1:43 ` Stefan Monnier
2008-12-31 1:54 ` Dan Nicolaescu
2008-12-31 12:28 ` Juri Linkov
2008-12-31 16:17 ` Dan Nicolaescu
2008-12-31 17:27 ` Stefan Monnier
2008-12-31 21:41 ` Dan Nicolaescu
2008-12-31 23:50 ` Chetan Pandya
2009-01-03 0:45 ` Juri Linkov
2008-12-31 16:39 ` Richard M Stallman
2008-12-25 4:49 ` Miles Bader
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).