Fix `org-edit-special' on file names with spaces
[org-mode.git] / lisp / ob-coq.el
blobbe3b9f6fd3fad41041e59cae153b930cc181906e
1 ;;; ob-coq.el --- org-babel functions for Coq
3 ;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
5 ;; Author: Eric Schulte
6 ;; Keywords: literate programming, reproducible research
7 ;; Homepage: http://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 <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Rudimentary support for evaluating Coq code blocks. Currently only
27 ;; session evaluation is supported. Requires both coq.el and
28 ;; coq-inferior.el, both of which are distributed with Coq.
30 ;; http://coq.inria.fr/
32 ;;; Code:
33 (require 'ob)
35 (declare-function run-coq "ext:coq-inferior.el" (cmd))
36 (declare-function coq-proc "ext:coq-inferior.el" ())
38 (defvar org-babel-coq-buffer "*coq*"
39 "Buffer in which to evaluate coq code blocks.")
41 (defvar org-babel-coq-eoe "org-babel-coq-eoe")
43 (defun org-babel-coq-clean-prompt (string)
44 (if (string-match "^[^[:space:]]+ < " string)
45 (substring string 0 (match-beginning 0))
46 string))
48 (defun org-babel-execute:coq (body params)
49 (let ((full-body (org-babel-expand-body:generic body params))
50 (session (org-babel-coq-initiate-session))
51 (pt (lambda ()
52 (marker-position
53 (process-mark (get-buffer-process (current-buffer)))))))
54 (org-babel-coq-clean-prompt
55 (org-babel-comint-in-buffer session
56 (let ((start (funcall pt)))
57 (with-temp-buffer
58 (insert full-body)
59 (comint-send-region (coq-proc) (point-min) (point-max))
60 (comint-send-string (coq-proc)
61 (if (string= (buffer-substring (- (point-max) 1) (point-max)) ".")
62 "\n"
63 ".\n")))
64 (while (equal start (funcall pt)) (sleep-for 0.1))
65 (buffer-substring start (funcall pt)))))))
67 (defun org-babel-coq-initiate-session ()
68 "Initiate a coq session.
69 If there is not a current inferior-process-buffer in SESSION then
70 create one. Return the initialized session."
71 (unless (fboundp 'run-coq)
72 (error "`run-coq' not defined, load coq-inferior.el."))
73 (save-window-excursion (run-coq "coqtop"))
74 (sit-for 0.1)
75 (get-buffer org-babel-coq-buffer))
77 (provide 'ob-coq)