Browse Source

Merge branch 'master' of orgmode.org:org-mode

Bastien Guerry 14 years ago
parent
commit
0dc16a0fe9
5 changed files with 117 additions and 23 deletions
  1. 19 2
      doc/org.texi
  2. 80 0
      lisp/ob-maxima.el
  3. 3 7
      lisp/ob-tangle.el
  4. 14 14
      lisp/ob.el
  5. 1 0
      lisp/org.el

+ 19 - 2
doc/org.texi

@@ -675,6 +675,8 @@ Specific header arguments
                                 files during tangling
 * comments::                    Toggle insertion of comments in tangled
                                 code files
+* padline::                     Control insertion of padding lines in tangled
+                                code files
 * no-expand::                   Turn off variable assignment and noweb
                                 expansion during tangling
 * session::                     Preserve the state of code evaluation
@@ -11817,6 +11819,8 @@ The following header arguments are defined:
                                 files during tangling
 * comments::                    Toggle insertion of comments in tangled
                                 code files
+* padline::                     Control insertion of padding lines in tangled
+                                code files
 * no-expand::                   Turn off variable assignment and noweb
                                 expansion during tangling
 * session::                     Preserve the state of code evaluation
@@ -12276,7 +12280,7 @@ The @code{:mkdirp} header argument can be used to create parent directories
 of tangled files when missing.  This can be set to @code{yes} to enable
 directory creation or to @code{no} to inhibit directory creation.
 
-@node comments, no-expand, mkdirp, Specific header arguments
+@node comments, padline, mkdirp, Specific header arguments
 @subsubsection @code{:comments}
 By default code blocks are tangled to source-code files without any insertion
 of comments beyond those which may already exist in the body of the code
@@ -12303,7 +12307,20 @@ Turns on the ``link'' comment option, and additionally wraps expanded noweb
 references in the code block body in link comments.
 @end itemize
 
-@node no-expand, session, comments, Specific header arguments
+@node padline, no-expand, comments, Specific header arguments
+Control in insertion of padding lines around code block bodies in tangled
+code files.  The default value is @code{yes} which results in insertion of
+newlines before and after each tangled code block.  The following arguments
+are accepted.
+
+@itemize @bullet
+@item @code{yes}
+Insert newlines before and after each code block body in tangled code files.
+@item @code{no}
+Do not insert any newline padding in tangled output.
+@end itemize
+
+@node no-expand, session, padline, Specific header arguments
 @subsubsection @code{:no-expand}
 
 By default, code blocks are expanded with @code{org-babel-expand-src-block}

+ 80 - 0
lisp/ob-maxima.el

