GNU bug report logs - #61210
28.2; Request to modify code which can accidentally overwrite AUCTeX function

Previous Next

Package: emacs;

Reported by: Ikumi Keita <ikumi <at> ikumi.que.jp>

Date: Wed, 1 Feb 2023 12:14:01 UTC

Severity: normal

Tags: moreinfo

Found in version 28.2

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61210 in the body.
You can then email your comments to 61210 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Wed, 01 Feb 2023 12:14:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ikumi Keita <ikumi <at> ikumi.que.jp>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Wed, 01 Feb 2023 12:14:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.2; Request to modify code which can accidentally overwrite
 AUCTeX function
Date: Wed, 01 Feb 2023 21:13:16 +0900
I'm working on arranging AUCTeX to reconcile built-in tex modes better.
One of the primary aim is to avoid clash of major mode name; for
example, to change `latex-mode' to `LaTeX-mode'. In the course of
reviewing the code, I realized the following problem.

If we do that in natural ways like
(define-derived-mode LaTeX-mode text-mode "LaTeX" ...)
or
(defun LaTeX-mode () ...)
, it could wreak havoc because tex-mode.el has these lines:
----------------------------------------------------------------------
;;;###autoload
(defalias 'TeX-mode #'tex-mode)
;;;###autoload
(defalias 'plain-TeX-mode #'plain-tex-mode)
;;;###autoload
(defalias 'LaTeX-mode #'latex-mode)
----------------------------------------------------------------------
These defalias'es overwrite the AUCTeX definition unconditionally if
tex-mode.el are loaded after AUCTeX. So AUCTeX has to do workarounds
like
----------------------------------------------------------------------
(define-derived-mode TeX-latex-mode text-mode "LaTeX"
  ...
  (setq major-mode 'LaTeX-mode)
  ...)
(defalias 'LaTeX-mode #'TeX-latex-mode)
----------------------------------------------------------------------
and advertise `LaTeX-mode' as its official name. (Additionally, we need
some gotchas so that directory local variable entry like
((LaTeX-mode
  (...)))
should work.)

Hence I'd like to request to modify the built-in tex-modes.el to delete
those lines, or at least to do fboundp test like
(unless (fboundp 'LaTeX-mode)
  (defalias 'LaTeX-mode #'latex-mode))
in, say, emacs-30.

If that is accepted, we can clean up the above workarounds in the
future, when the least emacs version supported by AUCTeX becomes 30.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



In GNU Emacs 28.2 (build 1, x86_64-unknown-freebsd13.1, GTK+ Version 3.24.33, cairo version 1.17.4)
 of 2022-09-15 built on freebsd.vmware
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: 13.1-RELEASE-p5

Configured using:
 'configure --with-canna --with-canna-includes=/usr/local/canna/include
--with-canna-libraries=/usr/local/canna/lib --without-xim
--disable-largefile --without-modules --with-sound=yes
--with-file-notification=yes CFLAGS=-O3'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBXML2 NOTIFY KQUEUE PDUMPER PNG RSVG SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $EMACSLOADPATH: /home/keita/elisp:
  value of $LANG: ja_JP.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  TeX-PDF-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/keita/.emacs.d/elpa/transient-20230124.2013/transient hides /usr/local/share/emacs/28.2/lisp/transient
~/elisp/reftex-parse hides /usr/local/share/emacs/28.2/lisp/textmodes/reftex-parse
/home/keita/.emacs.d/elpa/soap-client-3.2.1/soap-inspect hides /usr/local/share/emacs/28.2/lisp/net/soap-inspect
/home/keita/.emacs.d/elpa/soap-client-3.2.1/soap-client hides /usr/local/share/emacs/28.2/lisp/net/soap-client

Features:
(shadow emacsbug mh-thread supercite regi mh-identity mh-letter mh-comp
sendmail reftex-sel reftex-ref reftex-parse preview reftex-dcr
reftex-auc reftex reftex-loaddefs reftex-vars tex-bar toolbar-x noutline
outline tex-mode shell pcomplete font-latex tex-jp latex easy-mmode
latex-flymake flymake-proc flymake project compile comint ansi-color
ring warnings tex-ispell tex-style tex texmathp latexenc mh-search qp
mm-archive smiley mail-extr mh-mime mh-gnus mh-alias multi-prompt crm
mh-show goto-addr thingatpt gnus-cite gnus-art mm-uu mml2015 mm-view
mml-smime smime dig gnus-sum shr svg dom gnus-group gnus-undo gnus-start
gnus-dbus dbus gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo
gnus-spec gnus-int message dired dired-loaddefs rfc822 mml mml-sec
mm-decode mm-bodies mm-encode gmm-utils mailheader gnus-win gnus-range
gnus nnheader wid-edit mh-seq mh-inc hl-line mh-tool-bar mh-xface
mh-utils mh-folder which-func imenu gnus-util rmail rmail-loaddefs
mail-utils text-property-search mh-scan mh-e mh-compat mailabbrev
mh-buffers mh-loaddefs skeleton misearch multi-isearch conf-mode
mule-util kinsoku cl-extra help-mode parse-time iso8601 time-date
ucs-normalize epa derived epg rfc6068 epg-config url-http url-auth
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr url-gw
nsm rmc puny jka-compr twittering-mode advice xml edmacro kmacro
preview-latex tex-site canna-im info package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json subr-x map
url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib
japan-util iso-transl tooltip eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads dbusbind kqueue lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 823574 92247)
 (symbols 48 23600 10)
 (strings 32 129178 21854)
 (string-bytes 1 5678353)
 (vectors 16 74334)
 (vector-slots 8 1690475 62672)
 (floats 8 431 886)
 (intervals 56 20117 6833)
 (buffers 992 34))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Sat, 18 Mar 2023 22:36:02 GMT) Full text and rfc822 format available.

Message #8 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2; Request to modify code which can accidentally
 overwrite AUCTeX function
Date: Sat, 18 Mar 2023 18:35:05 -0400
> If we do that in natural ways like
> (define-derived-mode LaTeX-mode text-mode "LaTeX" ...)
> or
> (defun LaTeX-mode () ...)
> , it could wreak havoc because tex-mode.el has these lines:
> ----------------------------------------------------------------------
> ;;;###autoload
> (defalias 'TeX-mode #'tex-mode)
> ;;;###autoload
> (defalias 'plain-TeX-mode #'plain-tex-mode)
> ;;;###autoload
> (defalias 'LaTeX-mode #'latex-mode)
> ----------------------------------------------------------------------
> These defalias'es overwrite the AUCTeX definition unconditionally if
> tex-mode.el are loaded after AUCTeX. So AUCTeX has to do workarounds

In Emacs-29 (see commit 18d75b4ab91fef6e344e612580088b714acfdb6e), the
above `defalias` are now predefined once and for all:

    ;;;###autoload (defalias 'TeX-mode #'tex-mode)
    ;;;###autoload (defalias 'plain-TeX-mode #'plain-tex-mode)
    ;;;###autoload (defalias 'LaTeX-mode #'latex-mode)

It's still not ideal, but at least  loading `tex-mode` won't override
any other definition such as AUCTeX's.  I'd like to hear what you think
about this "solution", both in the short term and what we could try to
do in the longer term (e.g. I'd like to aim to get rid of those
defaliases, but I'm not sure how to get there progressively.
`define-obsolete-function-alias` is not a solution because almost noone
will see those obsolescence warnings, and to make matters worse the
obsolecence will stay (and thus become incorrect) after AUCTeX redefines
the function.  Maybe we should predefine things like `TeX-mode` not as
an alias but as an actual function that emits an obsolecence warning of
some kind?).


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Mon, 20 Mar 2023 12:26:02 GMT) Full text and rfc822 format available.

Message #11 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2;
 Request to modify code which can accidentally overwrite AUCTeX
 function
Date: Mon, 20 Mar 2023 21:25:12 +0900
Hi Stefan,

>>>>> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> In Emacs-29 (see commit 18d75b4ab91fef6e344e612580088b714acfdb6e), the
> above `defalias` are now predefined once and for all:

>     ;;;###autoload (defalias 'TeX-mode #'tex-mode)
>     ;;;###autoload (defalias 'plain-TeX-mode #'plain-tex-mode)
>     ;;;###autoload (defalias 'LaTeX-mode #'latex-mode)

> It's still not ideal, but at least  loading `tex-mode` won't override
> any other definition such as AUCTeX's.

Thanks, then AUCTeX can use LaTeX-mode etc. for names of its own major
modes for emacs 29 and later. (I assume that it isn't problematic that
AUCTeX overrides unconditionally them by `autoload' for them in the init
code and
(define-derived-mode LaTeX-mode text-mode "LaTeX" ...)
or
(defun LaTeX-mode () ...)
later.)

