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#22349: 24.5; Documentation of variable major-mode does not seem to tell the exactly true Date: Mon, 11 Jan 2016 16:33:18 +0100 Message-ID: <87lh7w2ksh.fsf@linux-qg7d.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1452530367 12137 80.91.229.3 (11 Jan 2016 16:39:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 11 Jan 2016 16:39:27 +0000 (UTC) To: 22349@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 11 17:39:14 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 1aIfUu-0004wS-WE for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Jan 2016 17:39:13 +0100 Original-Received: from localhost ([::1]:55696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIfUu-0000uE-Fa for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Jan 2016 11:39:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIfUp-0000qR-7N for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIfUk-0007g7-Mu for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIfUk-0007g3-K3 for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aIfUk-00042E-Fz for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 11:39:02 -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:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 22349 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.145253028315425 (code B ref -1); Mon, 11 Jan 2016 16:39:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Jan 2016 16:38:03 +0000 Original-Received: from localhost ([127.0.0.1]:46646 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aIfTm-00040W-My for submit@debbugs.gnu.org; Mon, 11 Jan 2016 11:38:03 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57200) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aIeTT-0002U7-MY for submit@debbugs.gnu.org; Mon, 11 Jan 2016 10:33:40 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIeTM-0005wb-NQ for submit@debbugs.gnu.org; Mon, 11 Jan 2016 10:33:34 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:55772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeTM-0005wX-J8 for submit@debbugs.gnu.org; Mon, 11 Jan 2016 10:33:32 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeTK-0002iJ-Jv for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 10:33:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIeTH-0005vG-9n for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 10:33:30 -0500 Original-Received: from mxout3.interscholz.de ([2a01:1e8:8::238]:53254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeTH-0005u6-0N for bug-gnu-emacs@gnu.org; Mon, 11 Jan 2016 10:33:27 -0500 Original-Received: from localhost (mxout3 [127.0.0.1]) by mxout3.interscholz.de (Postfix) with ESMTP id 2BE7A22A83 for ; Mon, 11 Jan 2016 16:33:24 +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 89C6721B0A for ; Mon, 11 Jan 2016 16:33:21 +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 709063403B9; Mon, 11 Jan 2016 13:57:43 +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:01 -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:111502 Archived-At: The documentation of the variable `major-mode' reads as: Documentation: Symbol for current buffer's major mode. The default value (normally `fundamental-mode') affects new buffers. A value of nil means to use the current buffer's major mode, provided it is not marked as "special". 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. You can customize this variable. Emacs 25.1.50.2 still has excatly the same wording (just some `' changed to =E2=80=98=E2=80=99, y'know). Something in the second paragraph ("When a mode ... to be set up.") doesn't seem to really describe, what happens. The text seem to suggest, that in case the default major mode is used the mode hooks run before the file content is available in the buffer. (As a consequence, this seems to explain, why point movements in the freshly opened buffer from within a mode hook doesn't work, see bug report "24.5; Mode hooks doesn't run as expected if the major mode of a new buffer is determined by the default major mode".) But look at this: - 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.) - Start emacs -Q - In the *scratch* buffer evaluate this lisp code: (setq-default major-mode 'text-mode) (add-hook 'text-mode-hook (lambda () (message "From text-mode hook: %s" (buffer-string)))) - Open the above prepared file test.abc (just a normal C-x C-f ...). Emacs presents me a new buffer in major mode text-mode, filled with the content of the file; everything so far expected.=20 But, lesser expected, after reading the major-mode variable documentation paragraph in question here, the echo area shows the output of the hook, including the whole content of the buffer. (Or look at the *Messages* buffer, to verify.) How could it be possible, that the hook sees the content of the buffer when - as the documentation say - "`find-file' switches to it [the default major mode (and running its hooks)] before it reads the contents into the buffer"? So, at least this paragraph seems not be crystal clear in describing what really happens. But my main point isn't this nit about the wording. I should not speculate inside a bug report (I know) but it seems to me, this paragraph in question is just there to 'explain away' some confusing behaviour as described and reported by me with the bug report "24.5; Mode hooks doesn't run as expected if the major mode of a new buffer is determined by the default major mode": 'Told you there is something special and strange things may happen under this circumstances'. The least surprising behaviour (at least for my eyes) would be: If a new buffer (after a `file-find') gets the default major mode because nothing in auto-mode-alist et. al. matches ensure, that the mode hooks have the same result (work at the same state of things), as if the major mode of the new buffer is determined by a match in auto-mode-alist. This is currently not so, please see my bug report "24.5; Mode hooks doesn't run as expected if the major mode of a new buffer is determined by the default major mode" If such a fix isn't so easy feasible, for whatever internal reason of the implementation please be more explicte what a hook could do and what not (that it normally can) in this case ("certain variables such as [...]" doesn't sound like a complete list, not to speak about other subtleties, as the one described in the mentioned other bug report and maybe other ones not known by me). But that would be only second-best. (Just me, saying that.) 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=3Dlocal locale-coding-system: utf-8-unix Major mode: Message Minor modes in effect: TeX-PDF-mode: t diff-auto-refine-mode: t shell-dirtrack-mode: t mml-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 line-number-mode: t auto-fill-function: message-do-auto-fill transient-mark-mode: t abbrev-mode: t Recent messages: Mark set Saved text until " (buffer-string)))) " Saving file /home/rolf/Mail/drafts/*message*-20160111-135955... Wrote /home/rolf/Mail/drafts/*message*-20160111-135955 Mark set [2 times] Desktop saved in ~/.emacs.d/ Making completion list... Quit Load-path shadows: /home/rolf/.emacs.d/elpa/icicles-20151231.1515/icicles hides ~/.emacs.d/sit= e-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 2874101 1067415) (symbols 48 99194 11) (miscs 40 6326 8385) (strings 32 380612 91766) (string-bytes 1 10940763) (vectors 16 110038) (vector-slots 8 2761784 276727) (floats 8 2281 1824) (intervals 56 454852 48000) (buffers 960 470) (heap 1024 235269 38392))