GNU bug report logs - #74339
30.0.92; CC Mode stomps C TS Mode

Previous Next

Package: emacs;

Reported by: Eli Zaretskii <eliz <at> gnu.org>

Date: Wed, 13 Nov 2024 14:02:02 UTC

Severity: normal

Found in version 30.0.92

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Alan Mackenzie <acm <at> muc.de>, 74339 <at> debbugs.gnu.org
Subject: bug#74339: 30.0.92; CC Mode stomps C TS Mode
Date: Wed, 13 Nov 2024 15:28:08 -0500
> This seems to happen due to this code in cc-mode.el:
>
>   ;; Make entries in `major-mode-remap-defaults' to ensure that when CC
>   ;; Mode has been loaded, the symbols `c-mode' etc., will call CC Mode's
>   ;; modes rather than c-ts-mode etc..
>   (when (boundp 'major-mode-remap-defaults)
>     (add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode))
>     (add-to-list 'major-mode-remap-defaults '(c-mode . c-ts-mode))
>     (add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode))
>     (let (entry)
>       (dolist (mode '(c-mode c++-mode c-or-c++-mode))
> 	(if (and (setq entry (assq mode major-mode-remap-defaults))
> 		 (null (cdr entry)))
> 	    (setq major-mode-remap-defaults
> 		  (delq entry major-mode-remap-defaults)))
> 	(push (cons mode nil) major-mode-remap-defaults))))

Interesting!

I hadn't actually looked at that code.

AFAICT it's the result of the decision to make `c-ts-mode.el` add itself
to `major-mode-remap-defaults` when the file is loaded (which AFAIK we
don't want to re-discuss).  To defend against the case where that file
was loaded without the intention to use c-ts-mode everywhere the above
code "one ups" `c-ts-mode.el`s settings so as to take precedence
over them.

Looks like an arms race to me.  🙂

I think a "more fair" solution would be to do something like:

    ;; Make entries in `major-mode-remap-defaults' to ensure that when CC
    ;; Mode has been loaded, the symbols `c-mode' etc., will call CC Mode's
    ;; modes rather than c-ts-mode etc..
    (when (boundp 'major-mode-remap-defaults)
      (dolist (mode '(c-mode c++-mode c-or-c++-mode))
        (let ((entry (assq mode major-mode-remap-defaults)))
          (when entry
            (setq major-mode-remap-defaults
                  (delq entry major-mode-remap-defaults))))))

The idea being that whichever file was loaded last (`c-mode.el` or
`c-ts-mode.el`) would take precedence.

Personally, my vote is for neither file to touch that
`major-mode-remap-defaults` variable when it is loaded.
Instead, they each could emit a message encouraging the user to
customize `major-mode-remap-alist`.
Maybe they could do that only when they see that the "other" file/mode
is also loaded (i.e. only once we have evidence that there is
a conflict).


        Stefan





This bug report was last modified 237 days ago.

Previous Next


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