annotate lisp/org/ob-lisp.el @ 111797:b2c5606310f5

diff-sentinel trivia. * lisp/ibuf-ext.el (diff-sentinel): Update declaration. * lisp/ibuffer.el: Regenerate autoloads. * lisp/vc/diff.el (diff-sentinel): Make new arguments optional, eg for the sake of ibuffer-diff-buffer-with-file-1.
author Glenn Morris <rgm@gnu.org>
date Thu, 02 Dec 2010 19:01:16 -0800
parents 76c2ff4450eb
children a7740098b594
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1 ;;; ob-lisp.el --- org-babel functions for Common Lisp
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
2
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
4
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
5 ;; Author: David T. O'Toole <dto@gnu.org>
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
6 ;; Eric Schulte
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
7 ;; Keywords: literate programming, reproducible research, lisp
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
8 ;; Homepage: http://orgmode.org
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
9 ;; Version: 7.3
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
10
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
11 ;; This file is part of GNU Emacs.
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
12
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
16 ;; (at your option) any later version.
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
17
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
21 ;; GNU General Public License for more details.
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
22
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
111521
76c2ff4450eb Standardize some file headers.
Glenn Morris <rgm@gnu.org>
parents: 111508
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
25
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
26 ;;; Commentary:
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
27
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
28 ;; Now working with SBCL for both session and external evaluation.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
29 ;;
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
30 ;; This certainly isn't optimally robust, but it seems to be working
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
31 ;; for the basic use cases.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
32
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
33 ;;; Requirements:
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
34
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
35 ;; Requires SLIME (Superior Lisp Interaction Mode for Emacs.)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
36 ;; See http://common-lisp.net/project/slime/
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
37
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
38 ;;; Code:
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
39 (require 'ob)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
40 (require 'ob-ref)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
41 (require 'ob-comint)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
42 (require 'ob-eval)
111508
45f3703e90f2 Fix ob-lisp.el expectation that slime would be available
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111506
diff changeset
43 (declare-function slime-eval "ext:slime" (form))
45f3703e90f2 Fix ob-lisp.el expectation that slime would be available
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111506
diff changeset
44 (declare-function slime-connected-p "ext:slime" ())
45f3703e90f2 Fix ob-lisp.el expectation that slime would be available
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111506
diff changeset
45 (declare-function slime-process "ext:slime" ())
45f3703e90f2 Fix ob-lisp.el expectation that slime would be available
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111506
diff changeset
46 (require 'slime nil 'noerror)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
47
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
48 (defvar org-babel-default-header-args:lisp '()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
49 "Default header arguments for lisp code blocks.")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
50
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
51 (defcustom org-babel-lisp-cmd "sbcl --script"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
52 "Name of command used to evaluate lisp blocks.")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
53
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
54 (defun org-babel-expand-body:lisp (body params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
55 "Expand BODY according to PARAMS, return the expanded body."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
56 (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
57 (if (> (length vars) 0)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
58 (concat "(let ("
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
59 (mapconcat
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
60 (lambda (var) (format "%S" (print `(,(car var) ',(cdr var)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
61 vars "\n ")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
62 ")\n" body ")")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
63 body)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
64
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
65 (defun org-babel-execute:lisp (body params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
66 "Execute a block of Lisp code with org-babel.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
67 This function is called by `org-babel-execute-src-block'"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
68 (message "executing Lisp source code block")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
69 (let* ((session (org-babel-lisp-initiate-session
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
70 (cdr (assoc :session params))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
71 (result-type (cdr (assoc :result-type params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
72 (full-body (org-babel-expand-body:lisp body params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
73 (read
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
74 (if session
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
75 ;; session evaluation
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
76 (save-window-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
77 (cadr (slime-eval `(swank:eval-and-grab-output ,full-body))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
78 ;; external evaluation
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
79 (let ((script-file (org-babel-temp-file "lisp-script-")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
80 (with-temp-file script-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
81 (insert
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
82 ;; return the value or the output
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
83 (if (string= result-type "value")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
84 (format "(print %s)" full-body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
85 full-body)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
86 (org-babel-eval
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
87 (format "%s %s" org-babel-lisp-cmd
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
88 (org-babel-process-file-name script-file)) ""))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
89
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
90 ;; This function should be used to assign any variables in params in
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
91 ;; the context of the session environment.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
92 (defun org-babel-prep-session:lisp (session params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
93 "Prepare SESSION according to the header arguments specified in PARAMS."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
94 (error "not yet implemented"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
95
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
96 (defun org-babel-lisp-initiate-session (&optional session)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
97 "If there is not a current inferior-process-buffer in SESSION
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
98 then create. Return the initialized session."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
99 (unless (string= session "none")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
100 (save-window-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
101 (or (slime-connected-p)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
102 (slime-process)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
103
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
104 (provide 'ob-lisp)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
105
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
106 ;; arch-tag: 18086168-009f-4947-bbb5-3532375d851d
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
107
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
108 ;;; ob-lisp.el ends here