ob-fomus.el 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ;;; ob-fomus.el --- org-babel functions for fomus evaluation
  2. ;; Copyright (C) 2011-2012 Torsten Anders
  3. ;; Author: Torsten Anders
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version:
  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. ;; Org-Babel support for evaluating Fomus source code.
  24. ;; For information on Fomus see http://fomus.sourceforge.net/
  25. ;;
  26. ;; This differs from most standard languages in that
  27. ;;
  28. ;; 1) there is no such thing as a "session" in fomus
  29. ;;
  30. ;; 2) we are generally only going to return results of type "file"
  31. ;;
  32. ;; 3) we are adding the "file" and "cmdline" header arguments
  33. ;;
  34. ;; 4) there are no variables (at least for now)
  35. ;;; Code:
  36. (require 'ob)
  37. (require 'ob-eval)
  38. (defvar org-babel-default-header-args:fomus
  39. '((:results . "file") (:exports . "results"))
  40. "Default arguments to use when evaluating a fomus source block.")
  41. (defun org-babel-expand-body:fomus (body params)
  42. "Expand BODY according to PARAMS, return the expanded body."
  43. (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
  44. (mapc
  45. (lambda (pair)
  46. (let ((name (symbol-name (car pair)))
  47. (value (cdr pair)))
  48. (setq body
  49. (replace-regexp-in-string
  50. (concat "\$" (regexp-quote name))
  51. (if (stringp value) value (format "%S" value))
  52. body))))
  53. vars)
  54. body))
  55. (defun org-babel-execute:fomus (body params)
  56. "Execute a block of Fomus code with org-babel.
  57. This function is called by `org-babel-execute-src-block'."
  58. (let* ((result-params (cdr (assoc :result-params params)))
  59. (out-file (cdr (assoc :file params)))
  60. (cmdline (cdr (assoc :cmdline params)))
  61. (cmd (or (cdr (assoc :cmd params)) "fomus"))
  62. (in-file (org-babel-temp-file "fomus-" ".fms")))
  63. (with-temp-file in-file
  64. (insert (org-babel-expand-body:fomus body params)))
  65. ;; TMP: testing
  66. ;; (message (concat cmd
  67. ;; " " (org-babel-process-file-name in-file)
  68. ;; " " cmdline
  69. ;; " -o " (org-babel-process-file-name out-file)))
  70. (org-babel-eval
  71. (concat cmd
  72. " " (org-babel-process-file-name in-file)
  73. " " cmdline
  74. " -o " (org-babel-process-file-name out-file)) "")
  75. nil)) ;; signal that output has already been written to file
  76. (defun org-babel-prep-session:fomus (session params)
  77. "Return an error because Fomus does not support sessions."
  78. (error "Fomus does not support sessions"))
  79. (provide 'ob-fomus)
  80. ;;; ob-fomus.el ends here