Bladeren bron

Introducing ob-org and now wrapping ":results org" in org code block

  ob-org has two non-standard header arguments in that it exports it's
  results by default and the result type defaults to raw, this ensures
  that the body of a begin_src org block exports transparently.

  This is a breaking change in that if you are currently using org
  code blocks to export org-fontified code you will have to set the
  ":exports" header argument for org-mode blocks to "code" on a block,
  file, language or system-wide basis.

* Makefile (LISPF): adding ob-org.el to the makefile

* lisp/ob-org.el: defines handling of org code blocks

* lisp/ob.el (org-babel-insert-result): now when "org" is a result
  type the results are wrapped in an org code block
Eric Schulte 14 jaren geleden
bovenliggende
commit
2c33b2eb66
4 gewijzigde bestanden met toevoegingen van 65 en 3 verwijderingen
  1. 2 1
      Makefile
  2. 53 0
      lisp/ob-org.el
  3. 9 2
      lisp/ob.el
  4. 1 0
      lisp/org.el

+ 2 - 1
Makefile

@@ -148,7 +148,8 @@ LISPF      = 	org.el			\
 		ob-gnuplot.el		\
 		ob-octave.el		\
 		ob-screen.el		\
-		ob-plantuml.el
+		ob-plantuml.el		\
+		ob-org.el
 
 LISPFILES0  = $(LISPF:%=lisp/%)
 LISPFILES   = $(LISPFILES0) lisp/org-install.el

+ 53 - 0
lisp/ob-org.el

@@ -0,0 +1,53 @@
+;;; ob-org.el --- org-babel functions for org code block evaluation
+
+;; Copyright (C) 2010  Free Software Foundation, Inc.
+
+;; Author: Eric Schulte
+;; Keywords: literate programming, reproducible research
+;; Homepage: http://orgmode.org
+;; Version: 7.01trans
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This is the simplest of code blocks, where upon evaluation the
+;; contents of the code block are returned in a raw result.
+
+;;; Code:
+(require 'ob)
+
+(defvar org-babel-default-header-args:org
+  '((:results . "raw") (:exports . "results"))
+  "Default arguments for evaluating a org source block.")
+
+(defun org-babel-expand-body:org (body params &optional processed-params)
+  "Expand BODY according to PARAMS, return the expanded body." body)
+
+(defun org-babel-execute:org (body params)
+  "Execute a block of Org code with.
+This function is called by `org-babel-execute-src-block'."
+  body)
+
+(defun org-babel-prep-session:org (session params)
+  "Return an error because org does not support sessions."
+  (error "Org does not support sessions"))
+
+(provide 'ob-org)
+
+;; arch-tag: 130af5fe-cc56-46bd-9508-fa0ebd94cb1f
+
+;;; ob-org.el ends here

+ 9 - 2
lisp/ob.el

@@ -1202,7 +1202,12 @@ raw ----- results are added directly to the org-mode file.  This
           is a good option if you code block will output org-mode
           formatted text.
 
-org ----- this is the same as the 'raw' option
+org ----- similar in effect to raw, only the results are wrapped
+          in an org code block.  Similar to the raw option, on
+          export the results will be interpreted as org-formatted
+          text, however by wrapping the results in an org code
+          block they can be replaced upon re-execution of the
+          code block.
 
 html ---- results are added inside of a #+BEGIN_HTML block.  This
           is a good option if you code block will output html
@@ -1279,7 +1284,9 @@ code ---- the results are extracted in the syntax of the source
 	   ((member "code" result-params)
 	    (insert (format "#+BEGIN_SRC %s%s\n%s#+END_SRC\n"
                             (or lang "none") results-switches result)))
-	   ((or (member "raw" result-params) (member "org" result-params))
+	   ((member "org" result-params)
+	    (insert (format "#+BEGIN_SRC org\n%s#+END_SRC\n" result)))
+	   ((member "raw" result-params)
 	    (save-excursion (insert result)) (if (org-at-table-p) (org-cycle)))
 	   (t
 	    (org-babel-examplize-region

+ 1 - 0
lisp/org.el

@@ -160,6 +160,7 @@ requirements) is loaded."
 		 (const :tag "Mscgen" mscgen)
 		 (const :tag "Ocaml" ocaml)
 		 (const :tag "Octave" octave)
+		 (const :tag "Org" org)
 		 (const :tag "Perl" perl)
 		 (const :tag "PlantUML" plantuml)
 		 (const :tag "Python" python)