Fix overriding 'c-ts-mode' by 'c-mode'

* lisp/progmodes/c-ts-mode.el: Remove all c- and c++-mode
associations from 'major-mode-remap-defaults' before installing
entries that remap to 'c-ts-mode' and 'c++-ts-mode'.  (Bug#74339)
This commit is contained in:
Eli Zaretskii 2024-11-21 09:43:34 +02:00
parent 331610aef0
commit 70dd5705e1

View file

@ -1488,19 +1488,20 @@ the code is C or C++, and based on that chooses whether to enable
'c-ts-mode))) 'c-ts-mode)))
(funcall (major-mode-remap mode)))) (funcall (major-mode-remap mode))))
;; The entries for C++ must come first to prevent *.c files be taken (when (treesit-ready-p 'cpp)
;; as C++ on case-insensitive filesystems, since *.C files are C++, (setq major-mode-remap-defaults
;; not C. (assq-delete-all 'c++-mode major-mode-remap-defaults))
(if (treesit-ready-p 'cpp) (add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode)))
(add-to-list 'major-mode-remap-defaults
'(c++-mode . c++-ts-mode)))
(when (treesit-ready-p 'c) (when (treesit-ready-p 'c)
(add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode)) (setq major-mode-remap-defaults
(assq-delete-all 'c-mode 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)))
(when (and (treesit-ready-p 'cpp) (when (and (treesit-ready-p 'cpp)
(treesit-ready-p 'c)) (treesit-ready-p 'c))
(setq major-mode-remap-defaults
(assq-delete-all 'c-or-c++-mode major-mode-remap-defaults))
(add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode))) (add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode)))
(provide 'c-ts-mode) (provide 'c-ts-mode)