From 1fdf0f68ccf02cc92e4fb995f82f01a6148b62e7 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Thu, 30 May 2024 12:40:07 +0000 Subject: [PATCH] In normal-mode, make c-mode call c-mode when CC Mode is loaded 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 5f11622733f..8ce4da56ef7 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -3326,6 +3326,22 @@ Key bindings: (insert (format "Buffer Style: %s\nc-emacs-features: %s\n" style c-features))))))) + +;; 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)))) + (cc-provide 'cc-mode)