emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-orgmode@gnu.org
Subject: Mapping language to mode
Date: Sun, 17 Nov 2024 10:55:28 -0500	[thread overview]
Message-ID: <jwva5dxzwjh.fsf-monnier+emacs@gnu.org> (raw)

Would the 100% untested patch below make sense?


        Stefan


diff --git a/lisp/org/org-src.el b/lisp/org/org-src.el
index 229bf62e1c0..1f0306a1f98 100644
--- a/lisp/org/org-src.el
+++ b/lisp/org/org-src.el
@@ -970,11 +970,14 @@ org-src-do-key-sequence-at-code-block
 (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.
diff --git a/lisp/org/ox-html.el b/lisp/org/ox-html.el
index 4eb3a511b00..002978e65c3 100644
--- a/lisp/org/ox-html.el
+++ b/lisp/org/ox-html.el
@@ -2355,8 +2355,7 @@ org-html-fontify-code
       (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))
diff --git a/lisp/org/ox-odt.el b/lisp/org/ox-odt.el
index c6a70fe9cd8..1b2728d1a5d 100644
--- a/lisp/org/ox-odt.el
+++ b/lisp/org/ox-odt.el
@@ -3116,8 +3116,7 @@ org-odt-htmlfontify-string
 
 (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)



                 reply	other threads:[~2024-11-17 15:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwva5dxzwjh.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).