Skip to content

Commit

Permalink
Consider major-mode-remap-alist to determine major-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
syohex committed Aug 7, 2023
1 parent 8781cf9 commit 1bd23dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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][]
Expand Down Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 1bd23dd

Please sign in to comment.