org.el (org-read-date-minibuffer-local-map): Check if we are at the beginning of...
[org-mode.git] / contrib / lisp / ob-eukleides.el
blobe25ed1c7e463ca364c22afbbb4fae5f50f599fdf
1 ;;; ob-eukleides.el --- Org-babel functions for eukleides evaluation
3 ;; Copyright (C) 2010-2013 Free Software Foundation, Inc.
5 ;; Author: Luis Anaya
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://orgmode.org
9 ;; This file is not part of GNU Emacs.
11 ;; This program 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 ;; This program 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 <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Org-Babel support for evaluating eukleides script.
28 ;; Inspired by Ian Yang's org-export-blocks-format-eukleides
29 ;; http://www.emacswiki.org/emacs/org-export-blocks-format-eukleides.el
31 ;;; Requirements:
33 ;; eukleides | http://eukleides.org
34 ;; eukleides | `org-eukleides-path' should point to the eukleides executablexs
36 ;;; Code:
37 (require 'ob)
38 (require 'ob-eval)
40 (defvar org-babel-default-header-args:eukleides
41 '((:results . "file") (:exports . "results"))
42 "Default arguments for evaluating a eukleides source block.")
44 (defcustom org-eukleides-path nil
45 "Path to the eukleides executable file."
46 :group 'org-babel
47 :type 'string)
49 (defcustom org-eukleides-eps-to-raster nil
50 "Command used to convert EPS to raster. Nil for no conversion."
51 :group 'org-babel
52 :type '(choice
53 (repeat :tag "Shell Command Sequence" (string :tag "Shell Command"))
54 (const :tag "sam2p" "a=%s;b=%s;sam2p ${a} ${b}" )
55 (const :tag "NetPNM" "a=%s;b=%s;pstopnm -stdout ${a} | pnmtopng > ${b}" )
56 (const :tag "None" nil)))
58 (defun org-babel-execute:eukleides (body params)
59 "Execute a block of eukleides code with org-babel.
60 This function is called by `org-babel-execute-src-block'."
61 (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
62 (out-file (or (cdr (assoc :file params))
63 (error "Eukleides requires a \":file\" header argument")))
64 (cmdline (cdr (assoc :cmdline params)))
65 (in-file (org-babel-temp-file "eukleides-"))
66 (java (or (cdr (assoc :java params)) ""))
67 (cmd (if (not org-eukleides-path)
68 (error "`org-eukleides-path' is not set")
69 (concat (expand-file-name org-eukleides-path)
70 " -b --output="
71 (org-babel-process-file-name
72 (concat
73 (file-name-sans-extension out-file) ".eps"))
74 " "
75 (org-babel-process-file-name in-file)))))
76 (unless (file-exists-p org-eukleides-path)
77 (error "Could not find eukleides at %s" org-eukleides-path))
79 (if (string= (file-name-extension out-file) "png")
80 (if org-eukleides-eps-to-raster
81 (shell-command (format org-eukleides-eps-to-raster
82 (concat (file-name-sans-extension out-file) ".eps")
83 (concat (file-name-sans-extension out-file) ".png")))
84 (error "Conversion to PNG not supported. use a file with an EPS name")))
86 (with-temp-file in-file (insert body))
87 (message "%s" cmd) (org-babel-eval cmd "")
88 nil)) ;; signal that output has already been written to file
90 (defun org-babel-prep-session:eukleides (session params)
91 "Return an error because eukleides does not support sessions."
92 (error "Eukleides does not support sessions"))
94 (provide 'ob-eukleides)
98 ;;; ob-eukleides.el ends here