> I'd like to hear what you think about this "solution", both in the
> short term and what we could try to do in the longer term (e.g. I'd
> like to aim to get rid of those defaliases, but I'm not sure how to
> get there progressively.

I see that `major-mode-remap-alist' was also incorporated into emacs-29.
So in short term, the conflicts between built-in modes and AUCTeX modes
will reduce, and disappear when the least supported emacs version is
raised to emacs-29.
In the longer term, I think there's no practical problem regardless
of existence of those aliases.
1. If they persist, AUCTeX changes the doc string for LaTeX-mode etc.
   in a brutal manner, but most ordinary users won't mind it. (Maybe it
   increases difficulty a bit in debug process? But I expect that
   drawback is small enough.)
2. The only reason that built-in tex-mode.el needs those aliases is, as
   you wrote in tex-mode.el, "for those users who may have files
   annotated with -*- LaTeX -*- (e.g. because they received them from
   someone using AUCTeX)." They can install AUCTeX even when those
   aliases are erased.

Best regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Mon, 20 Mar 2023 15:08:01 GMT) Full text and rfc822 format available.

Message #14 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2; Request to modify code which can accidentally
 overwrite AUCTeX function
Date: Mon, 20 Mar 2023 11:07:14 -0400
> Thanks, then AUCTeX can use LaTeX-mode etc. for names of its own major
> modes for emacs 29 and later. (I assume that it isn't problematic that
> AUCTeX overrides unconditionally them by `autoload' for them in the init
> code and
> (define-derived-mode LaTeX-mode text-mode "LaTeX" ...)
> or
> (defun LaTeX-mode () ...)
> later.)

