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