* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
@ 2011-08-01 10:22 Štěpán Němec
2012-01-28 10:37 ` Chong Yidong
0 siblings, 1 reply; 10+ messages in thread
From: Štěpán Němec @ 2011-08-01 10:22 UTC (permalink / raw)
To: 9214
(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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2011-08-01 10:22 bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect Štěpán Němec
@ 2012-01-28 10:37 ` Chong Yidong
2012-01-28 20:24 ` Štěpán Němec
0 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2012-01-28 10:37 UTC (permalink / raw)
To: Štěpán Němec; +Cc: 9214
Štěpán Němec <stepnem@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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-28 10:37 ` Chong Yidong
@ 2012-01-28 20:24 ` Štěpán Němec
2012-01-28 22:54 ` Stefan Monnier
2012-01-28 23:34 ` Juanma Barranquero
0 siblings, 2 replies; 10+ messages in thread
From: Štěpán Němec @ 2012-01-28 20:24 UTC (permalink / raw)
To: Chong Yidong; +Cc: 9214
On Sat, 28 Jan 2012 11:37:12 +0100
Chong Yidong wrote:
> Štěpán Němec <stepnem@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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-28 20:24 ` Štěpán Němec
@ 2012-01-28 22:54 ` Stefan Monnier
2012-01-28 23:34 ` Juanma Barranquero
1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2012-01-28 22:54 UTC (permalink / raw)
To: Štěpán Němec; +Cc: Chong Yidong, 9214
> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-28 20:24 ` Štěpán Němec
2012-01-28 22:54 ` Stefan Monnier
@ 2012-01-28 23:34 ` Juanma Barranquero
2012-01-29 1:40 ` Chong Yidong
1 sibling, 1 reply; 10+ messages in thread
From: Juanma Barranquero @ 2012-01-28 23:34 UTC (permalink / raw)
To: Štěpán Němec; +Cc: Chong Yidong, 9214
2012/1/28 Štěpán Němec <stepnem@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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-28 23:34 ` Juanma Barranquero
@ 2012-01-29 1:40 ` Chong Yidong
2012-01-29 1:44 ` Juanma Barranquero
0 siblings, 1 reply; 10+ messages in thread
From: Chong Yidong @ 2012-01-29 1:40 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Štěpán Němec, 9214
Juanma Barranquero <lekktu@gmail.com> writes:
> 2012/1/28 Štěpán Němec <stepnem@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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-29 1:40 ` Chong Yidong
@ 2012-01-29 1:44 ` Juanma Barranquero
2012-01-29 16:34 ` Štěpán Němec
0 siblings, 1 reply; 10+ messages in thread
From: Juanma Barranquero @ 2012-01-29 1:44 UTC (permalink / raw)
To: Chong Yidong; +Cc: Štěpán Němec, 9214
On Sun, Jan 29, 2012 at 02:40, Chong Yidong <cyd@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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-29 1:44 ` Juanma Barranquero
@ 2012-01-29 16:34 ` Štěpán Němec
2012-01-30 4:16 ` Stefan Monnier
0 siblings, 1 reply; 10+ messages in thread
From: Štěpán Němec @ 2012-01-29 16:34 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Chong Yidong, 9214
On Sun, 29 Jan 2012 02:44:27 +0100
Juanma Barranquero wrote:
> On Sun, Jan 29, 2012 at 02:40, Chong Yidong <cyd@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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-29 16:34 ` Štěpán Němec
@ 2012-01-30 4:16 ` Stefan Monnier
2012-01-30 4:45 ` Štěpán Němec
0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2012-01-30 4:16 UTC (permalink / raw)
To: Štěpán Němec; +Cc: Juanma Barranquero, Chong Yidong, 9214
> 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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect
2012-01-30 4:16 ` Stefan Monnier
@ 2012-01-30 4:45 ` Štěpán Němec
0 siblings, 0 replies; 10+ messages in thread
From: Štěpán Němec @ 2012-01-30 4:45 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Juanma Barranquero, Chong Yidong, 9214
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
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-01-30 4:45 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-01 10:22 bug#9214: `fundamental-mode-hook' not run when setting up `fundamental-mode' under certain circumstances; Info documentation incorrect Štěpán Němec
2012-01-28 10:37 ` Chong Yidong
2012-01-28 20:24 ` Štěpán Němec
2012-01-28 22:54 ` Stefan Monnier
2012-01-28 23:34 ` Juanma Barranquero
2012-01-29 1:40 ` Chong Yidong
2012-01-29 1:44 ` Juanma Barranquero
2012-01-29 16:34 ` Štěpán Němec
2012-01-30 4:16 ` Stefan Monnier
2012-01-30 4:45 ` Štěpán Němec
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).