mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
feat(lib): backport major-mode-remap{,-alist}
Will be necessary for treesit.el support coming to the :tools tree-sitter module later.
This commit is contained in:
@ -109,5 +109,33 @@ and return the value found in PLACE instead."
|
||||
(unless (fboundp 'bol) (defalias 'bol #'line-beginning-position))
|
||||
(unless (fboundp 'eol) (defalias 'eol #'line-end-position))
|
||||
|
||||
;; Introduced in Emacs 29+
|
||||
(unless (boundp 'major-mode-remap-alist)
|
||||
(defvar major-mode-remap-alist nil)
|
||||
(defvar-local set-auto-mode--last nil)
|
||||
(define-advice set-auto-mode-0 (:override (mode &optional keep-mode-if-same) backport-major-mode-remap)
|
||||
(unless (and keep-mode-if-same
|
||||
(or (eq (indirect-function mode)
|
||||
(indirect-function major-mode))
|
||||
(and set-auto-mode--last
|
||||
(eq mode (car set-auto-mode--last))
|
||||
(eq major-mode (cdr set-auto-mode--last)))))
|
||||
(when mode
|
||||
(funcall (major-mode-remap mode))
|
||||
(unless (eq mode major-mode)
|
||||
(setq set-auto-mode--last (cons mode major-mode)))
|
||||
mode))))
|
||||
|
||||
|
||||
;;; From Emacs 30+
|
||||
;; Introduced in Emacs 30+
|
||||
(unless (fboundp 'major-mode-remap)
|
||||
(defvar major-mode-remap-defaults nil)
|
||||
(defun major-mode-remap (mode)
|
||||
"Return the function to use to enable MODE."
|
||||
(or (cdr (or (assq mode major-mode-remap-alist)
|
||||
(assq mode major-mode-remap-defaults)))
|
||||
mode)))
|
||||
|
||||
(provide 'doom-compat)
|
||||
;;; doom-compat.el ends here
|
||||
|
Reference in New Issue
Block a user