From: Bjarte Johansen <bjarte.johansen@infomedia.uib.no>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: ob-sed
Date: Wed, 27 May 2015 10:51:31 +0200 [thread overview]
Message-ID: <3C35DA19-1BA3-4249-9128-99DDA0F4752D@infomedia.uib.no> (raw)
[-- 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
next reply other threads:[~2015-05-27 8:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-27 8:51 Bjarte Johansen [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3C35DA19-1BA3-4249-9128-99DDA0F4752D@infomedia.uib.no \
--to=bjarte.johansen@infomedia.uib.no \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).