org-src-get-lang-mode: Honor `major-mode-remap-alist'

* lisp/org-src.el (org-src-get-lang-mode): When `major-mode-remap' is
available, use it to honor `major-mode-remap-alist'.
* lisp/ox-html.el (org-html-fontify-code):
* lisp/ox-odt.el (org-odt-do-format-code): Use `org-src-get-lang-mode'.
This commit is contained in:
Stefan Monnier 2024-11-17 10:55:28 -05:00 committed by Ihor Radchenko
parent 4381f52463
commit 984c0c58bb
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 10 additions and 9 deletions

View File

@ -970,11 +970,14 @@ Org-babel commands."
(defun org-src-get-lang-mode (lang)
"Return major mode that should be used for LANG.
LANG is a string, and the returned major mode is a symbol."
(intern
(concat
(let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
(if (symbolp l) (symbol-name l) l))
"-mode")))
(let ((mode (intern
(concat
(let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
(if (symbolp l) (symbol-name l) l))
"-mode"))))
(if (fboundp 'major-mode-remap)
(major-mode-remap mode)
mode)))
(defun org-src-edit-buffer-p (&optional buffer)
"Non-nil when current buffer is a source editing buffer.

View File

@ -2368,8 +2368,7 @@ is the language used for CODE, as a string, or nil."
(org-html-encode-plain-text code))
(t
;; Map language
(setq lang (or (assoc-default lang org-src-lang-modes) lang))
(let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
(let* ((lang-mode (and lang (org-src-get-lang-mode lang))))
(cond
;; Case 1: Language is not associated with any Emacs mode
((not (functionp lang-mode))

View File

@ -3116,8 +3116,7 @@ and prefix with \"OrgSrc\". For example,
(defun org-odt-do-format-code
(code info &optional lang refs retain-labels num-start)
(let* ((lang (or (assoc-default lang org-src-lang-modes) lang))
(lang-mode (if lang (intern (format "%s-mode" lang)) #'ignore))
(let* ((lang-mode (if lang (org-src-get-lang-mode lang) #'ignore))
(code-lines (org-split-string code "\n"))
(code-length (length code-lines))
(use-htmlfontify-p (and (functionp lang-mode)