bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#22349: 24.5; Documentation of variable major-mode does not seem to t


From: Rolf Ade
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

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 ‘’, 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. 

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=local
  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/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 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))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]