From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rolf Ade Newsgroups: gmane.emacs.help 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 Organization: Me Message-ID: <8760z34mhj.fsf@linux-qg7d.fritz.box> References: <87h9in4zee.fsf@linux-qg7d.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1452300024 26990 80.91.229.3 (9 Jan 2016 00:40:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 9 Jan 2016 00:40:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 09 01:40:18 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aHhZp-0005Pf-TL for geh-help-gnu-emacs@m.gmane.org; Sat, 09 Jan 2016 01:40:18 +0100 Original-Received: from localhost ([::1]:38540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHhZo-0004nj-Qj for geh-help-gnu-emacs@m.gmane.org; Fri, 08 Jan 2016 19:40:16 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-X-Trace: individual.net 7H8KWPVK/4pUeDGlO8/fugPFBgpzdsaN+33AeUd3+2UHPk0BY= Cancel-Lock: sha1:Mq51zCA14D94JfSQJYEhA6m1vCU= sha1:Zik7RVrtSJABO7jc3X4hn2x61oQ= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:216376 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108666 Archived-At: Michael Heerdegen writes: > Rolf Ade 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