GNU bug report logs -
#9214
`fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
Previous Next
Reported by: Štěpán Němec <stepnem <at> gmail.com>
Date: Mon, 1 Aug 2011 10:28:01 UTC
Severity: normal
Done: Chong Yidong <cyd <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9214 in the body.
You can then email your comments to 9214 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Mon, 01 Aug 2011 10:28:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Štěpán Němec <stepnem <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 01 Aug 2011 10:28:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
(emacs-version)
"GNU Emacs 24.0.50.6 (i686-pc-linux-gnu) of 2011-01-15 on headley"
Steps to reproduce:
-------------------
emacs -Q
(defvar f-m-hook-run 0)
(add-hook 'fundamental-mode-hook
(lambda () (setq f-m-hook-run (1+ f-m-hook-run))))
(with-current-buffer (get-buffer-create "f-m-test-buf")
major-mode)
;=> fundamental-mode
f-m-hook-run
;=> 0
(with-current-buffer (get-buffer-create "f-m-test-buf")
(fundamental-mode)
major-mode)
;=> fundamental-mode
f-m-hook-run
;=> 1
A related problem: (info "(elisp)Auto Major Mode") states:
-- Command: fundamental-mode
Fundamental mode is a major mode that is not specialized for
anything in particular. Other major modes are defined in effect
by comparison with this one--their definitions say what to change,
starting from Fundamental mode. The `fundamental-mode' function
does _not_ run any mode hooks; you're not supposed to customize
it. (If you want Emacs to behave differently in Fundamental mode,
change the _global_ state of Emacs.)
Which is incorrect, as the recipe above shows (the hook _is_ run when
`fundamental-mode' is called explicitly).
--
Štěpán
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sat, 28 Jan 2012 10:39:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 9214 <at> debbugs.gnu.org (full text, mbox):
Štěpán Němec <stepnem <at> gmail.com> writes:
> emacs -Q
>
> (defvar f-m-hook-run 0)
>
> (add-hook 'fundamental-mode-hook
> (lambda () (setq f-m-hook-run (1+ f-m-hook-run))))
>
> (with-current-buffer (get-buffer-create "f-m-test-buf")
> major-mode)
> ;=> fundamental-mode
>
> f-m-hook-run
> ;=> 0
>
> (with-current-buffer (get-buffer-create "f-m-test-buf")
> (fundamental-mode)
> major-mode)
> ;=> fundamental-mode
>
> f-m-hook-run
> ;=> 1
This was fixed a few months ago (2011-10-27 commit to simple.el).
Closing the bug. Thanks.
bug closed, send any further explanations to
9214 <at> debbugs.gnu.org and Štěpán Němec <stepnem <at> gmail.com>
Request was from
Chong Yidong <cyd <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Sat, 28 Jan 2012 10:39:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sat, 28 Jan 2012 20:26:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 9214 <at> debbugs.gnu.org (full text, mbox):
On Sat, 28 Jan 2012 11:37:12 +0100
Chong Yidong wrote:
> Štěpán Němec <stepnem <at> gmail.com> writes:
>
>> emacs -Q
>>
>> (defvar f-m-hook-run 0)
>>
>> (add-hook 'fundamental-mode-hook
>> (lambda () (setq f-m-hook-run (1+ f-m-hook-run))))
>>
>> (with-current-buffer (get-buffer-create "f-m-test-buf")
>> major-mode)
>> ;=> fundamental-mode
>>
>> f-m-hook-run
>> ;=> 0
>>
>> (with-current-buffer (get-buffer-create "f-m-test-buf")
>> (fundamental-mode)
>> major-mode)
>> ;=> fundamental-mode
>>
>> f-m-hook-run
>> ;=> 1
>
> This was fixed a few months ago (2011-10-27 commit to simple.el).
> Closing the bug. Thanks.
Well, with current emacs-snapshot (GNU Emacs 24.0.92.1
(i486-pc-linux-gnu, GTK+ Version 3.2.3) of 2012-01-26 on zelenka,
modified by Debian) I get `0' even for the second time above. So now
`fundamental-mode-hook' doesn't seem to be run at all? That fixes the
documentation problem I guess, but is certainly not what I need.
What's the point of having `fundamental-mode-hook' at all, if it isn't
ever run?
And, how can I run code whenever a new buffer is setup (in
fundamental-mode), if `fundamental-mode-hook' is not meant for that?
--
Štěpán
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sat, 28 Jan 2012 22:56:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 9214 <at> debbugs.gnu.org (full text, mbox):
> What's the point of having `fundamental-mode-hook' at all, if it isn't
> ever run?
There is no fundamental-mode-hook any more.
> And, how can I run code whenever a new buffer is setup (in
> fundamental-mode), if `fundamental-mode-hook' is not meant for that?
You can't.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sat, 28 Jan 2012 23:36:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 9214 <at> debbugs.gnu.org (full text, mbox):
2012/1/28 Štěpán Němec <stepnem <at> gmail.com>:
> And, how can I run code whenever a new buffer is setup (in
> fundamental-mode), if `fundamental-mode-hook' is not meant for that?
You can perhaps fake it with some combination of (setq-default
major-mode my-fundamental-mode), `buffer-list-update-hook', and
advices. It won't be pretty, though.
Juanma
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sun, 29 Jan 2012 01:41:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 9214 <at> debbugs.gnu.org (full text, mbox):
Juanma Barranquero <lekktu <at> gmail.com> writes:
> 2012/1/28 Štěpán Němec <stepnem <at> gmail.com>:
>
>> And, how can I run code whenever a new buffer is setup (in
>> fundamental-mode), if `fundamental-mode-hook' is not meant for that?
>
> You can perhaps fake it with some combination of (setq-default
> major-mode my-fundamental-mode), `buffer-list-update-hook', and
> advices. It won't be pretty, though.
Or use after-change-major-mode-hook.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sun, 29 Jan 2012 01:46:02 GMT)
Full text and
rfc822 format available.
Message #25 received at 9214 <at> debbugs.gnu.org (full text, mbox):
On Sun, Jan 29, 2012 at 02:40, Chong Yidong <cyd <at> gnu.org> wrote:
> Or use after-change-major-mode-hook.
The OP's use case
(with-current-buffer (get-buffer-create "f-m-test-buf")
major-mode)
does not run after-change-major-mode-hook, I think.
Juanma
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Sun, 29 Jan 2012 16:35:01 GMT)
Full text and
rfc822 format available.
Message #28 received at 9214 <at> debbugs.gnu.org (full text, mbox):
On Sun, 29 Jan 2012 02:44:27 +0100
Juanma Barranquero wrote:
> On Sun, Jan 29, 2012 at 02:40, Chong Yidong <cyd <at> gnu.org> wrote:
>
>> Or use after-change-major-mode-hook.
>
> The OP's use case
>
> (with-current-buffer (get-buffer-create "f-m-test-buf")
> major-mode)
>
> does not run after-change-major-mode-hook, I think.
Exactly. I need a way to run code for _any_ new buffer (I don't really
need to run the code for temporary buffers which never get any user
interaction, but I don't think there is a way to set those apart), no
matter how it is created.
Is that really so much to ask?
If so, I suppose a `display-buffer-functions' hook as proposed by Juanma
on emacs-devel just now[1] would be something I could make do with (the
problem with that solution would be that I only need to run the code
once when the buffer is created, but I guess testing a variable every
time a buffer is displayed isn't worse than running useless code for
never-displayed temporary buffers).
`after-change-major-mode-hook' is what I use, but it is not run for new
default-moded buffers, even when I setq-default `major-mode' to
something else than `fundamental-mode' (maybe because `major-mode' is
only used when the buffer is created by `find-file'? The `major-mode'
docstring needs some clarification in that respect).
[1] <http://permalink.gmane.org/gmane.emacs.devel/147999>
--
Štěpán
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Mon, 30 Jan 2012 04:17:02 GMT)
Full text and
rfc822 format available.
Message #31 received at 9214 <at> debbugs.gnu.org (full text, mbox):
> Exactly. I need a way to run code for _any_ new buffer (I don't really
> need to run the code for temporary buffers which never get any user
> interaction, but I don't think there is a way to set those apart), no
There is a way: whether they call a major-mode function or not.
Of course, some packages may erroneously forget to call a major-mode
function for those buffers, but the problem is in those packages.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#9214
; Package
emacs
.
(Mon, 30 Jan 2012 04:47:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 9214 <at> debbugs.gnu.org (full text, mbox):
On Sun, Jan 29, 2012 at 11:16:11PM -0500, Stefan Monnier wrote:
> > Exactly. I need a way to run code for _any_ new buffer (I don't
> > really need to run the code for temporary buffers which never get
> > any user interaction, but I don't think there is a way to set those
> > apart), no
>
> There is a way: whether they call a major-mode function or not.
Ooh, I did not know that. Thanks. Is this documented somewhere? (I.e., a
recommendation that a major mode function should be called in any buffer
of potential interest to the user.)
In that case, `after-change-major-mode-hook' should do, after all.
> Of course, some packages may erroneously forget to call a major-mode
> function for those buffers, but the problem is in those packages.
Yes, I admit I have code around that does(n't do) that myself (e.g.
simple dumping of some text into a buffer left in fundamental-mode), as
I had no idea calling e.g. `fundamental-mode' in a buffer already in
fundamental-mode was supposed to be of some value (until I bumped into
this problem, that is).
--
Štěpán
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 27 Feb 2012 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 13 years and 174 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.