emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] handle the case when a language's name isn't it's major mode's name
@ 2009-08-16 23:58 Eric Schulte
  0 siblings, 0 replies; only message in thread
From: Eric Schulte @ 2009-08-16 23:58 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 568 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-adding-org-src-lang-modes-to-map-languages-to-their-.patch --]
[-- Type: text/x-patch, Size: 2257 bytes --]

From cd4ce4bd47398ae43d477d7a02af0e2139ddcc15 Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
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 formatting")))
 
 	      (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 `outline-minor-mode'
 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)
-- 
1.6.4.73.gc144


[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

only message in thread, other threads:[~2009-08-16 23:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-16 23:58 [PATCH] handle the case when a language's name isn't it's major mode's name Eric Schulte

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