fix(tree-sitter): ignore major-mode-remap-defaults for ts modes

...registered with `set-tree-sitter!`. Then we don't have to chase after
packages inconsistently modifying `major-mode-remap-defaults`.
This commit is contained in:
Henrik Lissner
2025-06-28 19:32:27 +02:00
parent 22e03d7e90
commit 617d8411e6
3 changed files with 18 additions and 12 deletions

View File

@ -63,17 +63,6 @@ This is ignored by ccls.")
(add-to-list 'find-sibling-rules '("/\\([^/]+\\)\\.c\\(c\\|pp\\)?\\'" "\\1.h\\(h\\|pp\\)?\\'"))
(add-to-list 'find-sibling-rules '("/\\([^/]+\\)\\.h\\(h\\|pp\\)?\\'" "\\1.c\\(c\\|pp\\)?\\'"))
;; Delete all the default remappings created by the cc-mode package. We define
;; better ones with `set-tree-sitter!' further below, otherwise there should
;; be no remapping if the user hasn't explicitly asked for tree-sitter
;; integration.
(dolist (mode '((c++-mode . c++-ts-mode)
(c-mode . c-ts-mode)
(c-or-c++-mode . c-or-c++-ts-mode)))
(cl-callf2 delete mode major-mode-remap-defaults)
(cl-callf2 delete (list (car mode)) major-mode-remap-defaults)
(cl-callf2 rassq-delete-all (cdr mode) auto-mode-alist))
;; HACK Suppress 'Args out of range' error in when multiple modifications are
;; performed at once in a `c++-mode' buffer, e.g. with `iedit' or
;; multiple cursors.

View File

@ -22,7 +22,7 @@ Note that COMMIT is only available in Emacs >=31."
(setq recipes (ensure-list recipes))
(dolist (m (ensure-list mode))
(add-to-list
'major-mode-remap-defaults
'+tree-sitter--major-mode-remaps-alist
(cons
m (let (ensured?)
(lambda ()

View File

@ -1,5 +1,8 @@
;;; tools/tree-sitter/config.el -*- lexical-binding: t; -*-
(defvar +tree-sitter--major-mode-remaps-alist nil)
;;
;;; Packages
@ -17,6 +20,20 @@
(let ((user-emacs-directory doom-profile-data-dir))
(apply fn args)))
;; HACK: Some *-ts-mode packages modify `major-mode-remap-defaults'
;; inconsistently. Playing whack-a-mole to undo those changes is more hassle
;; then simply ignoring them (by overriding `major-mode-remap-defaults' for
;; any modes remapped with `set-tree-sitter!'). The user shouldn't touch
;; `major-mode-remap-defaults' anyway; `major-mode-remap-alist' will always
;; have precedence.
(defadvice! +tree-sitter--ignore-default-major-mode-remaps-a (fn mode)
:around #'major-mode-remap
(let ((major-mode-remap-defaults
(if-let* ((m (assq mode +tree-sitter--major-mode-remaps-alist)))
+tree-sitter--major-mode-remaps-alist
major-mode-remap-defaults)))
(funcall fn mode)))
;; TODO: Move most of these out to modules
(dolist (map '((awk "https://github.com/Beaglefoot/tree-sitter-awk" nil nil nil nil)
(bibtex "https://github.com/latex-lsp/tree-sitter-bibtex" nil nil nil nil)