Fix Org ChangeLog entries and remove arch-tag.
[bpt/emacs.git] / lisp / org / ob-dot.el
CommitLineData
86fbb8ca
CD
1;;; ob-dot.el --- org-babel functions for dot evaluation
2
3ab2c837 3;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
86fbb8ca
CD
4
5;; Author: Eric Schulte
6;; Keywords: literate programming, reproducible research
7;; Homepage: http://orgmode.org
3ab2c837 8;; Version: 7.7
86fbb8ca
CD
9
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs 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 of the License, or
15;; (at your option) any later version.
16
17;; GNU Emacs 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.
21
22;; You should have received a copy of the GNU General Public License
23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25;;; Commentary:
26
27;; Org-Babel support for evaluating dot source code.
28;;
29;; For information on dot see http://www.graphviz.org/
30;;
31;; This differs from most standard languages in that
32;;
33;; 1) there is no such thing as a "session" in dot
34;;
35;; 2) we are generally only going to return results of type "file"
36;;
37;; 3) we are adding the "file" and "cmdline" header arguments
38;;
39;; 4) there are no variables (at least for now)
40
41;;; Code:
42(require 'ob)
43(require 'ob-eval)
44
45(defvar org-babel-default-header-args:dot
46 '((:results . "file") (:exports . "results"))
47 "Default arguments to use when evaluating a dot source block.")
48
afe98dfa 49(defun org-babel-expand-body:dot (body params)
86fbb8ca 50 "Expand BODY according to PARAMS, return the expanded body."
afe98dfa 51 (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
86fbb8ca
CD
52 (mapc
53 (lambda (pair)
54 (let ((name (symbol-name (car pair)))
55 (value (cdr pair)))
56 (setq body
57 (replace-regexp-in-string
58 (concat "\$" (regexp-quote name))
59 (if (stringp value) value (format "%S" value))
60 body))))
61 vars)
62 body))
63
64(defun org-babel-execute:dot (body params)
65 "Execute a block of Dot code with org-babel.
66This function is called by `org-babel-execute-src-block'."
afe98dfa
CD
67 (let* ((result-params (cdr (assoc :result-params params)))
68 (out-file (cdr (assoc :file params)))
69 (cmdline (or (cdr (assoc :cmdline params))
70 (format "-T%s" (file-name-extension out-file))))
71 (cmd (or (cdr (assoc :cmd params)) "dot"))
72 (in-file (org-babel-temp-file "dot-")))
86fbb8ca 73 (with-temp-file in-file
afe98dfa
CD
74 (insert (org-babel-expand-body:dot body params)))
75 (org-babel-eval
76 (concat cmd
77 " " (org-babel-process-file-name in-file)
78 " " cmdline
79 " -o " (org-babel-process-file-name out-file)) "")
3ab2c837 80 nil)) ;; signal that output has already been written to file
86fbb8ca
CD
81
82(defun org-babel-prep-session:dot (session params)
83 "Return an error because Dot does not support sessions."
84 (error "Dot does not support sessions"))
85
86(provide 'ob-dot)
87
5b409b39 88
86fbb8ca
CD
89
90;;; ob-dot.el ends here