all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Rolf Ade <rolf@pointsman.de>
To: help-gnu-emacs@gnu.org
Subject: Hook doesn't run as expected, if buffer mode is set from major-mode
Date: Fri, 08 Jan 2016 20:58:01 +0100	[thread overview]
Message-ID: <87h9in4zee.fsf@linux-qg7d.fritz.box> (raw)


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	other threads:[~2016-01-08 19:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-08 19:58 Rolf Ade [this message]
2016-01-08 21:20 ` Hook doesn't run as expected, if buffer mode is set from major-mode 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h9in4zee.fsf@linux-qg7d.fritz.box \
    --to=rolf@pointsman.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.