66 lines
2.3 KiB
EmacsLisp
66 lines
2.3 KiB
EmacsLisp
|
;;; litorgy-shell.el --- litorgy functions for shell execution
|
||
|
|
||
|
;; Copyright (C) 2009 Eric Schulte
|
||
|
|
||
|
;; Author: Eric Schulte
|
||
|
;; Keywords: literate programming, reproducible research
|
||
|
;; Homepage: http://orgmode.org
|
||
|
;; Version: 0.01
|
||
|
|
||
|
;;; 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; see the file COPYING. If not, write to the
|
||
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
;; Boston, MA 02110-1301, USA.
|
||
|
|
||
|
;;; Commentary:
|
||
|
|
||
|
;; Litorgy support for evaluating sh, bash, and zsh shells
|
||
|
|
||
|
;;; Code:
|
||
|
(require 'litorgy)
|
||
|
|
||
|
(defun litorgy-shell-add-interpreter (var cmds)
|
||
|
(set-default var cmds)
|
||
|
(mapc (lambda (cmd)
|
||
|
(setq litorgy-interpreters (cons cmd litorgy-interpreters))
|
||
|
(eval
|
||
|
`(defun ,(intern (concat "litorgy-execute:" cmd)) (body params)
|
||
|
,(concat "Evaluate a block of " cmd " shell with litorgy. This function is
|
||
|
called by `litorgy-execute-src-block'. This function is an
|
||
|
automatically generated wrapper for `litorgy-shell-execute'.")
|
||
|
(litorgy-shell-execute ,cmd body params))))
|
||
|
cmds))
|
||
|
|
||
|
(defcustom litorgy-shell-interpreters '("sh" "bash" "zsh")
|
||
|
"List of interpreters of shelling languages which can be
|
||
|
executed through litorgy."
|
||
|
:group 'litorgy
|
||
|
:set 'litorgy-shell-add-interpreter)
|
||
|
|
||
|
(defun litorgy-shell-execute (cmd body params)
|
||
|
"Run CMD on BODY obeying any options set with PARAMS."
|
||
|
(message (format "executing %s code block..." cmd))
|
||
|
(let ((vars (litorgy-reference-variables params)))
|
||
|
(save-window-excursion
|
||
|
(with-temp-buffer
|
||
|
(if (> (length vars) 0)
|
||
|
(error "currently no support for passing variables to shells"))
|
||
|
(insert body)
|
||
|
(shell-command-on-region (point-min) (point-max) cmd nil 'replace)
|
||
|
(buffer-string)))))
|
||
|
|
||
|
(provide 'litorgy-shell)
|
||
|
;;; litorgy-shell.el ends here
|