[Top][All Lists]

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

Re: AUCTeX and "builtin latex mode" integration

From: Ikumi Keita
Subject: Re: AUCTeX and "builtin latex mode" integration
Date: Wed, 01 Feb 2023 18:50:34 +0900

Hi Stefan,

>>>>> Stefan Monnier <> writes:
>> 1. I first tried [A] because [B] wouldn't be easy to retain
>> compatibility for users who have
>> - a lot of files with "mode: latex" tag in the file local variables
>> section.

> The `mode:` specifies which function is called to enable the mode,
> rather than which value of `major-mode` will be used in the resulting
> buffer.

> `mode: latex` means that we'll call `latex-mode` and that function can
> activate AUCTeX's `LaTeX-mode` (which sets `major-mode` to
> `LaTeX-mode`) without any trouble.

With respect to "mode:" tag, what I want to express is that "[B]
wouldn't lead to immediate removal of the trickery codes[1] in
tex-site.el." (On the other hand, we can replace them with clearer codes
if we can take approach [A].)

> [ And in Emacs-30, you can use `major-mode-remap-alist` so that
>   `mode: latex` will not call `latex-mode` but some other function,
>   such as `LaTeX-mode`.  ]

Yes, `major-mode-remap-alist` provides a clean way. However AUCTeX still
need to keep the current code for a certain period for emacs<30 if we
take approach [B]. It would take at least several years until AUCTeX
raises the least supported version to emacs 30.

>> - hard-coded mode names in their personal customized codes.

> I don't know what problem you're thinking of here.

For example, users can have conditionals like
  (if (eq major-mode 'latex-mode) ...)
in their personal customized codes assuming that `latex-mode' is
actually AUCTeX mode.

> AFAIK the only clean way is to actually change those bindings.
> Yes, users will complain, and it may even break some 3rd party code, so
> it'll be somewhat painful.

Too bad. Then available appraoch is [B] only.

> OTOH you should be able to completely hide the "base" menus (by
> overriding their bindings with something silly like the `ignore`
> command).

Do you mean menus provided by built-in tex mode by "base" menus? Or
"File Edit Options Buffers..."?

>> 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.

> Agreed.  Could you open a bug report for that?
> (with me in `X-Debbugs-Cc:`)

I see. I'll do it later.

> Hmm... this seems directly relevant to Emacs-30's new
> `major-mode-remap-alist`.  Can you open another bug report (with me in
> `X-Debbugs-Cc:`) to discuss this.

I'll do that, too.

>> In addition, they don't need their own keymaps and syntax
>> tables created by define-derived-mode. (Own hooks and abbrev tables may
>> be useful, though.)

> You can use `:keymap` and `:syntax-table` args to `define-derived-mode`
> to avoid creating their own.

Yes. It doesn't matter much anyway.

Ikumi Keita
#StandWithUkraine #StopWarInUkraine

[1] Currently, AUCTeX adds :around advice to `latex-mode' etc.
(defconst TeX-mode-alist
  '((tex-mode . tex-mode)
    (plain-tex-mode . tex-mode)
    (texinfo-mode . texinfo)
    (latex-mode . tex-mode)
    (doctex-mode . tex-mode))
  "Alist of built-in TeX modes and their load files.")
(add-hook 'tex-site-unload-hook
          (lambda ()
            (TeX-modes-set 'TeX-modes nil)
            (setq load-path (delq TeX-lisp-directory load-path))))

(defun TeX-modes-set (var value &optional _ignored)
  "Set VAR (which should be `TeX-modes') to VALUE.

This places either the standard or the AUCTeX versions of
functions into the respective function cell of the mode."
  (custom-set-default var value)
  (let ((list TeX-mode-alist) elt)
    (while list
      (setq elt (car (pop list)))
      (let ((dst (intern (concat "TeX-" (symbol-name elt)))))
        (if (memq elt value)
            (advice-add elt :override dst
                        ;; COMPATIBILITY for Emacs 28.[12]
                        ;; Give it higher precedence than the :around
                        ;; advice given to `tex-mode' in tex-mode.el.
                        '((depth . -10)))
          (advice-remove elt dst))))))

(defcustom TeX-modes
  (mapcar #'car TeX-mode-alist)
  "List of modes provided by AUCTeX.

This variable can't be set normally; use customize for that, or
set it with `TeX-modes-set'."
  :type (cons 'set
              (mapcar (lambda(x) (list 'const (car x))) TeX-mode-alist))
  :set #'TeX-modes-set
  :initialize #'custom-initialize-reset)

reply via email to

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