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: Re: Hook doesn't run as expected, if buffer mode is set from major-mode
Date: Sat, 09 Jan 2016 01:36:56 +0100	[thread overview]
Message-ID: <8760z34mhj.fsf@linux-qg7d.fritz.box> (raw)
In-Reply-To: mailman.2004.1452295936.843.help-gnu-emacs@gnu.org


Michael Heerdegen <michael_heerdegen@web.de> writes:
> Rolf Ade <rolf@pointsman.de> writes:
>> Is it me, doing something wrong or stupid? If not, what's the
>> rationale behind this behavior?
>
> Though it's better to set `default-major-mode' and use (goto-char
> (point-max)) instead of `end-of-buffer' (which sets the mark) - it
> should work as you expect.  But it doesn't.

Thanks for confirming.

The variable `default-major-mode' was, what I used since ages in my
init.el just to learn this evening, while analyzing this problem, that
this variable is obsolete since 23.2, see C-h v default-major-mode RET.

The documentation of `default-major-mode' points to major-mode. The
behavior is the same, regardless which of the two variables I use.

Also true is your note about (goto-char (point-max)). I tested both with
the same behavior. Picked just 'end-of-buffer to simplify the
reproducing recipe.

Diging further I realize, that what the documentation say explains, what
I see. C-h v major#-mode RET say:

    When a mode is used by default, `find-file' switches to it before it
    reads the contents into the buffer and before it finishes setting up
    the buffer. Thus, the mode and its hooks should not expect [...]

If the mode-hooks run, before the content is read into the buffer it
isn't surprising that (end-of-buffer) doesn't set the point at the end
of the (up to know not read into) content.

But this documentation doesn't tell the truth.

- 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 (lambda () (message "End of buffer: %s" (point-max))))

- find-file the above prepared file test.abc

If your file test.abc contains some text, as requested, something other
than 1 is show in the message line. If the content isn't read into the
buffer at the moment, the hook runs, how could it know the (point-max)
of the up to now not known data?

rolf


  parent reply	other threads:[~2016-01-09  0:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=8760z34mhj.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.