ob-fomus.el 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; ob-fomus.el --- Org-babel functions for fomus evaluation
  2. ;; Copyright (C) 2011-2014 Torsten Anders
  3. ;; Author: Torsten Anders
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; This file is not part of GNU Emacs.
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 3, or (at your option)
  10. ;; any later version.
  11. ;;
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;;
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  19. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. ;; Boston, MA 02110-1301, USA.
  21. ;;; Commentary:
  22. ;; Org-Babel support for evaluating Fomus source code.
  23. ;; For information on Fomus see http://fomus.sourceforge.net/
  24. ;;
  25. ;; This differs from most standard languages in that
  26. ;;
  27. ;; 1) there is no such thing as a "session" in fomus
  28. ;;
  29. ;; 2) we are generally only going to return results of type "file"
  30. ;;
  31. ;; 3) we are adding the "file" and "cmdline" header arguments
  32. ;;
  33. ;; 4) there are no variables (at least for now)
  34. ;;; Code:
  35. (require 'ob)
  36. (require 'ob-eval)
  37. (defvar org-babel-default-header-args:fomus
  38. '((:results . "file") (:exports . "results"))
  39. "Default arguments to use when evaluating a fomus source block.")
  40. (defun org-babel-expand-body:fomus (body params)
  41. "Expand BODY according to PARAMS, return the expanded body."
  42. (let ((vars (org-babel--get-vars params)))
  43. (mapc
  44. (lambda (pair)
  45. (let ((name (symbol-name (car pair)))
  46. (value (cdr pair)))
  47. (setq body
  48. (replace-regexp-in-string
  49. (concat "\$" (regexp-quote name))
  50. (if (stringp value) value (format "%S" value))
  51. body))))
  52. vars)
  53. body))
  54. (defun org-babel-execute:fomus (body params)
  55. "Execute a block of Fomus code with org-babel.
  56. This function is called by `org-babel-execute-src-block'."
  57. (let* ((result-params (cdr (assq :result-params params)))
  58. (out-file (cdr (assq :file params)))
  59. (cmdline (cdr (assq :cmdline params)))
  60. (cmd (or (cdr (assq :cmd params)) "fomus"))
  61. (in-file (org-babel-temp-file "fomus-" ".fms")))
  62. (with-temp-file in-file
  63. (insert (org-babel-expand-body:fomus body params)))
  64. ;; TMP: testing
  65. ;; (message (concat cmd
  66. ;; " " (org-babel-process-file-name in-file)
  67. ;; " " cmdline
  68. ;; " -o " (org-babel-process-file-name out-file)))
  69. (org-babel-eval
  70. (concat cmd
  71. " " (org-babel-process-file-name in-file)
  72. " " cmdline
  73. " -o " (org-babel-process-file-name out-file)) "")
  74. nil)) ;; signal that output has already been written to file
  75. (defun org-babel-prep-session:fomus (session params)
  76. "Return an error because Fomus does not support sessions."
  77. (error "Fomus does not support sessions"))
  78. (provide 'ob-fomus)
  79. ;;; ob-fomus.el ends here