Browse Source

Allow language names where the major mode name seems unrelated to the language

Eric Schulte writes:

> 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?
Carsten Dominik 15 years ago
parent
commit
5e9fc20394
3 changed files with 33 additions and 2 deletions
  1. 6 0
      lisp/ChangeLog
  2. 9 1
      lisp/org-exp.el
  3. 18 1
      lisp/org-src.el

+ 6 - 0
lisp/ChangeLog

@@ -1,5 +1,11 @@
 2009-08-23  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-08-23  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org-exp.el (org-export-format-source-code-or-example): Translate
+	language.
+
+	* org-src.el (org-src-lang-modes): New variable
+	(org-edit-src-code): Translate language.
+
 	* org-exp.el (org-export-format-source-code-or-example): Deal wit
 	* org-exp.el (org-export-format-source-code-or-example): Deal wit
 	the new structure of the `org-export-latex-listings-langs'
 	the new structure of the `org-export-latex-listings-langs'
 	variable.
 	variable.

+ 9 - 1
lisp/org-exp.el

@@ -2278,7 +2278,15 @@ INDENT was the original indentation of the block."
 		   "htmlize.el 1.34 or later is needed for source code formatting")))
 		   "htmlize.el 1.34 or later is needed for source code formatting")))
 
 
 	      (if lang
 	      (if lang
-		  (let* ((mode (and lang (intern (concat lang "-mode"))))
+		  (let* ((lang-m (when lang
+                                   (or (cdr (assoc lang org-src-lang-modes))
+                                       lang)))
+                         (mode (and lang-m (intern
+					    (concat
+					     (if (symbolp lang-m)
+						 (symbol-name lang-m)
+					       lang-m)
+					     "-mode"))))
 			 (org-inhibit-startup t)
 			 (org-inhibit-startup t)
 			 (org-startup-folded nil))
 			 (org-startup-folded nil))
 		    (setq rtn
 		    (setq rtn

+ 18 - 1
lisp/org-src.el

@@ -109,6 +109,21 @@ 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,
 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.")
 but which mess up the display of a snippet in Org exported files.")
 
 
+(defcustom org-src-lang-modes
+  '("ocaml" . tuareg)
+  "Alist 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.  For many languages this is
+simple, but for language where this is not the case, this variable
+provides a way to simplify things on the user side.
+For example, there is no ocaml-mode in Emacs, but the mode to use is
+`tuareg-mode'."
+  :group 'org-edit-structure
+  :type '(repeat
+	  (cons
+	   (string "Language name")
+	   (symbol "Major mode"))))
+
 ;;; Editing source examples
 ;;; Editing source examples
 
 
 (defvar org-src-mode-map (make-sparse-keymap))
 (defvar org-src-mode-map (make-sparse-keymap))
@@ -151,7 +166,9 @@ the edited version."
       (setq beg (move-marker beg (nth 0 info))
       (setq beg (move-marker beg (nth 0 info))
 	    end (move-marker end (nth 1 info))
 	    end (move-marker end (nth 1 info))
 	    code (buffer-substring-no-properties beg end)
 	    code (buffer-substring-no-properties beg end)
-	    lang (nth 2 info)
+	    lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
+                     (nth 2 info))
+	    lang (if (symbolp lang) (symbol-name lang) lang)
 	    single (nth 3 info)
 	    single (nth 3 info)
 	    lfmt (nth 4 info)
 	    lfmt (nth 4 info)
 	    nindent (nth 5 info)
 	    nindent (nth 5 info)