branch: externals/polymode
commit b761ec8418daac37ecdbf147bcf6bc833b066174
Author: Kien Nguyen <[email protected]>
Commit: Vitalie Spinu <[email protected]>
pm-get-mode-symbol-from-name: make use of major-mode-remap and support
-ts-mode
---
polymode-compat.el | 11 +++++++++++
polymode-core.el | 47 ++++++++++++++++++++++++-----------------------
2 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/polymode-compat.el b/polymode-compat.el
index 859fc81965..aa919b71c0 100644
--- a/polymode-compat.el
+++ b/polymode-compat.el
@@ -69,6 +69,17 @@ Elements of ALIST that are not conses are ignored."
(assoc-delete-all key alist #'eq)))
+;;; emacs 30
+(unless (fboundp 'major-mode-remap)
+ (defvar major-mode-remap-alist nil)
+ (defvar major-mode-remap-defaults nil)
+ (defalias 'major-mode-remap
+ (lambda (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))))
+
;;; Various Wrappers for Around Advice
diff --git a/polymode-core.el b/polymode-core.el
index 50f1c57824..17a7848075 100644
--- a/polymode-core.el
+++ b/polymode-core.el
@@ -1977,29 +1977,30 @@ Return FALLBACK if non-nil, otherwise the value of
(mname (if (string-match-p "-mode$" str)
str
(concat str "-mode"))))
- (or
- ;; direct search
- (let ((mode (intern mname)))
- (when (and (fboundp mode) (functionp mode))
- mode))
- ;; downcase
- (let ((mode (intern (downcase mname))))
- (when (and (fboundp mode) (functionp mode))
- mode))
- ;; auto-mode alist
- (let ((dummy-file (concat "a." str)))
- (cl-loop for (k . v) in auto-mode-alist
- if (and (string-match-p k dummy-file)
- (not (string-match-p "^poly-" (symbol-name v))))
- return v))
- (when (or (eq polymode-default-inner-mode 'host)
- (and (fboundp polymode-default-inner-mode)
- (functionp polymode-default-inner-mode)))
- polymode-default-inner-mode)
- (when (or (eq fallback 'host)
- (and (fboundp fallback) (functionp fallback)))
- fallback)
- 'poly-fallback-mode))))))
+ (major-mode-remap
+ (or
+ ;; direct search
+ (let ((mode (intern mname)))
+ (when (and (fboundp mode) (functionp mode))
+ mode))
+ ;; downcase
+ (let ((mode (intern (downcase mname))))
+ (when (and (fboundp mode) (functionp mode))
+ mode))
+ ;; auto-mode alist
+ (let ((dummy-file (concat "a." str)))
+ (cl-loop for (k . v) in auto-mode-alist
+ if (and (string-match-p k dummy-file)
+ (not (string-match-p "^poly-" (symbol-name v))))
+ return v))
+ (when (or (eq polymode-default-inner-mode 'host)
+ (and (fboundp polymode-default-inner-mode)
+ (functionp polymode-default-inner-mode)))
+ polymode-default-inner-mode)
+ (when (or (eq fallback 'host)
+ (and (fboundp fallback) (functionp fallback)))
+ fallback)
+ 'poly-fallback-mode)))))))
(defun pm--oref-with-parents (object slot)
"Merge slots SLOT from the OBJECT and all its parent instances."