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/>.
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/
35 (defvar org-babel-coq-buffer
"*coq*"
36 "Buffer in which to evaluate coq code blocks.")
38 (defvar org-babel-coq-eoe
"org-babel-coq-eoe")
40 (defun org-babel-coq-clean-prompt (string)
41 (if (string-match "^[^[:space:]]+ < " string
)
42 (substring string
0 (match-beginning 0))
45 (defun org-babel-execute:coq
(body params
)
46 (let ((full-body (org-babel-expand-body:generic body params
))
47 (session (org-babel-coq-initiate-session))
50 (process-mark (get-buffer-process (current-buffer)))))))
51 (org-babel-coq-clean-prompt
52 (org-babel-comint-in-buffer session
53 (let ((start (funcall pt
)))
56 (comint-send-region (coq-proc) (point-min) (point-max))
57 (comint-send-string (coq-proc)
58 (if (string= (buffer-substring (- (point-max) 1) (point-max)) ".")
61 (while (equal start
(funcall pt
)) (sleep-for 0.1))
62 (buffer-substring start
(funcall pt
)))))))
64 (defun org-babel-coq-initiate-session ()
65 "Initiate a coq session.
66 If there is not a current inferior-process-buffer in SESSION then
67 create one. Return the initialized session."
68 (unless (fboundp 'run-coq
)
69 (error "`run-coq' not defined, load coq-inferior.el."))
70 (save-window-excursion (run-coq "coqtop"))
72 (get-buffer org-babel-coq-buffer
))