Subject: Re: bug#69191: 30.0.50; New var `major-mode-remap-defaults`, for packages

From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 21 Feb 2024 14:44:52 +0100

Stefan Monnier [2024-02-16 10:45 -0500] wrote:

> While `major-mode-remap-alist` provides a way for users to indicate the
> major mode of their choice, I think we need a similar variable for the
> use of packages.
>
> The package below accordingly adds a new `major-mode-remap-defaults`
> and changes various packages to obey it or make use of it.
> I think it nicely cleans the regexp duplication between CC-mode and
> `c-ts-mode.el` and also makes it easier/cleaner for users to override
> the changes made by `*-ts-mode.el`.

SGTM.

> There are some FIXMEs that one might want to address, most importantly
> whether we should use an indirection through `major-mode-remap-defaults`
> for all TS modes or only for those for which we provide a non-TS mode.

My gut says: we shouldn't add out-of-tree modes (e.g. go-mode) to
auto-mode-alist (they should and already do that themselves); and so
long as TS modes are viewed as an optional alternative, then they should
be responsible for setting up major-mode-remap-defaults (so it should be
a no-op if they remap from an out-of-tree mode that is not installed).

If/as TS modes become more canonical, perhaps the remapping should be
bidirectional?

> +  (let ((mode
> +         (if (save-excursion
> +               (save-restriction
> +                 (save-match-data       ; Why `save-match-data'?
> +                   (widen)
> +                   (goto-char (point-min))
> +                   (re-search-forward c-ts-mode--c-or-c++-regexp nil t))))
> +             'c++-ts-mode)
> +         'c-ts-mode))

I'm excited for this new let-syntax to catch on, but maybe as a separate
feature request.

> -;;;###autoload (defalias 'TeX-mode #'tex-mode)
> -;;;###autoload (defalias 'plain-TeX-mode #'plain-tex-mode)
> -;;;###autoload (defalias 'LaTeX-mode #'latex-mode)
> +;;;###autoload (add-to-list 'major-mode-remap-defaults '(TeX-mode . tex-mode))
> +;;;###autoload (add-to-list 'major-mode-remap-defaults '(plain-TeX-mode . plain-tex-mode))
> +;;;###autoload (add-to-list 'major-mode-remap-defaults '(LaTeX-mode . latex-mode))

Can we really afford to lose the aliases in loaddefs.el?
There are at least a few in-tree uses of the AUCTeX names.

Thanks,
-- 
Basil