From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rolf Ade Newsgroups: gmane.emacs.bugs Subject: bug#22348: 24.5; Mode hooks doesn't run as expected if the major mode of a new buffer is determined by the default major mode Date: Mon, 11 Jan 2016 13:43:32 +0100 Message-ID: <87wprg2snf.fsf@linux-qg7d.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1452530376 12215 80.91.229.3 (11 Jan 2016 16:39:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 11 Jan 2016 16:39:36 +0000 (UTC) To: 22348@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 11 17:39:22 2016 Return-path: Envelope-to: geb-bug-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 1aIfV3-00051g-I9 for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Jan 2016 17:39:21 +0100 Original-Received: from localhost ([::1]:55701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIfV3-0001AS-3d for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Jan 2016 11:39:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIfUp-0000qO-6R for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIfUk-0007fx-0e for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58426) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIfUj-0007ft-TL for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aIfUj-00041z-PQ for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Rolf Ade Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Jan 2016 16:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 22348 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.145253028215412 (code B ref -1); Mon, 11 Jan 2016 16:39:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Jan 2016 16:38:02 +0000 Original-Received: from localhost ([127.0.0.1]:46644 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aIfTl-00040N-Rt for submit@debbugs.gnu.org; Mon, 11 Jan 2016 11:38:02 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:32924) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aIbpL-0006r4-3G for submit@debbugs.gnu.org; Mon, 11 Jan 2016 07:44:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIbpD-0007A9-Qn for submit@debbugs.gnu.org; Mon, 11 Jan 2016 07:43:57 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:48828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIbpD-0007A5-NI for submit@debbugs.gnu.org; Mon, 11 Jan 2016 07:43:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIbpB-0002nk-Op for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 07:43:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIbp7-00079A-II for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 07:43:53 -0500 Original-Received: from mxout3.interscholz.de ([85.236.196.238]:42641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIbp7-00078n-79 for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 07:43:49 -0500 Original-Received: from localhost (mxout3 [127.0.0.1]) by mxout3.interscholz.de (Postfix) with ESMTP id 2FA2C22A7C for ; Mon, 11 Jan 2016 13:43:44 +0100 (CET) X-Virus-Scanned: interscholz amavisd-new at mxout3.interscholz.de Original-Received: from server.web01.interscholz.net (server.web01.interscholz.net [85.236.196.138]) by mxout3.interscholz.de (Postfix) with ESMTP id 32A3720783 for ; Mon, 11 Jan 2016 13:43:40 +0100 (CET) Original-Received: from linux-qg7d.fritz.box (p4FFBE688.dip0.t-ipconnect.de [79.251.230.136]) by server.web01.interscholz.net (Postfix) with ESMTPSA id 6AC7A3403BC; Mon, 11 Jan 2016 11:07:58 +0100 (CET) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Mailman-Approved-At: Mon, 11 Jan 2016 11:38:00 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111503 Archived-At: Although reported from my all day working emacs version I see the same behavior with emacs-25.1.50.2. Recipe to reproduce the problem: - Prepare a file with a name/suffix, that isn't matched by anything in auto-mode-alist (and interpreter-mode-alist and magic-mode-alist), with some content in it. From what I see in my tests, the exact name and content doesn't matter (as long as it fullfills the above condition). To give an exact example recipe I see it with a file named test.abc with the content of (exclude the ""): " abc abc abc" (Nothing in the default value of auto-mode-alist matches this file name test.abc.) - Create a copy of that file from above with the name test.txt. Please note, that the suffix .txt is (beside other ones) handled / matched by the default value of auto-mode-alist and points to text-mode. - Start emacs -Q - In the *scratch* buffer evaluate this lisp code: (setq-default major-mode 'text-mode) (add-hook 'text-mode-hook 'end-of-buffer) Please note that I'm aware that end-of-buffer sets the mark. That's irrelevant for what I want to show. I used end-of-buffer just for simplicity of the recipe. If I use a lamba with (goto-char (point-max)) I see the same mis-behaviour (see below). - Open the above prepared file test.abc (just a normal C-x C-f ...) Emacs presents me a new buffer, showing the content of the file. The buffer has major mode text-mode. (Since nothing out of auto-mode-alist et. al. matched, the above set default major mode applies. That's expected.) But the point is at the beginning of the buffer, not at the end. This is not expected. - To contrast, now open (also just a normal C-x C-f ...) the second file from above, test.txt. Emacs presents me another new buffer, showing the content of this file (since this file is a copy of the first one, it's exactly the same content). The buffer is in major mode text-mode. (No surprise here, .txt is handled by the default value of auto-mode-alist.) But the point is in this case at the end of the buffer (as expected). Expected behavior: In both buffers the point should be at the end of the buffer. Or, to put it more general: the mode hooks of the major mode of a new buffer should have the same effects for both files. Futher notes: - This isn't special to text-mode. I see the same mis-behaviour, if I do the recipe from above (appropriate applied) with other major modes. - Initially, from older days, I had (setq default-major-mode 'text-mode) in my init.el, just to learn while analysing the problem, that this variable is obsolete since 23.2. The documentation of default-major-mode points to major-mode. The (mis-)behaviour is the same, regardless which of the both variables I use. - In general, the hooks do run, it isn't that they just not run in the above described circumstances. So, e.g. one is able the enable auto-fill-mode by hook. - One may argue this works as documented. The documentation of major-mode includes this (not as cristal clear as it could be, I'd comment) paragraph: "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 certain variables such as `buffer-read-only' and `buffer-file-coding-system' to be set up." This seems to suggest, that (in case the default major mode is used, because nothing from auto-mode-alist et. al. matches) the mode hooks run before the file content is available in the buffer. So it seems it is no surprise, that point movements within some hook doesn't work as expected, because there isn't some content, to work on. But beside the fact, that this paragraph doesn't seem to tell the exact truth about what in fact happens (see another to be written bug report - I'll use the title "Documentation of variable major-mode does not seem to tell the exactly true") I'd call this a mis-feature. It is surprising and confusing to open two different files and then have two new buffers, both in the same major mode, but some of the hooks of that major mode have different results/effects, for (at least at first look) no obvious reason. In fact, I stubled over this in the wild. A small configuration change that I expected to be done in at max minutes took me hours. Well, this is of course not the fault of the emacs developers but completely mine, to spend so much time on this. I note this just as a random data point, that the current behaviour is confusing und surprising at least for some users and therefor not providing the best emacs experience. - As a partly workaround I've added some more suffixes to the auto-mode-alist of my configuration. It may seems possible, to specify the wished default major mode with a last entry to auto-mode-alist, that matches all and use the form (REGEXP FUNCTION NON-NIL). But this seems to be fragil (how to ensure, that entry stays the last one in auto-mode-alist?) and much more complicated then setting just major-mode (and using such a 'magic' auto-mode-alist entry isn't - at least, as far as I see - adviced anywhere). In GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.10) of 2015-04-11 on linux-qg7d Windowing system distributor `The X.Org Foundation', version 11.0.11203000 System Description: openSUSE 12.2 (x86_64) Important settings: value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=local locale-coding-system: utf-8-unix Major mode: Outline Minor modes in effect: goto-address-mode: t TeX-PDF-mode: t diff-auto-refine-mode: t shell-dirtrack-mode: t desktop-save-mode: t show-paren-mode: t tooltip-mode: t electric-indent-mode: t mouse-wheel-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t buffer-read-only: t line-number-mode: t transient-mark-mode: t view-mode: t Recent messages: Quit C-c C-p is undefined Mark set View mode: type C-h for help, h for commands, q to quit. Mark saved where search started Quit [2 times] Mark saved where search started Type C-x 1 to delete the help window. Making completion list... Load-path shadows: /home/rolf/.emacs.d/elpa/icicles-20151231.1515/icicles hides ~/.emacs.d/site-lisp/icicles Features: (benchmark vc-git follow debbugs-org rainbow-mode holidays hol-loaddefs icomplete fireplace org-capture web-beautify debbugs-browse descr-text thai-util thai-word lao-util info-look make-mode gnus-draft expand-region text-mode-expansions cc-mode-expansions the-org-mode-expansions ruby-mode-expansions python-el-fgallina-expansions nxml-mode-expansions latex-mode-expansions web-mode-expansions hippie-exp ox-latex ox-icalendar ox-html ox-ascii ox-publish ox hungry-delete ert ewoc timezone texinfo toolbar-x reporter context plain-tex debbugs-gnu add-log debbugs soap-client superword subword ruby-mode rx python json html-mode-expansions sgml-mode er-basic-expansions expand-region-core expand-region-custom diff linum mailalias smtpmail filecache arc-mode archive-mode goto-addr binhex ps-mule ps-print ps-def lpr url-queue eww mm-url canlock ido calc-misc calc-aent calc-yank finder rcirc image-file face-remap mb-depth icicles-mode icicles-face icicles-cmd2 icicles-cmd1 imenu completion icicles-mcmd image-dired icicles-fn icicles-var icicles-opt cus-theme filesets icicles-mac cl-macs warnings yow etags cookie1 bookmark recentf tree-widget cl gv autoload tar-mode lisp-mnt url-http url-gw url-cache url-auth url url-proxy url-privacy url-expand url-methods url-history url-cookie url-domsuf url-util url-handlers epg finder-inf time view org-agenda calc-incom rect sh-script smie executable animate misc nnir preview prv-emacs tex-buf font-latex latex tex-style tex dbus xml crm tex-mode latexenc profiler pcase tramp-cmds lunar solar cal-dst tramp-cache tramp-sh tramp tramp-compat tramp-loaddefs trampver calc-alg calc-ext calc-menu calc calc-loaddefs calc-macs ffap url-parse url-vars smerge-mode diff-mode compare-w cal-iso cal-move pp shadow emacsbug sendmail shell debug shr-color color ibuf-ext ibuffer tabify org-table grep compile dired-aux flyspell cus-edit ifold two-column iso-transl eieio-opt speedbar sb-image ezimage dframe gnus-fun flow-fill mule-util shr browse-url mm-archive sort smiley gnus-cite mail-extr gnus-async gnus-bcklg qp gnus-ml gnus-topic nndraft nnmh gnutls nnfolder parse-time netrc network-stream auth-source eieio byte-opt bytecomp byte-compile cconv eieio-core starttls tls gnus-agent gnus-srvr gnus-score score-mode nnvirtual gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime password-cache dig mailcap nntp gnus-cache gnus-sum nnoo gnus-group gnus-undo nnmail mail-source gnus-start gnus-spec gnus-int gnus-range message rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus-win gnus gnus-ems nnheader mail-utils mm-util mail-prsvr wid-edit misearch multi-isearch dabbrev thingatpt help-mode org-clock org-colview cl-extra org-element org-rmail org-mhe org-irc org-info org-gnus gnus-util org-docview doc-view jka-compr image-mode dired org-bibtex bibtex org-bbdb org-w3m org org-macro org-footnote org-pcomplete pcomplete org-list org-faces org-entities org-version ob-emacs-lisp ob ob-tangle ob-ref ob-lob ob-table ob-exp org-src ob-keys ob-comint ob-core ob-eval org-compat org-macs org-loaddefs format-spec find-func cal-menu calendar cal-loaddefs noutline outline easy-mmode tcl comint ansi-color ring footnote nxml-uchnm rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid nxml-mode nxml-outln nxml-rap nxml-glyph tex-site info icicles-autoloads package epg-config windmove goto-chg key-chord web-mode advice help-fns derived edmacro kmacro disp-table desktop frameset rng-loc rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns nxml-enc xmltok nxml-util delsel cus-start cus-load vc-fossil vc vc-dispatcher paren server klone-line ispell cc-langs cl-loaddefs cl-lib cc-mode cc-fonts easymenu cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs time-date tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment lisp-mode prog-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process dbusbind gfilenotify dynamic-setting system-font-setting font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs) Memory information: ((conses 16 2847334 1094304) (symbols 48 87985 352) (miscs 40 6241 8511) (strings 32 373670 98708) (string-bytes 1 10550494) (vectors 16 109922) (vector-slots 8 2743525 278850) (floats 8 2285 1943) (intervals 56 451125 51727) (buffers 960 459) (heap 1024 234127 39534))