unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Hook doesn't run as expected, if buffer mode is set from major-mode
@ 2016-01-08 19:58 Rolf Ade
  2016-01-08 21:20 ` Drew Adams
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Rolf Ade @ 2016-01-08 19:58 UTC (permalink / raw)
  To: help-gnu-emacs


I see the following with emacs 24.5.1 as well as with 25.1.50.2, even
with emacs -Q.

If the major mode of a new buffer is determined by the variable
major-mode (nothing from auto-mode-alist et. al matches), then the hooks
of that major mode doesn't run, as I expect.

From what I see, it looks like the hooks do run, but in this case (mode
selection comes from major-mode, not from auto-mode-alist) somehow
wrapped into a (save-excursion).

To reproduce, do:

- Prepare a file with a suffix not included in auto-mode-alist (e.g.
  test.abc) with some text in it. Create a copy of that file with the
  name test.txt

- Start emacs -Q

- In the scratch buffer, evaluate:

(setq-default major-mode 'text-mode)
(add-hook 'text-mode-hook 'end-of-buffer)

- find-file the above prepared file test.abc

After opening the file, the buffer is in fact in text-mode. But the
point is at the beginning of the buffer, not at the end (as, at least I
expected).

- Then open the file test.txt.

In this case, the major mode of the new buffer is determined by
auto-mode-alist (the default of this variable includes ("\\.te?xt\\'" .
text-mode)). After opening the file, the buffer is, as expected, also in
text-mode, but now the point is at the end of the buffer.

Further observations:

- This isn't special to text-mode. If I do the steps from above with
  another major mode (in an appropriate way), I see the same.

- From what I see, the hooks do run, even if the mode is determined by
  major-mode. You may verify this by adding

  (add-hook 'text-mode-hook 'auto-fill-mode)

  to the third step above.

Is it me, doing something wrong or stupid? If not, what's the rationale
behind this behavior?


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-01-10  4:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-08 19:58 Hook doesn't run as expected, if buffer mode is set from major-mode Rolf Ade
2016-01-08 21:20 ` Drew Adams
2016-01-08 23:32 ` Michael Heerdegen
     [not found] ` <mailman.1999.1452288065.843.help-gnu-emacs@gnu.org>
2016-01-09  0:15   ` Rolf Ade
2016-01-09  2:07     ` Drew Adams
     [not found] ` <mailman.2004.1452295936.843.help-gnu-emacs@gnu.org>
2016-01-09  0:36   ` Rolf Ade
2016-01-09  2:09     ` Drew Adams
2016-01-09  2:19     ` Michael Heerdegen
     [not found]     ` <mailman.2012.1452305981.843.help-gnu-emacs@gnu.org>
2016-01-09 22:14       ` Rolf Ade
2016-01-10  4:29         ` Michael Heerdegen

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).