Subject: bug#74339: 30.0.92; CC Mode stomps C TS Mode

From: Eli Zaretskii <[email-masked]>
Date: Fri, 15 Nov 2024 10:17:32 +0200

> From: Stefan Monnier <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
> Date: Thu, 14 Nov 2024 16:26:35 -0500
> 
> For reference, here's the patch I'm suggesting.
> 
> 
>         Stefan
> 
> 
> diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
> index 8ce4da56ef7..2e985ef9a83 100644
> --- a/lisp/progmodes/cc-mode.el
> +++ b/lisp/progmodes/cc-mode.el
> @@ -3331,16 +3331,11 @@ c-submit-bug-report
>  ;; 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))))
> +      (while (setq entry (assq mode major-mode-remap-defaults))
> +	(setq major-mode-remap-defaults
> +	      (delq entry major-mode-remap-defaults))))))

Thanks, but wouldn't it be better to use assq-delete-all?  Your
proposed code deletes only the first entry found in the alist.  But
what if the alist has both '(c-mode . c-ts-mode) and '(c-mode) ?  Then
the second one will not be removed from the alist, AFAIU.