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: Hook doesn't run as expected, if buffer mode is set from major-mode Date: Fri, 08 Jan 2016 20:58:01 +0100 Organization: Me Message-ID: <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 1452283223 29704 80.91.229.3 (8 Jan 2016 20:00:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jan 2016 20:00:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 08 21:00:23 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 1aHdCw-0000oi-JG for geh-help-gnu-emacs@m.gmane.org; Fri, 08 Jan 2016 21:00:22 +0100 Original-Received: from localhost ([::1]:37945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aHdCw-0004k1-3x for geh-help-gnu-emacs@m.gmane.org; Fri, 08 Jan 2016 15:00:22 -0500 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 52 Original-X-Trace: individual.net f+PHvsVcfwTvAvfMtCfBngStYgTNagXq1A1RY8oPUsfNC/exE= Cancel-Lock: sha1:5w4jANzcKR9RydpfX3p3M/BY0Ac= sha1:duHHl6LiyRy4ZctaUdYu9NdbMr8= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:216370 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:108660 Archived-At: 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?