From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bjarte Johansen Subject: Re: ob-sed Date: Wed, 27 May 2015 10:56:17 +0200 Message-ID: References: <3C35DA19-1BA3-4249-9128-99DDA0F4752D@infomedia.uib.no> Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_1F0B1C03-2003-4112-A036-D39D0FE8A266" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxX8O-0006b4-OA for emacs-orgmode@gnu.org; Wed, 27 May 2015 04:56:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxX8L-0003GT-Jx for emacs-orgmode@gnu.org; Wed, 27 May 2015 04:56:20 -0400 Received: from alfons.uib.no ([2001:700:200:30::141]:48942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxX8L-0003G9-C4 for emacs-orgmode@gnu.org; Wed, 27 May 2015 04:56:17 -0400 Received: from alfux.uib.no (smtp.uib.no) [2001:700:200:6::a:1f0c] by alfons.uib.no for emacs-orgmode@gnu.org with esmtp (Exim 4.84) id 1YxX8J-0001wX-CR; Wed, 27 May 2015 10:56:15 +0200 Received: from pc-115-18.eduroam.uib.no [129.177.115.18]:62348 by smtp.uib.no for emacs-orgmode@gnu.org with esmtpsa (Exim 4.84) id 1YxX8J-0000Aq-BG; Wed, 27 May 2015 10:56:15 +0200 In-Reply-To: <3C35DA19-1BA3-4249-9128-99DDA0F4752D@infomedia.uib.no> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode --Apple-Mail=_1F0B1C03-2003-4112-A036-D39D0FE8A266 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii I had loosely based it on my own ob-sparql and ob-awk, I saw that there = was a remnant of ob-sparql left in there. Here is an updated version. --Apple-Mail=_1F0B1C03-2003-4112-A036-D39D0FE8A266 Content-Disposition: attachment; filename=ob-sed.el Content-Type: application/octet-stream; name="ob-sed.el" Content-Transfer-Encoding: 7bit ;;; 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 . ;;; 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:sed '() "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 --Apple-Mail=_1F0B1C03-2003-4112-A036-D39D0FE8A266--