It isn't problematic from Emacs's point of view, no.
From AUCTeX's point of view you do need to take into account that
`autoload` does nothing if the function is already defined, so AUCTeX
will need to remove the aliases before calling `autoload`.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Mon, 20 Mar 2023 17:46:02 GMT) Full text and rfc822 format available.

Message #17 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2;
 Request to modify code which can accidentally overwrite AUCTeX
 function
Date: Tue, 21 Mar 2023 02:44:55 +0900
>>>>> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> From AUCTeX's point of view you do need to take into account that
> `autoload` does nothing if the function is already defined, so AUCTeX
> will need to remove the aliases before calling `autoload`.

Ah, I see. Thank you.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Tue, 05 Sep 2023 23:30:01 GMT) Full text and rfc822 format available.

Message #20 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2; Request to modify code which can accidentally
 overwrite AUCTeX function
Date: Tue, 5 Sep 2023 16:29:25 -0700
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

>>>>>> Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> From AUCTeX's point of view you do need to take into account that
>> `autoload` does nothing if the function is already defined, so AUCTeX
>> will need to remove the aliases before calling `autoload`.
>
> Ah, I see. Thank you.

From skimming this bug report, it seems like all the issues were
resolved here?  Or is there anything left to do?




Added tag(s) moreinfo. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 05 Sep 2023 23:30:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Wed, 06 Sep 2023 06:10:01 GMT) Full text and rfc822 format available.

Message #25 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2;
 Request to modify code which can accidentally overwrite AUCTeX
 function
Date: Wed, 06 Sep 2023 15:08:57 +0900
Hi Stefan,

>>>>> Stefan Kangas <stefankangas <at> gmail.com> writes:
> From skimming this bug report, it seems like all the issues were
> resolved here?  Or is there anything left to do?

As a longer term goal, it would be ideal to remove the current autoloads
in my opinion. However, if it is considered difficult to do so for some
reason (e.g. keeping backward compatibility), I don't mind much.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine




Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Wed, 06 Sep 2023 08:03:02 GMT) Full text and rfc822 format available.

Notification sent to Ikumi Keita <ikumi <at> ikumi.que.jp>:
bug acknowledged by developer. (Wed, 06 Sep 2023 08:03:02 GMT) Full text and rfc822 format available.

Message #30 received at 61210-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 61210-done <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#61210: 28.2; Request to modify code which can accidentally
 overwrite AUCTeX function
Date: Wed, 6 Sep 2023 01:02:23 -0700
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> Hi Stefan,
>
>>>>>> Stefan Kangas <stefankangas <at> gmail.com> writes:
>> From skimming this bug report, it seems like all the issues were
>> resolved here?  Or is there anything left to do?
>
> As a longer term goal, it would be ideal to remove the current autoloads
> in my opinion. However, if it is considered difficult to do so for some
> reason (e.g. keeping backward compatibility), I don't mind much.

I think it will be a breaking change unfortunately.  To do it safely,
we'd have to obsolete the relevant functions, and introduce new ones
that are not autoloaded.  Which I guess is not ideal here.

I'm closing this bug for now.  If you can think of anything else, please
reopen this bug or file a new one.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61210; Package emacs. (Tue, 12 Sep 2023 21:53:01 GMT) Full text and rfc822 format available.

Message #33 received at 61210 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Stefan Kangas <stefankangas <at> gmail.com>, 61210 <at> debbugs.gnu.org
Subject: Re: bug#61210: 28.2; Request to modify code which can accidentally
 overwrite AUCTeX function
Date: Tue, 12 Sep 2023 17:50:37 -0400
>>>>>> Stefan Kangas <stefankangas <at> gmail.com> writes:
>> From skimming this bug report, it seems like all the issues were
>> resolved here?  Or is there anything left to do?
> As a longer term goal, it would be ideal to remove the current autoloads
> in my opinion. However, if it is considered difficult to do so for some
> reason (e.g. keeping backward compatibility), I don't mind much.

These autoloads are currently used in the case where a file says
`mode: LaTeX` to provide a fallback that redirect to `latex-mode`.

We currently don't have any other way to provide such a fallback.

Maybe the better long term strategy is to encourage users to use
`mode: latex` instead (e.g. by emitting warnings, or highlighting such
`mode:` settings), i.e. to use the mode as a specification of the
file type *without* enforcing a particular preference of major mode and
then rely on the user's `major-mode-remap-alist` to choose between
`latex-mode` and `LaTeX-mode` (or any other mode the user may fancy to
edit such files).


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 11 Oct 2023 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 191 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.