lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / lisp / ob-dot.el
blob73a16738a0b17e338e384fe5a3ecf105f07b21cf
1 ;;; ob-dot.el --- Babel Functions for dot -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2009-2019 Free Software Foundation, Inc.
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: https://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Org-Babel support for evaluating dot source code.
28 ;; For information on dot see http://www.graphviz.org/
30 ;; This differs from most standard languages in that
32 ;; 1) there is no such thing as a "session" in dot
34 ;; 2) we are generally only going to return results of type "file"
36 ;; 3) we are adding the "file" and "cmdline" header arguments
38 ;; 4) there are no variables (at least for now)
40 ;;; Code:
41 (require 'ob)
43 (defvar org-babel-default-header-args:dot
44 '((:results . "file") (:exports . "results"))
45 "Default arguments to use when evaluating a dot source block.")
47 (defun org-babel-expand-body:dot (body params)
48 "Expand BODY according to PARAMS, return the expanded body."
49 (let ((vars (org-babel--get-vars params)))
50 (mapc
51 (lambda (pair)
52 (let ((name (symbol-name (car pair)))
53 (value (cdr pair)))
54 (setq body
55 (replace-regexp-in-string
56 (concat "$" (regexp-quote name))
57 (if (stringp value) value (format "%S" value))
58 body
60 t))))
61 vars)
62 body))
64 (defun org-babel-execute:dot (body params)
65 "Execute a block of Dot code with org-babel.
66 This function is called by `org-babel-execute-src-block'."
67 (let* ((out-file (cdr (or (assq :file params)
68 (error "You need to specify a :file parameter"))))
69 (cmdline (or (cdr (assq :cmdline params))
70 (format "-T%s" (file-name-extension out-file))))
71 (cmd (or (cdr (assq :cmd params)) "dot"))
72 (coding-system-for-read 'utf-8) ;use utf-8 with sub-processes
73 (coding-system-for-write 'utf-8)
74 (in-file (org-babel-temp-file "dot-")))
75 (with-temp-file in-file
76 (insert (org-babel-expand-body:dot body params)))
77 (org-babel-eval
78 (concat cmd
79 " " (org-babel-process-file-name in-file)
80 " " cmdline
81 " -o " (org-babel-process-file-name out-file)) "")
82 nil)) ;; signal that output has already been written to file
84 (defun org-babel-prep-session:dot (_session _params)
85 "Return an error because Dot does not support sessions."
86 (error "Dot does not support sessions"))
88 (provide 'ob-dot)
92 ;;; ob-dot.el ends here