@@ -0,0 +1,80 @@
+;;; org-babel-maxima.el --- org-babel functions for maxima evaluation
+
+;; Copyright (c) 2009, 2010, 2011 Eric S Fraga, Eric Schulte
+
+;; Author: Eric S Fraga, Eric Schulte
+;; Keywords: literate programming, reproducible research, maxima
+;; Homepage: http://orgmode.org
+;; Version: 0.01
+
+;;; License:
+
+;; This program 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, or (at your option)
+;; any later version.
+;;
+;; This program 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; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; Org-Babel support for evaluating maxima entries.
+;;
+;; This differs from most standard languages in that
+;;
+;; 1) there is no such thing as a "session" in maxima
+;;
+;; 2) we are generally only going to return output from maxima
+;;
+;; 3) we are adding the "cmdline" header argument
+;;
+;; 4) there are no variables
+
+;;; Code:
+(require 'ob)
+
+(defvar org-babel-default-header-args:maxima '())
+
+(defun org-babel-maxima-expand (body params)
+  "Expand a block of Maxima code according to its header arguments."
+  body)
+
+(defun org-babel-execute:maxima (body params)
+  "Execute a block of Maxima entries with org-babel.  This function is
+called by `org-babel-execute-src-block'."
+  (message "executing Maxima source code block")
+  (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
+	 (cmdline (cdr (assoc :cmdline params)))
+	 (in-file (org-babel-temp-file "maxima-"))
+	 (cmd (format "maxima --very-quiet -r 'batchload(%S)$' %s"
+		      in-file cmdline)))
+    (with-temp-file in-file (insert body))
+    (message cmd)
+    ((lambda (raw) ;; " | grep -v batch | grep -v 'replaced' | sed '/^$/d' "
+       (mapconcat
+	#'identity
+	(delq nil
+	      (mapcar (lambda (line)
+			(unless (or (string-match "batch" line)
+				    (string-match "^rat: replaced .*$" line)
+				    (= 0 (length line)))
+			  line))
+		      (split-string raw "[\r\n]"))) "\n"))
+     (org-babel-eval cmd ""))))
+
+(defun org-babel-prep-session:maxima (session params)
+  (error "Maxima does not support sessions"))
+
+(provide 'ob-maxima)
+
+;; arch-tag: d86c97ac-7eab-4349-8d8b-302dd09779a8
+
+;;; org-babel-maxima.el ends here

+ 3 - 7
lisp/ob-tangle.el

@@ -68,11 +68,6 @@ then the name of the language is used."
   :group 'org-babel
   :type 'hook)
 
-(defcustom org-babel-tangle-pad-newline t
-  "Switch indicating whether to pad tangled code with newlines."
-  :group 'org-babel
-  :type 'boolean)
-
 (defcustom org-babel-tangle-comment-format-beg "[[%link][%source-name]]"
   "Format of inserted comments in tangled code files.
 The following format strings can be used to insert special
@@ -378,6 +373,7 @@ form
 	 (body (nth 5 spec))
 	 (comment (nth 6 spec))
 	 (comments (cdr (assoc :comments (nth 4 spec))))
+	 (padline (not (string= "no" (cdr (assoc :padline (nth 4 spec))))))
 	 (link-p (or (string= comments "both") (string= comments "link")
 		     (string= comments "yes") (string= comments "noweb")))
 	 (link-data (mapcar (lambda (el)
@@ -390,14 +386,14 @@ form
             (let ((text (org-babel-trim text)))
 	      (when (and comments (not (string= comments "no"))
 			 (> (length text) 0))
-		(when org-babel-tangle-pad-newline (insert "\n"))
+		(when padline (insert "\n"))
 		(comment-region (point) (progn (insert text) (point)))
 		(end-of-line nil) (insert "\n")))))
       (when comment (insert-comment comment))
       (when link-p
 	(insert-comment
 	 (org-fill-template org-babel-tangle-comment-format-beg link-data)))
-      (when org-babel-tangle-pad-newline (insert "\n"))
+      (when padline (insert "\n"))
       (insert
        (format
 	"%s\n"

+ 14 - 14
lisp/ob.el

@@ -291,14 +291,15 @@ then run `org-babel-pop-to-session'."
 
 (defconst org-babel-header-arg-names
   '(cache cmdline colnames dir exports file noweb results
-    session tangle var eval noeval comments no-expand)
+    session tangle var eval noeval comments no-expand shebang padline)
   "Common header arguments used by org-babel.
 Note that individual languages may define their own language
 specific header arguments as well.")
 
 (defvar org-babel-default-header-args
   '((:session . "none") (:results . "replace") (:exports . "code")
-    (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
+    (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no")
+    (:padnewline . "yes"))
   "Default arguments to use when evaluating a source block.")
 
 (defvar org-babel-default-inline-header-args
@@ -1679,7 +1680,7 @@ parameters when merging lists."
 	   ("output" "value")))
 	(exports-exclusive-groups
 	 '(("code" "results" "both" "none")))
-	params results exports tangle noweb cache vars shebang comments)
+	params results exports tangle noweb cache vars shebang comments padline)
     (flet ((e-merge (exclusive-groups &rest result-params)
              ;; maintain exclusivity of mutually exclusive parameters
              (let (output)
@@ -1746,6 +1747,9 @@ parameters when merging lists."
 	      (:cache
 	       (setq cache (e-merge '(("yes" "no")) cache
 				    (split-string (or (cdr pair) "")))))
+	      (:padline
+	       (setq padline (e-merge '(("yes" "no")) padline
+				      (split-string (or (cdr pair) "")))))
 	      (:shebang ;; take the latest -- always overwrite
 	       (setq shebang (or (list (cdr pair)) shebang)))
 	      (:comments
@@ -1756,17 +1760,13 @@ parameters when merging lists."
 	  plist))
        plists))
     (while vars (setq params (cons (cons :var (cddr (pop vars))) params)))
-    (cons (cons :comments (mapconcat 'identity comments " "))
-          (cons (cons :shebang (mapconcat 'identity shebang " "))
-                (cons (cons :cache (mapconcat 'identity cache " "))
-                      (cons (cons :noweb (mapconcat 'identity noweb " "))
-                            (cons (cons :tangle (mapconcat 'identity tangle " "))
-                                  (cons (cons :exports
-                                              (mapconcat 'identity exports " "))
-                                        (cons
-                                         (cons :results
-                                               (mapconcat 'identity results " "))
-                                         params)))))))))
+    (mapc
+     (lambda (hd)
+       (let ((key (intern (concat ":" (symbol-name hd))))
+	     (val (eval hd)))
+	 (setf params (cons (cons key (mapconcat 'identity val " ")) params))))
+     '(results exports tangle noweb padline cache shebang comments))
+    params))
 
 (defun org-babel-expand-noweb-references (&optional info parent-buffer)
   "Expand Noweb references in the body of the current source code block.

+ 1 - 0
lisp/org.el

@@ -164,6 +164,7 @@ requirements) is loaded."
 		 (const :tag "Javascript" js)
 		 (const :tag "Latex" latex)
 		 (const :tag "Ledger" ledger)
+		 (const :tag "Maxima" maxima)
 		 (const :tag "Matlab" matlab)
 		 (const :tag "Mscgen" mscgen)
 		 (const :tag "Ocaml" ocaml)