From 1bd23dd102e8e264a45c5b69208a5b2fdc0be55b Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Mon, 7 Aug 2023 11:27:36 +0900 Subject: [PATCH] Consider major-mode-remap-alist to determine major-mode --- CHANGES.md | 2 ++ markdown-mode.el | 14 ++++++++++---- tests/markdown-test.el | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d4f33f82..8d3186bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ - Improve horizontal rule rendering in `markdown-view-mode` [GH-753][] - Don't load major-mode if it isn't in `auto-mode-alist`[GH-761][] - Improve `markdown-insert-table` prompt message [GH-771][] + - Consider `major-mode-remap-alist` to determine major-mode for code blocks [GH-787][] * Bug fixes: - Don't override table faces by link faces [GH-716][] @@ -57,6 +58,7 @@ [gh-774]: https://github.com/jrblevin/markdown-mode/issues/774 [gh-778]: https://github.com/jrblevin/markdown-mode/issues/778 [gh-786]: https://github.com/jrblevin/markdown-mode/pull/786 + [gh-787]: https://github.com/jrblevin/markdown-mode/issues/787 # Markdown Mode 2.5 diff --git a/markdown-mode.el b/markdown-mode.el index e0192b92..4af2fd56 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -8843,10 +8843,16 @@ LANG is a string, and the returned major mode is a symbol." (defun markdown--lang-mode-predicate (mode) (and mode (fboundp mode) - ;; https://github.com/jrblevin/markdown-mode/issues/761 - (cl-loop for pair in auto-mode-alist - for func = (cdr pair) - thereis (and (atom func) (eq mode func))))) + (or + ;; https://github.com/jrblevin/markdown-mode/issues/787 + ;; major-mode-remap-alist was introduced at Emacs 29.1 + (cl-loop for pair in (bound-and-true-p major-mode-remap-alist) + for func = (cdr pair) + thereis (and (atom func) (eq mode func))) + ;; https://github.com/jrblevin/markdown-mode/issues/761 + (cl-loop for pair in auto-mode-alist + for func = (cdr pair) + thereis (and (atom func) (eq mode func)))))) (defun markdown-fontify-code-blocks-generic (matcher last) "Add text properties to next code block from point to LAST. diff --git a/tests/markdown-test.el b/tests/markdown-test.el index 50862df4..f29f2060 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -4367,6 +4367,13 @@ Details: https://github.com/jrblevin/markdown-mode/issues/761" (let ((auto-mode-alist nil)) (should (null (markdown-get-lang-mode "emacs-lisp"))))) +(ert-deftest test-markdown-parsing/get-lang-mode-from-remap-alist () + "Test `markdown-get-lang-mode' from major-mode-remap-alist. +Details: https://github.com/jrblevin/markdown-mode/issues/787" + (when (fboundp 'treesit-available-p) + (let ((major-mode-remap-alist '((python-mode . python-ts-mode)))) + (should (eq (markdown-get-lang-mode "python") 'python-ts-mode))))) + (ert-deftest test-markdown-parsing/code-block-lang-period () "Test `markdown-code-block-lang' when language name begins with a period." (markdown-test-string "~~~ { .ruby }