From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bjarte Johansen Subject: ob-sed Date: Wed, 27 May 2015 10:51:31 +0200 Message-ID: <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=_628563BC-4EDC-4C7C-A674-3E25F56FD486" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxX3n-0004Uz-Bt for emacs-orgmode@gnu.org; Wed, 27 May 2015 04:51:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxX3k-0000kK-6S for emacs-orgmode@gnu.org; Wed, 27 May 2015 04:51:35 -0400 Received: from alfons.uib.no ([2001:700:200:30::141]:58860) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxX3j-0000jw-P9 for emacs-orgmode@gnu.org; Wed, 27 May 2015 04:51:32 -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 1YxX3h-0001MX-RL; Wed, 27 May 2015 10:51:29 +0200 Received: from pc-115-18.eduroam.uib.no [129.177.115.18]:62182 by smtp.uib.no for emacs-orgmode@gnu.org with esmtpsa (Exim 4.84) id 1YxX3h-0008Tg-Fh; Wed, 27 May 2015 10:51:29 +0200 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=_628563BC-4EDC-4C7C-A674-3E25F56FD486 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, I originally wrote this for Eric Schulte=E2=80=99s 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 --Apple-Mail=_628563BC-4EDC-4C7C-A674-3E25F56FD486 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: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 --Apple-Mail=_628563BC-4EDC-4C7C-A674-3E25F56FD486--