emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Mapping language to mode
@ 2024-11-17 15:55 Stefan Monnier
  0 siblings, 0 replies; only message in thread
From: Stefan Monnier @ 2024-11-17 15:55 UTC (permalink / raw)
  To: emacs-orgmode

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)



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-11-17 15:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-17 15:55 Mapping language to mode Stefan Monnier

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).