litorgy-script.el 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;;; litorgy-script.el --- litorgy functions for script execution
  2. ;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
  3. ;; Author: Eric Schulte, Dan Davison, Austin F. Frank
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Litorgy support for evaluating shell, ruby, and python source code.
  24. ;;; Code:
  25. (require 'litorgy)
  26. (defun litorgy-script-add-interpreter (var cmds)
  27. (set-default var cmds)
  28. (mapc (lambda (cmd)
  29. (setq litorgy-interpreters (cons cmd litorgy-interpreters))
  30. (eval
  31. `(defun ,(intern (concat "litorgy-execute:" cmd)) (body params)
  32. (concat "Evaluate a block of " ,cmd " script with litorgy.
  33. This function is called by `litorgy-execute-src-block'.")
  34. (litorgy-script-execute ,cmd body params))))
  35. cmds))
  36. (defcustom litorgy-script-interpreters '("sh" "bash" "zsh" "ruby" "python")
  37. "List of interpreters of scripting languages which can be
  38. executed through litorgy."
  39. :group 'litorgy
  40. :set 'litorgy-script-add-interpreter)
  41. (defun litorgy-script-execute (cmd body params)
  42. "Run CMD on BODY obeying any options set with PARAMS.
  43. TODO: currently the params part is not implemented"
  44. (message (format "executing source block with %s..." cmd))
  45. (with-temp-buffer
  46. (insert body)
  47. (shell-command-on-region (point-min) (point-max) cmd nil 'replace)
  48. (message "finished executing source block")
  49. (buffer-string)))
  50. (provide 'litorgy-script)
  51. ;;; litorgy-script.el ends here