diff options
Diffstat (limited to 'lisp/org/ob-picolisp.el')
-rw-r--r-- | lisp/org/ob-picolisp.el | 105 |
1 files changed, 53 insertions, 52 deletions
diff --git a/lisp/org/ob-picolisp.el b/lisp/org/ob-picolisp.el index 1d1791926c5..279cd7b3f45 100644 --- a/lisp/org/ob-picolisp.el +++ b/lisp/org/ob-picolisp.el @@ -99,16 +99,16 @@ 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) @@ -118,53 +118,54 @@ (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 |