In normal-mode, make c-mode call c-mode when CC Mode is loaded
authorAlan Mackenzie <acm@muc.de>
Thu, 30 May 2024 12:40:07 +0000 (12:40 +0000)
committerAlan Mackenzie <acm@muc.de>
Thu, 30 May 2024 12:40:07 +0000 (12:40 +0000)
As regards which mode normal-mode calls for the symbols c-mode,
etc., the first of the following which applies holds:
(i) If the user has made a pertinent entry in
major-mode-remap-alist, this is used.
(ii) If CC Mode has been loaded, c-mode is called.
(iii) If library c-ts-mode has been loaded, c-ts-mode is
called.
(iv) Otherwise c-mode is called.

* lisp/progmodes/cc-mode.el (top level): Add entries to
major-mode-remap-defaults to implement the above.

lisp/progmodes/cc-mode.el

index 5f11622733fc5fe552a49aa17f47da37c36ab01e..8ce4da56ef725cad280326d60c8b3717b45e3df2 100644 (file)
@@ -3326,6 +3326,22 @@ Key bindings:
        (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
                        style c-features)))))))
 
+\f
+;; 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))))
+
 \f
 (cc-provide 'cc-mode)