Function: org-babel-execute:sed

org-babel-execute:sed is a byte-compiled function defined in ob-sed.el.gz.

Signature

(org-babel-execute:sed BODY PARAMS)

Documentation

Execute a block of sed code with Org Babel.

BODY is the source inside a sed source block and PARAMS is an association list over the source block configurations. This function is called by org-babel-execute-src-block.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-sed.el.gz
(defun org-babel-execute:sed (body params)
  "Execute a block of sed code with Org Babel.
BODY is the source inside a sed source block and PARAMS is an
association list over the source block configurations.  This
function is called by `org-babel-execute-src-block'."
  (let* ((result-params (cdr (assq :result-params params)))
         (cmd-line (cdr (assq :cmd-line params)))
         (in-file (cdr (assq :in-file params)))
	 (code-file (let ((file (org-babel-temp-file "sed-")))
                      (with-temp-file file
			(insert body))
		      file))
	 (stdin (let ((stdin (cdr (assq :stdin params))))
		  (when stdin
		    (let ((tmp (org-babel-temp-file "sed-stdin-"))
			  (res (org-babel-ref-resolve stdin)))
		      (with-temp-file tmp
			(insert res))
		      tmp))))
         (cmd (mapconcat #'identity
			 (remq nil
			       (list org-babel-sed-command
				     (format "-f \"%s\"" code-file)
				     cmd-line
				     in-file))
			 " ")))
    (org-babel-reassemble-table
     (let ((results
            (cond
             (stdin (with-temp-buffer
                      (call-process-shell-command cmd stdin (current-buffer))
                      (buffer-string)))
             (t (org-babel-eval cmd "")))))
       (when results
         (org-babel-result-cond result-params
	   results
	   (let ((tmp (org-babel-temp-file "sed-results-")))
	     (with-temp-file tmp (insert results))
	     (org-babel-import-elisp-from-file tmp)))))
     (org-babel-pick-name
      (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
     (org-babel-pick-name
      (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))