org-babel: more robust version of :results value for python and perl.

In ':results value' ('functional') mode, a return statement is now
required in python and perl code.
This commit is contained in:
Dan Davison 2009-11-11 16:09:05 -05:00
parent 838363f047
commit a9069d8dfd
2 changed files with 8 additions and 12 deletions

View File

@ -108,11 +108,10 @@ last statement in BODY, as elisp."
(if (member "pp" result-params)
(error "Pretty-printing not implemented for perl")
org-babel-perl-wrapper-method)
(let ((lines (split-string
(org-remove-indentation (org-babel-trim body)) "[\r\n]")))
(concat
(mapconcat #'identity (butlast lines) "\n")
(format "\nreturn %s" (car (last lines)))))
(mapconcat
(lambda (line) (format "\t%s" line))
(split-string
(org-remove-indentation (org-babel-trim body)) "[\r\n]") "\n")
tmp-file))
;; (message "buffer=%s" (buffer-string)) ;; debugging
(shell-command-on-region (point-min) (point-max) "perl"))

View File

@ -160,13 +160,10 @@ last statement in BODY, as elisp."
(if (member "pp" result-params)
org-babel-python-pp-wrapper-method
org-babel-python-wrapper-method)
(let ((lines (split-string
(org-remove-indentation (org-babel-trim body)) "[\r\n]")))
(concat
(mapconcat
(lambda (line) (format "\t%s" line))
(butlast lines) "\n")
(format "\n\treturn %s" (car (last lines)))))
(mapconcat
(lambda (line) (format "\t%s" line))
(split-string
(org-remove-indentation (org-babel-trim body)) "[\r\n]") "\n")
tmp-file))
;; (message "buffer=%s" (buffer-string)) ;; debugging
(shell-command-on-region (point-min) (point-max) "python"))