help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hook doesn't run as expected, if buffer mode is set from major-mode


From: Rolf Ade
Subject: Hook doesn't run as expected, if buffer mode is set from major-mode
Date: Fri, 08 Jan 2016 20:58:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]