emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* ob-sed
@ 2015-05-27  8:51 Bjarte Johansen
  2015-05-27  8:56 ` ob-sed Bjarte Johansen
  0 siblings, 1 reply; 11+ messages in thread
From: Bjarte Johansen @ 2015-05-27  8:51 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

Hi,

I originally wrote this for Eric Schulte’s sed-mode, but he thought I should post it here instead. I have been using it for little over a week and it has been working perfectly for me. If there is anything that you think should be added or removed before it is accepted into org-mode please tell me.

I have already signed the CA for projects in relation to GNU Emacs.

Regards,
Bjarte


[-- Attachment #2: ob-sed.el --]
[-- Type: application/octet-stream, Size: 2926 bytes --]

;;; ob-sed.el --- org-babel functions for sed scripts

;; Copyright (C) 2015 Bjarte Johansen

;; Author: Bjarte Johansen
;; Keywords: literate programming, reproducible research
;; Version: 0.1.0

;;; 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. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Provides a way to evaluate sed scripts in org-mode.

;;; Usage:

;; Add to your Emacs config:

;; (org-babel-do-load-languages
;;  'org-babel-load-languages
;;  '((sed . t)))

(require 'ob)
(require 'sed-mode)

(defvar org-babel-sed-command "sed")

(defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("sed" . "sed"))

(defvar org-babel-default-header-args:sparql '()
  "Default arguments for evaluating a sed source code block.")

(defun org-babel-execute:sed (body params)
  "Execute a block of sed code with org-babel.  This function is
called by `org-babel-execute-src-block'"
  (message "executing sed source code block")
  (let* ((result-params (cdr (assoc :result-params params)))
         (cmd-line (cdr (assoc :cmd-line params)))
         (in-file (cdr (assoc :in-file params)))
	 (code-file (let ((file (org-babel-temp-file "sed-")))
                      (with-temp-file file
			(insert body)) file))
	 (stdin (let ((stdin (cdr (assoc :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 (remove nil (list org-babel-sed-command
						      "-f" 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 (assoc :colname-names params)) (cdr (assoc :colnames params)))
     (org-babel-pick-name
      (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params))))))

(provide 'ob-sed)
;;; ob-sed.el ends here

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-05-31  2:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-27  8:51 ob-sed Bjarte Johansen
2015-05-27  8:56 ` ob-sed Bjarte Johansen
2015-05-27 21:31   ` ob-sed Nicolas Goaziou
2015-05-28 11:47     ` ob-sed Bjarte Johansen
2015-05-29  9:00       ` ob-sed Nicolas Goaziou
2015-05-29 13:32         ` ob-sed Bjarte Johansen
2015-05-29 17:08           ` ob-sed Suvayu Ali
2015-05-30 12:32           ` ob-sed Nicolas Goaziou
2015-05-30 12:36             ` ob-sed Bjarte Johansen
2015-05-30 13:01               ` ob-sed Nicolas Goaziou
2015-05-31  2:08               ` ob-sed Nick Dokos

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).