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

From: Eli Zaretskii <[email-masked]>
Date: Sat, 23 Nov 2024 21:40:19 +0200

> Cc: [email-masked], [email-masked], [email-masked]
> Date: Thu, 21 Nov 2024 21:48:55 +0200
> From: Eli Zaretskii <[email-masked]>
> 
> > Date: Thu, 21 Nov 2024 21:02:55 +0200
> > Cc: [email-masked]
> > From: Dmitry Gutov <[email-masked]>
> > 
> > On 21/11/2024 09:57, Eli Zaretskii wrote:
> > > Dmitry, please consider a similar change in ruby-mode.el and
> > > ruby-ts-mode.el, since what we have there now is that once
> > > ruby-ts-mode is loaded, there's no way for users to go back to using
> > > ruby-mode unless they customize major-mode-remap-alist.
> > 
> > Could you please go ahead with whatever changes you think appropriate?
> > 
> > I didn't do (or review) either of the previous changes in that area.
> 
> I could suggest a patch, but as I don't use Ruby modes, I'd hesitate
> to install it without an okay from someone who does.

Like the patch below.  Is it okay?

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index d953ec8..903a1c5 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -2748,6 +2748,9 @@ ruby-mode
 (dolist (name (list "ruby" "rbx" "jruby" "j?ruby\\(?:[0-9.]+\\)"))
   (add-to-list 'interpreter-mode-alist (cons (purecopy name) 'ruby-mode)))
 
+(setq major-mode-remap-defaults
+      (assq-delete-all 'ruby-mode major-mode-remap-defaults))
+
 (provide 'ruby-mode)
 
 ;;; ruby-mode.el ends here
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index adcdf15..39a0d47 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -1237,8 +1237,10 @@ ruby-ts-mode
 
 (derived-mode-add-parents 'ruby-ts-mode '(ruby-mode))
 
-(if (treesit-ready-p 'ruby)
-    (add-to-list 'major-mode-remap-defaults
+(when (treesit-ready-p 'ruby)
+  (setq major-mode-remap-defaults
+        (assq-delete-all 'ruby-mode major-mode-remap-defaults))
+  (add-to-list 'major-mode-remap-defaults
                  '(ruby-mode . ruby-ts-mode)))
 
 (provide 'ruby-ts-mode)