* define-derived-mode runs parent mode hook after evaluating body
@ 2007-07-20 9:00 martin rudalics
2007-07-20 16:09 ` Stefan Monnier
2007-07-20 16:11 ` Stefan Monnier
0 siblings, 2 replies; 9+ messages in thread
From: martin rudalics @ 2007-07-20 9:00 UTC (permalink / raw)
To: emacs-devel
A subtle bug with `define-derived-mode' I just met with
`change-log-mode'. The latter's definition goes as ...
(define-derived-mode change-log-mode text-mode "Change Log"
"..."
(setq left-margin 8
fill-column 74
...
...but in my .emacs I have:
(add-hook
'text-mode-hook
'(lambda () (setq fill-column 72)))
Consequently, my Change Log buffers have a `fill-column' of 72 which is
not really desirable. I obviously don't have any intention to check
which of the major modes I eventually use derive from text-mode and add
the appropriate hooks there.
Is it really useful/needed to delay the hook of the parent mode in a
derived mode until after evaluating the body?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-20 9:00 define-derived-mode runs parent mode hook after evaluating body martin rudalics
@ 2007-07-20 16:09 ` Stefan Monnier
2007-07-21 16:54 ` Richard Stallman
2007-07-20 16:11 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2007-07-20 16:09 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel
> Is it really useful/needed to delay the hook of the parent mode in a
> derived mode until after evaluating the body?
Yes. It took a good bit of effort to do it, so yes, it is useful/needed.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-20 16:09 ` Stefan Monnier
@ 2007-07-21 16:54 ` Richard Stallman
2007-07-22 3:08 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2007-07-21 16:54 UTC (permalink / raw)
To: Stefan Monnier; +Cc: rudalics, emacs-devel
> Is it really useful/needed to delay the hook of the parent mode in a
> derived mode until after evaluating the body?
Yes. It took a good bit of effort to do it, so yes, it is useful/needed.
Do you remember the sort of problems which we solved with this?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-21 16:54 ` Richard Stallman
@ 2007-07-22 3:08 ` Stefan Monnier
2007-07-22 18:37 ` Richard Stallman
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2007-07-22 3:08 UTC (permalink / raw)
To: rms; +Cc: rudalics, emacs-devel
>> Is it really useful/needed to delay the hook of the parent mode in a
>> derived mode until after evaluating the body?
> Yes. It took a good bit of effort to do it, so yes, it is useful/needed.
> Do you remember the sort of problems which we solved with this?
Customizations that need to modify variable settings based on the
major-mode's value (e.g. add an element to a list).
Or customizations that depend on the major mode's variable settings
(e.g. font-lock-mode, which if turned ON too early tends to use the
font-lock-keywords of the parent mode rather than the child's, although
this particular case was worked around specifically because just fixing
define-derived-mode wasn't sufficient).
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-22 3:08 ` Stefan Monnier
@ 2007-07-22 18:37 ` Richard Stallman
0 siblings, 0 replies; 9+ messages in thread
From: Richard Stallman @ 2007-07-22 18:37 UTC (permalink / raw)
To: Stefan Monnier; +Cc: rudalics, emacs-devel
> Do you remember the sort of problems which we solved with this?
Customizations that need to modify variable settings based on the
major-mode's value (e.g. add an element to a list).
Or customizations that depend on the major mode's variable settings
Ah, yes. Those cases have not disappeared, and we do still need to
delay the mode hooks. Although delaying mode hook would give the
desired results in this case, we can't solve the problem that way.
So what should we recommend in a case like this?
One possible recommendation is that the hook function should test
major-mode and do nothing if it is not `text-mode'. That way it won't
affect the derived modes at all. Or it could test (memq major-mode
LIST-OF-OK-MODES) or (memq major-mode LIST-OF-EXCEPTIONS).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-20 9:00 define-derived-mode runs parent mode hook after evaluating body martin rudalics
2007-07-20 16:09 ` Stefan Monnier
@ 2007-07-20 16:11 ` Stefan Monnier
2007-07-21 9:21 ` martin rudalics
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2007-07-20 16:11 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel
> (define-derived-mode change-log-mode text-mode "Change Log"
> "..."
> (setq left-margin 8
> fill-column 74
> ...
> ...but in my .emacs I have:
> (add-hook
> 'text-mode-hook
> '(lambda () (setq fill-column 72)))
The problem here is that we use text-mode both as a parent and as a real
major-mode, so you can't change "text-mode" without changing all
its derivatives.
Maybe the real text-mode should be renamed to plain-text-mode (and derive
from text-mode, of course).
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-20 16:11 ` Stefan Monnier
@ 2007-07-21 9:21 ` martin rudalics
2007-07-22 18:36 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: martin rudalics @ 2007-07-21 9:21 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
>>(define-derived-mode change-log-mode text-mode "Change Log"
>> "..."
>> (setq left-margin 8
>> fill-column 74
>> ...
>
>
>>...but in my .emacs I have:
>
>
>>(add-hook
>> 'text-mode-hook
>> '(lambda () (setq fill-column 72)))
>
>
> The problem here is that we use text-mode both as a parent and as a real
> major-mode, so you can't change "text-mode" without changing all
> its derivatives.
>
> Maybe the real text-mode should be renamed to plain-text-mode (and derive
>>from text-mode, of course).
Which would solve this special case. In general, however, I want to add
something to a parent-mode hook and pass it on to its derivatives unless
the derivatives have their own opinion about that. Well, I could do
(add-hook
'text-mode-hook
'(lambda ()
(unless (and (local-variable-p 'fill-column)
(not (equal fill-column
(default-value 'fill-column))))
(setq fill-column 72))))
but this strikes me as inconvenient, ugly, and maybe faulty.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-21 9:21 ` martin rudalics
@ 2007-07-22 18:36 ` Stefan Monnier
2007-07-22 21:22 ` martin rudalics
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2007-07-22 18:36 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel
> Which would solve this special case. In general, however, I want to add
> something to a parent-mode hook and pass it on to its derivatives unless
> the derivatives have their own opinion about that. Well, I could do
> (add-hook
> 'text-mode-hook
> '(lambda ()
> (unless (and (local-variable-p 'fill-column)
> (not (equal fill-column
> (default-value 'fill-column))))
> (setq fill-column 72))))
Other than spurious quote in front of the lambda, this looks fine to me.
More specifically it says in Elisp basically the same as what you said above
in English, so it seems to be The Right Thing.
> but this strikes me as inconvenient, ugly, and maybe faulty.
The problem is that if what you want to do is "always add 4 to fill-column",
the current behavior allows you to do that whereas your suggestion to run
the parent mode early would preclude it.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: define-derived-mode runs parent mode hook after evaluating body
2007-07-22 18:36 ` Stefan Monnier
@ 2007-07-22 21:22 ` martin rudalics
0 siblings, 0 replies; 9+ messages in thread
From: martin rudalics @ 2007-07-22 21:22 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
>>(add-hook
>> 'text-mode-hook
>> '(lambda ()
>> (unless (and (local-variable-p 'fill-column)
>> (not (equal fill-column
>> (default-value 'fill-column))))
>> (setq fill-column 72))))
>
>
> Other than spurious quote in front of the lambda, this looks fine to me.
> More specifically it says in Elisp basically the same as what you said above
> in English, so it seems to be The Right Thing.
It works when the derived mode sets a buffer-local variable. I wouldn't
know what to do for normal variables though - maybe a non-problem.
>>but this strikes me as inconvenient, ugly, and maybe faulty.
>
>
> The problem is that if what you want to do is "always add 4 to fill-column",
> the current behavior allows you to do that whereas your suggestion to run
> the parent mode early would preclude it.
Hmmm .... the parent mode runs early in any case. Do we really want its
hooks to add 4 to something defined in the body of the derived mode?
What if a hook of the derived mode wants to add another four? Do we add
eight?
martin, who never wanted to "suggest" anything in this context.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-07-22 21:22 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-20 9:00 define-derived-mode runs parent mode hook after evaluating body martin rudalics
2007-07-20 16:09 ` Stefan Monnier
2007-07-21 16:54 ` Richard Stallman
2007-07-22 3:08 ` Stefan Monnier
2007-07-22 18:37 ` Richard Stallman
2007-07-20 16:11 ` Stefan Monnier
2007-07-21 9:21 ` martin rudalics
2007-07-22 18:36 ` Stefan Monnier
2007-07-22 21:22 ` martin rudalics
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.