Skip to content

Commit b761ec8

Browse files
kiennqvspinu
authored andcommitted
pm-get-mode-symbol-from-name: make use of major-mode-remap and support -ts-mode
1 parent 57dbda2 commit b761ec8

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

polymode-compat.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ Elements of ALIST that are not conses are ignored."
6969
(assoc-delete-all key alist #'eq)))
7070

7171

72+
;;; emacs 30
73+
(unless (fboundp 'major-mode-remap)
74+
(defvar major-mode-remap-alist nil)
75+
(defvar major-mode-remap-defaults nil)
76+
(defalias 'major-mode-remap
77+
(lambda (mode)
78+
"Return the function to use to enable MODE."
79+
(or (cdr (or (assq mode major-mode-remap-alist)
80+
(assq mode major-mode-remap-defaults)))
81+
mode))))
82+
7283

7384
;;; Various Wrappers for Around Advice
7485

polymode-core.el

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,29 +1977,30 @@ Return FALLBACK if non-nil, otherwise the value of
19771977
(mname (if (string-match-p "-mode$" str)
19781978
str
19791979
(concat str "-mode"))))
1980-
(or
1981-
;; direct search
1982-
(let ((mode (intern mname)))
1983-
(when (and (fboundp mode) (functionp mode))
1984-
mode))
1985-
;; downcase
1986-
(let ((mode (intern (downcase mname))))
1987-
(when (and (fboundp mode) (functionp mode))
1988-
mode))
1989-
;; auto-mode alist
1990-
(let ((dummy-file (concat "a." str)))
1991-
(cl-loop for (k . v) in auto-mode-alist
1992-
if (and (string-match-p k dummy-file)
1993-
(not (string-match-p "^poly-" (symbol-name v))))
1994-
return v))
1995-
(when (or (eq polymode-default-inner-mode 'host)
1996-
(and (fboundp polymode-default-inner-mode)
1997-
(functionp polymode-default-inner-mode)))
1998-
polymode-default-inner-mode)
1999-
(when (or (eq fallback 'host)
2000-
(and (fboundp fallback) (functionp fallback)))
2001-
fallback)
2002-
'poly-fallback-mode))))))
1980+
(major-mode-remap
1981+
(or
1982+
;; direct search
1983+
(let ((mode (intern mname)))
1984+
(when (and (fboundp mode) (functionp mode))
1985+
mode))
1986+
;; downcase
1987+
(let ((mode (intern (downcase mname))))
1988+
(when (and (fboundp mode) (functionp mode))
1989+
mode))
1990+
;; auto-mode alist
1991+
(let ((dummy-file (concat "a." str)))
1992+
(cl-loop for (k . v) in auto-mode-alist
1993+
if (and (string-match-p k dummy-file)
1994+
(not (string-match-p "^poly-" (symbol-name v))))
1995+
return v))
1996+
(when (or (eq polymode-default-inner-mode 'host)
1997+
(and (fboundp polymode-default-inner-mode)
1998+
(functionp polymode-default-inner-mode)))
1999+
polymode-default-inner-mode)
2000+
(when (or (eq fallback 'host)
2001+
(and (fboundp fallback) (functionp fallback)))
2002+
fallback)
2003+
'poly-fallback-mode)))))))
20032004

20042005
(defun pm--oref-with-parents (object slot)
20052006
"Merge slots SLOT from the OBJECT and all its parent instances."

0 commit comments

Comments
 (0)