[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [PATCH] handle the case when a language's name isn't it's majo

From: Eric Schulte
Subject: [Orgmode] [PATCH] handle the case when a language's name isn't it's major mode's name
Date: Sun, 16 Aug 2009 17:58:11 -0600
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (darwin)

Attached is a small patch for a small issue.

Sometimes a language uses a major mode which can't be guessed from it's
name.  This patch introduces the `org-src-lang-modes' variable which can
be used to map language names to major modes when this is the case.
This is used when editing a source-code block, or when exporting
fontified source-code with htmlize.

So far the only instance of this that I know of is ocaml and
tuareg-mode, so that's the only thing that `org-src-lang-modes' is
pre-populated with.  Maybe there are other instances as well?

Thanks -- Eric

>From cd4ce4bd47398ae43d477d7a02af0e2139ddcc15 Mon Sep 17 00:00:00 2001
From: Eric Schulte <address@hidden>
Date: Sun, 16 Aug 2009 17:53:06 -0600
Subject: [PATCH] adding org-src-lang-modes to map languages to their major modes

 lisp/org-exp.el |    6 +++++-
 lisp/org-src.el |   12 +++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 7e77fc5..bc413db 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -2278,7 +2278,11 @@ INDENT was the original indentation of the block."
                   "htmlize.el 1.34 or later is needed for source code 
              (if lang
-                 (let* ((mode (and lang (intern (concat lang "-mode"))))
+                 (let* ((lang-m (when lang
+                                   (or (plist-get org-src-lang-modes
+                                                  (intern (concat ":" lang)))
+                                       lang)))
+                         (mode (and lang-m (intern (concat lang-m "-mode"))))
                         (org-inhibit-startup t)
                         (org-startup-folded nil))
                    (setq rtn
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 2a6c087..028c545 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -109,6 +109,14 @@ You may want to use this hook for example to turn off 
 or similar things which you want to have when editing a source code file,
 but which mess up the display of a snippet in Org exported files.")
+(defcustom org-src-lang-modes
+  '(:ocaml "tuareg")
+  "Property list mapping languages to their major mode.
+The key is the language name, the value is the string that should
+be inserted as the name of the major mode."
+  :group 'org-edit-structure
+  :type 'plist)
 ;;; Editing source examples
 (defvar org-src-mode-map (make-sparse-keymap))
@@ -151,7 +159,9 @@ the edited version."
       (setq beg (move-marker beg (nth 0 info))
            end (move-marker end (nth 1 info))
            code (buffer-substring-no-properties beg end)
-           lang (nth 2 info)
+           lang (or (plist-get org-src-lang-modes
+                                (intern (concat ":" (nth 2 info))))
+                     (nth 2 info))
            single (nth 3 info)
            lfmt (nth 4 info)
            nindent (nth 5 info)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]