]> code.delx.au - gnu-emacs/blobdiff - lisp/org/ob-picolisp.el
Merge from origin/emacs-24
[gnu-emacs] / lisp / org / ob-picolisp.el
index 1d1791926c5683b994e5698b84706e72426b9cf7..5b696f1b1fc6588f7203dce661223edf8d5279ba 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ob-picolisp.el --- org-babel functions for picolisp evaluation
 
-;; Copyright (C) 2010-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2015 Free Software Foundation, Inc.
 
 ;; Authors: Thorsten Jolitz
 ;;      Eric Schulte
  called by `org-babel-execute-src-block'"
   (message "executing Picolisp source code block")
   (let* (
-        ;; name of the session or "none"
+        ;; Name of the session or "none".
         (session-name (cdr (assoc :session params)))
-        ;; set the session if the session variable is non-nil
+        ;; Set the session if the session variable is non-nil.
         (session (org-babel-picolisp-initiate-session session-name))
-        ;; either OUTPUT or VALUE which should behave as described above
+        ;; Either OUTPUT or VALUE which should behave as described above.
         (result-type (cdr (assoc :result-type params)))
         (result-params (cdr (assoc :result-params params)))
-        ;; expand the body with `org-babel-expand-body:picolisp'
+        ;; Expand the body with `org-babel-expand-body:picolisp'.
         (full-body (org-babel-expand-body:picolisp body params))
-         ;; wrap body appropriately for the type of evaluation and results
+         ;; Wrap body appropriately for the type of evaluation and results.
          (wrapped-body
           (cond
            ((or (member "code" result-params)
             (format "(print (out \"/dev/null\" %s))" full-body))
            ((member "value" result-params)
             (format "(out \"/dev/null\" %s)" full-body))
-           (t full-body))))
-
-    ((lambda (result)
-       (org-babel-result-cond result-params
-        result
-         (read result)))
-     (if (not (string= session-name "none"))
-         ;; session based evaluation
-        (mapconcat ;; <- joins the list back together into a single string
-          #'identity
-          (butlast ;; <- remove the org-babel-picolisp-eoe line
-           (delq nil
-                 (mapcar
-                  (lambda (line)
-                    (org-babel-chomp ;; remove trailing newlines
-                     (when (> (length line) 0) ;; remove empty lines
-                      (cond
-                       ;; remove leading "-> " from return values
-                       ((and (>= (length line) 3)
-                             (string= "-> " (substring line 0 3)))
-                        (substring line 3))
-                       ;; remove trailing "-> <<return-value>>" on the
-                       ;; last line of output
-                       ((and (member "output" result-params)
-                             (string-match-p "->" line))
-                        (substring line 0 (string-match "->" line)))
-                       (t line)
-                       )
-                       ;; (if (and (>= (length line) 3) ;; remove leading "<- "
-                       ;;          (string= "-> " (substring line 0 3)))
-                       ;;     (substring line 3)
-                       ;;   line)
-                      )))
-                  ;; returns a list of the output of each evaluated expression
-                  (org-babel-comint-with-output (session org-babel-picolisp-eoe)
-                    (insert wrapped-body) (comint-send-input)
-                    (insert "'" org-babel-picolisp-eoe) (comint-send-input)))))
-          "\n")
-       ;; external evaluation
-       (let ((script-file (org-babel-temp-file "picolisp-script-")))
-        (with-temp-file script-file
-          (insert (concat wrapped-body "(bye)")))
-         (org-babel-eval
-          (format "%s %s"
-                  org-babel-picolisp-cmd
-                  (org-babel-process-file-name script-file))
-          ""))))))
+           (t full-body)))
+         (result
+          (if (not (string= session-name "none"))
+              ;; Session based evaluation.
+              (mapconcat ;; <- joins the list back into a single string
+               #'identity
+               (butlast ;; <- remove the org-babel-picolisp-eoe line
+                (delq nil
+                      (mapcar
+                       (lambda (line)
+                         (org-babel-chomp      ;; Remove trailing newlines.
+                          (when (> (length line) 0) ;; Remove empty lines.
+                            (cond
+                             ;; Remove leading "-> " from return values.
+                             ((and (>= (length line) 3)
+                                   (string= "-> " (substring line 0 3)))
+                              (substring line 3))
+                             ;; Remove trailing "-> <<return-value>>" on the
+                             ;; last line of output.
+                             ((and (member "output" result-params)
+                                   (string-match-p "->" line))
+                              (substring line 0 (string-match "->" line)))
+                             (t line)
+                             )
+                            ;;(if (and (>= (length line) 3);Remove leading "<-"
+                            ;;         (string= "-> " (substring line 0 3)))
+                            ;;    (substring line 3)
+                            ;;  line)
+                            )))
+                       ;; Returns a list of the output of each evaluated exp.
+                       (org-babel-comint-with-output
+                           (session org-babel-picolisp-eoe)
+                         (insert wrapped-body) (comint-send-input)
+                         (insert "'" org-babel-picolisp-eoe)
+                         (comint-send-input)))))
+               "\n")
+            ;; external evaluation
+            (let ((script-file (org-babel-temp-file "picolisp-script-")))
+              (with-temp-file script-file
+                (insert (concat wrapped-body "(bye)")))
+              (org-babel-eval
+               (format "%s %s"
+                       org-babel-picolisp-cmd
+                       (org-babel-process-file-name script-file))
+               "")))))
+    (org-babel-result-cond result-params
+      result
+      (read result))))
 
 (defun org-babel-picolisp-initiate-session (&optional session-name)
   "If there is not a current inferior-process-buffer in SESSION