annotate lisp/org/ob.el @ 112314:b43e3dd4da2d

* lib/COPYING: New file, a copy of COPYING.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 08 Jan 2011 23:43:55 -0800
parents a7740098b594
children 6378d1b57038
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1 ;;; ob.el --- working with code blocks in org-mode
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
2
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
4
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
5 ;; Author: Eric Schulte, Dan Davison
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
6 ;; Keywords: literate programming, reproducible research
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
7 ;; Homepage: http://orgmode.org
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
8 ;; Version: 7.4
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
9
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
11
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
15 ;; (at your option) any later version.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
16
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
21
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
24
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
25 ;;; Commentary:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
26
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
27 ;; See the online documentation for more information
109812
063e94b66261 Fix some Org errors revealed by `make check-declare'.
Glenn Morris <rgm@gnu.org>
parents: 109462
diff changeset
28 ;;
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
29 ;; http://orgmode.org/worg/org-contrib/babel/
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
30
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
31 ;;; Code:
109823
6452d50492bb Fix some more Org `check-declare' issues.
Glenn Morris <rgm@gnu.org>
parents: 109812
diff changeset
32 (eval-when-compile
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
33 (require 'org-list)
109847
80192451ba34 Fix previous Org change.
Glenn Morris <rgm@gnu.org>
parents: 109823
diff changeset
34 (require 'cl))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
35 (require 'ob-eval)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
36 (require 'org-macs)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
37
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
38 (defvar org-babel-call-process-region-original)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
39 (declare-function show-all "outline" ())
109812
063e94b66261 Fix some Org errors revealed by `make check-declare'.
Glenn Morris <rgm@gnu.org>
parents: 109462
diff changeset
40 (declare-function tramp-compat-make-temp-file "tramp-compat"
063e94b66261 Fix some Org errors revealed by `make check-declare'.
Glenn Morris <rgm@gnu.org>
parents: 109462
diff changeset
41 (filename &optional dir-flag))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
42 (declare-function tramp-dissect-file-name "tramp" (name &optional nodefault))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
43 (declare-function tramp-file-name-user "tramp" (vec))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
44 (declare-function tramp-file-name-host "tramp" (vec))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
45 (declare-function with-parsed-tramp-file-name "tramp" (filename var &rest body))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
46 (declare-function org-icompleting-read "org" (&rest args))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
47 (declare-function org-edit-src-code "org-src"
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
48 (&optional context code edit-buffer-name quietp))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
49 (declare-function org-edit-src-exit "org-src" (&optional context))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
50 (declare-function org-open-at-point "org" (&optional in-emacs reference-buffer))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
51 (declare-function org-save-outline-visibility "org" (use-markers &rest body))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
52 (declare-function org-outline-overlay-data "org" (&optional use-markers))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
53 (declare-function org-set-outline-overlay-data "org" (data))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
54 (declare-function org-narrow-to-subtree "org" ())
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
55 (declare-function org-entry-get "org"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
56 (pom property &optional inherit literal-nil))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
57 (declare-function org-make-options-regexp "org" (kwds &optional extra))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
58 (declare-function org-do-remove-indentation "org" (&optional n))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
59 (declare-function org-show-context "org" (&optional key))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
60 (declare-function org-at-table-p "org" (&optional table-type))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
61 (declare-function org-cycle "org" (&optional arg))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
62 (declare-function org-uniquify "org" (list))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
63 (declare-function org-current-level "org" ())
109812
063e94b66261 Fix some Org errors revealed by `make check-declare'.
Glenn Morris <rgm@gnu.org>
parents: 109462
diff changeset
64 (declare-function org-table-import "org-table" (file arg))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
65 (declare-function org-add-hook "org-compat"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
66 (hook function &optional append local))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
67 (declare-function org-table-align "org-table" ())
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
68 (declare-function org-table-end "org-table" (&optional table-type))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
69 (declare-function orgtbl-to-generic "org-table" (table params))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
70 (declare-function orgtbl-to-orgtbl "org-table" (table params))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
71 (declare-function org-babel-lob-get-info "ob-lob" nil)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
72 (declare-function org-babel-ref-split-args "ob-ref" (arg-string))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
73 (declare-function org-babel-ref-parse "ob-ref" (assignment))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
74 (declare-function org-babel-ref-resolve "ob-ref" (ref))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
75 (declare-function org-babel-lob-execute-maybe "ob-lob" ())
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
76 (declare-function org-number-sequence "org-compat" (from &optional to inc))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
77 (declare-function org-in-item-p "org-list" ())
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
78 (declare-function org-list-parse-list "org-list" (&optional delete))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
79 (declare-function org-list-to-generic "org-list" (LIST PARAMS))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
80 (declare-function org-list-bottom-point "org-list" ())
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
81
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
82 (defgroup org-babel nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
83 "Code block evaluation and management in `org-mode' documents."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
84 :tag "Babel"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
85 :group 'org)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
86
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
87 (defcustom org-confirm-babel-evaluate t
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
88 "Confirm before evaluation.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
89 Require confirmation before interactively evaluating code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
90 blocks in Org-mode buffers. The default value of this variable
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
91 is t, meaning confirmation is required for any code block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
92 evaluation. This variable can be set to nil to inhibit any
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
93 future confirmation requests. This variable can also be set to a
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
94 function which takes two arguments the language of the code block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
95 and the body of the code block. Such a function should then
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
96 return a non-nil value if the user should be prompted for
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
97 execution or nil if no prompt is required.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
98
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
99 Warning: Disabling confirmation may result in accidental
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
100 evaluation of potentially harmful code. It may be advisable
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
101 remove code block execution from C-c C-c as further protection
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
102 against accidental code block evaluation. The
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
103 `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can be used to
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
104 remove code block execution from the C-c C-c keybinding."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
105 :group 'org-babel
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
106 :type '(choice boolean function))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
107 ;; don't allow this variable to be changed through file settings
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
108 (put 'org-confirm-babel-evaluate 'safe-local-variable (lambda (x) (eq x t)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
109
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
110 (defcustom org-babel-no-eval-on-ctrl-c-ctrl-c nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
111 "Remove code block evaluation from the C-c C-c key binding."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
112 :group 'org-babel
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
113 :type 'boolean)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
114
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
115 (defvar org-babel-src-name-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
116 "^[ \t]*#\\+\\(srcname\\|source\\|function\\):[ \t]*"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
117 "Regular expression used to match a source name line.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
118
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
119 (defvar org-babel-multi-line-header-regexp
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
120 "^[ \t]*#\\+headers?:[ \t]*\\([^\n]*\\)$"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
121 "Regular expression used to match multi-line header arguments.")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
122
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
123 (defvar org-babel-src-name-w-name-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
124 (concat org-babel-src-name-regexp
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
125 "\\("
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
126 org-babel-multi-line-header-regexp
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
127 "\\)*"
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
128 "\\([^ ()\f\t\n\r\v]+\\)\\(\(\\(.*\\)\)\\|\\)")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
129 "Regular expression matching source name lines with a name.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
130
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
131 (defvar org-babel-src-block-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
132 (concat
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
133 ;; (1) indentation (2) lang
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
134 "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
135 ;; (3) switches
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
136 "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
137 ;; (4) header arguments
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
138 "\\([^\n]*\\)\n"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
139 ;; (5) body
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
140 "\\([^\000]+?\n\\)[ \t]*#\\+end_src")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
141 "Regexp used to identify code blocks.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
142
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
143 (defvar org-babel-inline-src-block-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
144 (concat
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
145 ;; (1) replacement target (2) lang
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
146 "[ \f\t\n\r\v]\\(src_\\([^ \f\t\n\r\v]+\\)"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
147 ;; (3,4) (unused, headers)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
148 "\\(\\|\\[\\(.*?\\)\\]\\)"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
149 ;; (5) body
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
150 "{\\([^\f\n\r\v]+?\\)}\\)")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
151 "Regexp used to identify inline src-blocks.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
152
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
153 (defun org-babel-get-header (params key &optional others)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
154 "Select only header argument of type KEY from a list.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
155 Optional argument OTHERS indicates that only the header that do
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
156 not match KEY should be returned."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
157 (delq nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
158 (mapcar
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
159 (lambda (p) (when (funcall (if others #'not #'identity) (eq (car p) key)) p))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
160 params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
161
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
162 (defun org-babel-get-src-block-info (&optional light)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
163 "Get information on the current source block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
164
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
165 Optional argument LIGHT does not resolve remote variable
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
166 references; a process which could likely result in the execution
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
167 of other code blocks.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
168
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
169 Returns a list
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
170 (language body header-arguments-alist switches name indent)."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
171 (let ((case-fold-search t) head info name indent)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
172 ;; full code block
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
173 (if (setq head (org-babel-where-is-src-block-head))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
174 (save-excursion
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
175 (goto-char head)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
176 (setq info (org-babel-parse-src-block-match))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
177 (setq indent (car (last info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
178 (setq info (butlast info))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
179 (while (and (forward-line -1)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
180 (looking-at org-babel-multi-line-header-regexp))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
181 (setf (nth 2 info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
182 (org-babel-merge-params
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
183 (org-babel-parse-header-arguments (match-string 1))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
184 (nth 2 info))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
185 (when (looking-at org-babel-src-name-w-name-regexp)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
186 (setq name (org-babel-clean-text-properties (match-string 4)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
187 (when (match-string 6)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
188 (setf (nth 2 info) ;; merge functional-syntax vars and header-args
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
189 (org-babel-merge-params
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
190 (mapcar (lambda (ref) (cons :var ref))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
191 (org-babel-ref-split-args (match-string 6)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
192 (nth 2 info))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
193 ;; inline source block
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
194 (when (save-excursion (re-search-backward "[ \f\t\n\r\v]" nil t)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
195 (looking-at org-babel-inline-src-block-regexp))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
196 (setq info (org-babel-parse-inline-src-block-match))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
197 ;; resolve variable references and add summary parameters
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
198 (when (and info (not light))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
199 (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
200 (when info (append info (list name indent)))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
201
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
202 (defun org-babel-confirm-evaluate (info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
203 "Confirm evaluation of the code block INFO.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
204 This behavior can be suppressed by setting the value of
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
205 `org-confirm-babel-evaluate' to nil, in which case all future
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
206 interactive code block evaluations will proceed without any
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
207 confirmation from the user.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
208
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
209 Note disabling confirmation may result in accidental evaluation
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
210 of potentially harmful code."
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
211 (let* ((eval (or (cdr (assoc :eval (nth 2 info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
212 (when (assoc :noeval (nth 2 info)) "no")))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
213 (query (or (equal eval "query")
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
214 (if (functionp org-confirm-babel-evaluate)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
215 (funcall org-confirm-babel-evaluate
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
216 (nth 0 info) (nth 1 info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
217 org-confirm-babel-evaluate))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
218 (if (or (equal eval "never") (equal eval "no")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
219 (and query
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
220 (not (yes-or-no-p
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
221 (format "Evaluate this%scode block%son your system? "
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
222 (if info (format " %s " (nth 0 info)) " ")
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
223 (if (nth 4 info)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
224 (format " (%s) " (nth 4 info)) " "))))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
225 (prog1 nil (message "Evaluation %s"
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
226 (if (or (equal eval "never") (equal eval "no"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
227 "Disabled" "Aborted")))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
228 t)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
229
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
230 ;;;###autoload
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
231 (defun org-babel-execute-safely-maybe ()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
232 (unless org-babel-no-eval-on-ctrl-c-ctrl-c
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
233 (org-babel-execute-maybe)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
234
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
235 (add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-execute-safely-maybe)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
236
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
237 ;;;###autoload
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
238 (defun org-babel-execute-maybe ()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
239 (interactive)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
240 (or (org-babel-execute-src-block-maybe)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
241 (org-babel-lob-execute-maybe)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
242
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
243 (defun org-babel-execute-src-block-maybe ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
244 "Conditionally execute a source block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
245 Detect if this is context for a Babel src-block and if so
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
246 then run `org-babel-execute-src-block'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
247 (interactive)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
248 (let ((info (org-babel-get-src-block-info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
249 (if info
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
250 (progn (org-babel-eval-wipe-error-buffer)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
251 (org-babel-execute-src-block current-prefix-arg info) t) nil)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
252
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
253 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
254 (defun org-babel-expand-src-block-maybe ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
255 "Conditionally expand a source block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
256 Detect if this is context for a org-babel src-block and if so
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
257 then run `org-babel-expand-src-block'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
258 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
259 (let ((info (org-babel-get-src-block-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
260 (if info
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
261 (progn (org-babel-expand-src-block current-prefix-arg info) t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
262 nil)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
263
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
264 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
265 (defun org-babel-load-in-session-maybe ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
266 "Conditionally load a source block in a session.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
267 Detect if this is context for a org-babel src-block and if so
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
268 then run `org-babel-load-in-session'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
269 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
270 (let ((info (org-babel-get-src-block-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
271 (if info
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
272 (progn (org-babel-load-in-session current-prefix-arg info) t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
273 nil)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
274
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
275 (add-hook 'org-metaup-hook 'org-babel-load-in-session-maybe)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
276
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
277 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
278 (defun org-babel-pop-to-session-maybe ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
279 "Conditionally pop to a session.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
280 Detect if this is context for a org-babel src-block and if so
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
281 then run `org-babel-pop-to-session'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
282 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
283 (let ((info (org-babel-get-src-block-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
284 (if info (progn (org-babel-pop-to-session current-prefix-arg info) t) nil)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
285
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
286 (add-hook 'org-metadown-hook 'org-babel-pop-to-session-maybe)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
287
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
288 (defconst org-babel-header-arg-names
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
289 '(cache cmdline colnames dir exports file noweb results
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
290 session tangle var eval noeval comments)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
291 "Common header arguments used by org-babel.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
292 Note that individual languages may define their own language
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
293 specific header arguments as well.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
294
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
295 (defvar org-babel-default-header-args
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
296 '((:session . "none") (:results . "replace") (:exports . "code")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
297 (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
298 "Default arguments to use when evaluating a source block.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
299
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
300 (defvar org-babel-default-inline-header-args
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
301 '((:session . "none") (:results . "silent") (:exports . "results"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
302 "Default arguments to use when evaluating an inline source block.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
303
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
304 (defvar org-babel-current-buffer-properties nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
305 "Local cache for buffer properties.")
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
306 (make-variable-buffer-local 'org-babel-current-buffer-properties)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
307
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
308 (defvar org-babel-result-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
309 "^[ \t]*#\\+res\\(ults\\|name\\)\\(\\[\\([[:alnum:]]+\\)\\]\\)?\\:[ \t]*"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
310 "Regular expression used to match result lines.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
311 If the results are associated with a hash key then the hash will
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
312 be saved in the second match data.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
313
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
314 (defvar org-babel-result-w-name-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
315 (concat org-babel-result-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
316 "\\([^ ()\f\t\n\r\v]+\\)\\(\(\\(.*\\)\)\\|\\)"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
317
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
318 (defvar org-babel-min-lines-for-block-output 10
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
319 "The minimum number of lines for block output.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
320 If number of lines of output is equal to or exceeds this
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
321 value, the output is placed in a #+begin_example...#+end_example
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
322 block. Otherwise the output is marked as literal by inserting
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
323 colons at the starts of the lines. This variable only takes
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
324 effect if the :results output option is in effect.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
325
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
326 (defvar org-babel-noweb-error-langs nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
327 "Languages for which Babel will raise literate programming errors.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
328 List of languages for which errors should be raised when the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
329 source code block satisfying a noweb reference in this language
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
330 can not be resolved.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
331
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
332 (defvar org-babel-hash-show 4
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
333 "Number of initial characters to show of a hidden results hash.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
334
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
335 (defvar org-babel-after-execute-hook nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
336 "Hook for functions to be called after `org-babel-execute-src-block'")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
337 (defun org-babel-named-src-block-regexp-for-name (name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
338 "This generates a regexp used to match a src block named NAME."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
339 (concat org-babel-src-name-regexp (regexp-quote name) "[ \t\n]*"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
340 (substring org-babel-src-block-regexp 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
341
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
342 ;;; functions
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
343 (defvar call-process-region)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
344 ;;;###autoload
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
345
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
346 (defun org-babel-execute-src-block (&optional arg info params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
347 "Execute the current source code block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
348 Insert the results of execution into the buffer. Source code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
349 execution and the collection and formatting of results can be
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
350 controlled through a variety of header arguments.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
351
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
352 With prefix argument ARG, force re-execution even if a an
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
353 existing result cached in the buffer would otherwise have been
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
354 returned.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
355
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
356 Optionally supply a value for INFO in the form returned by
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
357 `org-babel-get-src-block-info'.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
358
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
359 Optionally supply a value for PARAMS which will be merged with
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
360 the header arguments specified at the front of the source code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
361 block."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
362 (interactive)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
363 (let ((info (or info (org-babel-get-src-block-info))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
364 (when (org-babel-confirm-evaluate info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
365 (let* ((lang (nth 0 info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
366 (params (if params
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
367 (org-babel-process-params
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
368 (org-babel-merge-params (nth 2 info) params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
369 (nth 2 info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
370 (cache? (and (not arg) (cdr (assoc :cache params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
371 (string= "yes" (cdr (assoc :cache params)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
372 (result-params (cdr (assoc :result-params params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
373 (new-hash (when cache? (org-babel-sha1-hash info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
374 (old-hash (when cache? (org-babel-result-hash info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
375 (body (setf (nth 1 info)
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
376 (let ((noweb (cdr (assoc :noweb params))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
377 (if (and noweb
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
378 (or (string= "yes" noweb)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
379 (string= "tangle" noweb)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
380 (org-babel-expand-noweb-references info)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
381 (nth 1 info)))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
382 (cmd (intern (concat "org-babel-execute:" lang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
383 (dir (cdr (assoc :dir params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
384 (default-directory
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
385 (or (and dir (file-name-as-directory dir)) default-directory))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
386 (org-babel-call-process-region-original
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
387 (if (boundp 'org-babel-call-process-region-original)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
388 org-babel-call-process-region-original
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
389 (symbol-function 'call-process-region)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
390 (indent (car (last info)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
391 result)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
392 (unwind-protect
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
393 (flet ((call-process-region (&rest args)
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
394 (apply 'org-babel-tramp-handle-call-process-region args)))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
395 (unless (fboundp cmd)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
396 (error "No org-babel-execute function for %s!" lang))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
397 (if (and (not arg) new-hash (equal new-hash old-hash))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
398 (save-excursion ;; return cached result
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
399 (goto-char (org-babel-where-is-src-block-result nil info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
400 (end-of-line 1) (forward-char 1)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
401 (setq result (org-babel-read-result))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
402 (message (replace-regexp-in-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
403 "%" "%%" (format "%S" result))) result)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
404 (message "executing %s code block%s..."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
405 (capitalize lang)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
406 (if (nth 4 info) (format " (%s)" (nth 4 info)) ""))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
407 (setq result
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
408 ((lambda (result)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
409 (cond
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
410 ((member "file" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
411 (cdr (assoc :file params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
412 ((and (eq (cdr (assoc :result-type params)) 'value)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
413 (or (member "vector" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
414 (member "table" result-params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
415 (not (listp result)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
416 (list (list result)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
417 (t result)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
418 (funcall cmd body params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
419 (org-babel-insert-result
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
420 result result-params info new-hash indent lang)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
421 (run-hooks 'org-babel-after-execute-hook)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
422 result))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
423 (setq call-process-region 'org-babel-call-process-region-original))))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
424
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
425 (defun org-babel-expand-body:generic (body params &optional var-lines)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
426 "Expand BODY with PARAMS.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
427 Expand a block of code with org-babel according to it's header
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
428 arguments. This generic implementation of body expansion is
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
429 called for languages which have not defined their own specific
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
430 org-babel-expand-body:lang function."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
431 (mapconcat #'identity (append var-lines (list body)) "\n"))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
432
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
433 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
434 (defun org-babel-expand-src-block (&optional arg info params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
435 "Expand the current source code block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
436 Expand according to the source code block's header
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
437 arguments and pop open the results in a preview buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
438 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
439 (let* ((info (or info (org-babel-get-src-block-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
440 (lang (nth 0 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
441 (params (setf (nth 2 info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
442 (sort (org-babel-merge-params (nth 2 info) params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
443 (lambda (el1 el2) (string< (symbol-name (car el1))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
444 (symbol-name (car el2)))))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
445 (body (setf (nth 1 info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
446 (if (and (cdr (assoc :noweb params))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
447 (string= "yes" (cdr (assoc :noweb params))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
448 (org-babel-expand-noweb-references info) (nth 1 info))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
449 (expand-cmd (intern (concat "org-babel-expand-body:" lang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
450 (assignments-cmd (intern (concat "org-babel-variable-assignments:" lang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
451 (expanded
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
452 (if (fboundp expand-cmd) (funcall expand-cmd body params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
453 (org-babel-expand-body:generic
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
454 body params (and (fboundp assignments-cmd) (funcall assignments-cmd params))))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
455 (org-edit-src-code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
456 nil expanded (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
457
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
458 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
459 (defun org-babel-load-in-session (&optional arg info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
460 "Load the body of the current source-code block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
461 Evaluate the header arguments for the source block before
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
462 entering the session. After loading the body this pops open the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
463 session."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
464 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
465 (let* ((info (or info (org-babel-get-src-block-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
466 (lang (nth 0 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
467 (params (nth 2 info))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
468 (body (setf (nth 1 info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
469 (if (and (cdr (assoc :noweb params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
470 (string= "yes" (cdr (assoc :noweb params))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
471 (org-babel-expand-noweb-references info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
472 (nth 1 info))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
473 (session (cdr (assoc :session params)))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
474 (dir (cdr (assoc :dir params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
475 (default-directory
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
476 (or (and dir (file-name-as-directory dir)) default-directory))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
477 (cmd (intern (concat "org-babel-load-session:" lang))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
478 (unless (fboundp cmd)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
479 (error "No org-babel-load-session function for %s!" lang))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
480 (pop-to-buffer (funcall cmd session body params))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
481 (end-of-line 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
482
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
483 ;;;###autoload
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
484 (defun org-babel-initiate-session (&optional arg info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
485 "Initiate session for current code block.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
486 If called with a prefix argument then resolve any variable
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
487 references in the header arguments and assign these variables in
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
488 the session. Copy the body of the code block to the kill ring."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
489 (interactive "P")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
490 (let* ((info (or info (org-babel-get-src-block-info (not arg))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
491 (lang (nth 0 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
492 (body (nth 1 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
493 (params (nth 2 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
494 (session (cdr (assoc :session params)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
495 (dir (cdr (assoc :dir params)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
496 (default-directory
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
497 (or (and dir (file-name-as-directory dir)) default-directory))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
498 (init-cmd (intern (format "org-babel-%s-initiate-session" lang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
499 (prep-cmd (intern (concat "org-babel-prep-session:" lang))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
500 (if (and (stringp session) (string= session "none"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
501 (error "This block is not using a session!"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
502 (unless (fboundp init-cmd)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
503 (error "No org-babel-initiate-session function for %s!" lang))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
504 (with-temp-buffer (insert (org-babel-trim body))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
505 (copy-region-as-kill (point-min) (point-max)))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
506 (when arg
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
507 (unless (fboundp prep-cmd)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
508 (error "No org-babel-prep-session function for %s!" lang))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
509 (funcall prep-cmd session params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
510 (funcall init-cmd session params)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
511
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
512 ;;;###autoload
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
513 (defun org-babel-switch-to-session (&optional arg info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
514 "Switch to the session of the current code block.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
515 Uses `org-babel-initiate-session' to start the session. If called
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
516 with a prefix argument then this is passed on to
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
517 `org-babel-initiate-session'."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
518 (interactive "P")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
519 (pop-to-buffer (org-babel-initiate-session arg info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
520 (end-of-line 1))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
521
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
522 (defalias 'org-babel-pop-to-session 'org-babel-switch-to-session)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
523
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
524 ;;;###autoload
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
525 (defun org-babel-switch-to-session-with-code (&optional arg info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
526 "Switch to code buffer and display session."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
527 (interactive "P")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
528 (flet ((swap-windows
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
529 ()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
530 (let ((other-window-buffer (window-buffer (next-window))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
531 (set-window-buffer (next-window) (current-buffer))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
532 (set-window-buffer (selected-window) other-window-buffer))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
533 (other-window 1)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
534 (let ((info (org-babel-get-src-block-info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
535 (org-src-window-setup 'reorganize-frame))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
536 (save-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
537 (org-babel-switch-to-session arg info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
538 (org-edit-src-code))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
539 (swap-windows)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
540
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
541 (defmacro org-babel-do-in-edit-buffer (&rest body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
542 "Evaluate BODY in edit buffer if there is a code block at point.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
543 Return t if a code block was found at point, nil otherwise."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
544 `(let ((org-src-window-setup 'switch-invisibly))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
545 (when (and (org-babel-where-is-src-block-head)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
546 (org-edit-src-code nil nil nil 'quietly))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
547 (unwind-protect (progn ,@body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
548 (if (org-bound-and-true-p org-edit-src-from-org-mode)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
549 (org-edit-src-exit)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
550 t)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
551
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
552 (defun org-babel-do-key-sequence-in-edit-buffer (key)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
553 "Read key sequence and execute the command in edit buffer.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
554 Enter a key sequence to be executed in the language major-mode
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
555 edit buffer. For example, TAB will alter the contents of the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
556 Org-mode code block according to the effect of TAB in the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
557 language major-mode buffer. For languages that support
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
558 interactive sessions, this can be used to send code from the Org
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
559 buffer to the session for evaluation using the native major-mode
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
560 evaluation mechanisms."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
561 (interactive "kEnter key-sequence to execute in edit buffer: ")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
562 (org-babel-do-in-edit-buffer
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
563 (call-interactively
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
564 (key-binding (or key (read-key-sequence nil))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
565
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
566 (defvar org-bracket-link-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
567 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
568 (defun org-babel-open-src-block-result (&optional re-run)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
569 "If `point' is on a src block then open the results of the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
570 source code block, otherwise return nil. With optional prefix
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
571 argument RE-RUN the source-code block is evaluated even if
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
572 results already exist."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
573 (interactive "P")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
574 (when (org-babel-get-src-block-info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
575 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
576 ;; go to the results, if there aren't any then run the block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
577 (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
578 (progn (org-babel-execute-src-block)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
579 (org-babel-where-is-src-block-result))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
580 (end-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
581 (while (looking-at "[\n\r\t\f ]") (forward-char 1))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
582 ;; open the results
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
583 (if (looking-at org-bracket-link-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
584 ;; file results
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
585 (org-open-at-point)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
586 (let ((results (org-babel-read-result)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
587 (flet ((echo-res (result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
588 (if (stringp result) result (format "%S" result))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
589 (pop-to-buffer (get-buffer-create "org-babel-results"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
590 (delete-region (point-min) (point-max))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
591 (if (listp results)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
592 ;; table result
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
593 (insert (orgtbl-to-generic results '(:sep "\t" :fmt echo-res)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
594 ;; scalar result
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
595 (insert (echo-res results))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
596 t)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
597
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
598 ;;;###autoload
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
599 (defmacro org-babel-map-src-blocks (file &rest body)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
600 "Evaluate BODY forms on each source-block in FILE.
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
601 If FILE is nil evaluate BODY forms on source blocks in current
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
602 buffer. During evaluation of BODY the following local variables
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
603 are set relative to the currently matched code block.
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
604
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
605 full-block ------- string holding the entirety of the code block
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
606 beg-block -------- point at the beginning of the code block
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
607 end-block -------- point at the end of the matched code block
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
608 lang ------------- string holding the language of the code block
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
609 beg-lang --------- point at the beginning of the lang
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
610 end-lang --------- point at the end of the lang
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
611 switches --------- string holding the switches
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
612 beg-switches ----- point at the beginning of the switches
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
613 end-switches ----- point at the end of the switches
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
614 header-args ------ string holding the header-args
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
615 beg-header-args -- point at the beginning of the header-args
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
616 end-header-args -- point at the end of the header-args
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
617 body ------------- string holding the body of the code block
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
618 beg-body --------- point at the beginning of the body
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
619 end-body --------- point at the end of the body"
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
620 (declare (indent 1))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
621 (let ((tempvar (make-symbol "file")))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
622 `(let* ((,tempvar ,file)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
623 (visited-p (or (null ,tempvar)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
624 (get-file-buffer (expand-file-name ,tempvar))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
625 (point (point)) to-be-removed)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
626 (save-window-excursion
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
627 (when ,tempvar (find-file ,tempvar))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
628 (setq to-be-removed (current-buffer))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
629 (goto-char (point-min))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
630 (while (re-search-forward org-babel-src-block-regexp nil t)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
631 (goto-char (match-beginning 0))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
632 (let ((full-block (match-string 0))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
633 (beg-block (match-beginning 0))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
634 (end-block (match-end 0))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
635 (lang (match-string 2))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
636 (beg-lang (match-beginning 2))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
637 (end-lang (match-end 2))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
638 (switches (match-string 3))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
639 (beg-switches (match-beginning 3))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
640 (end-switches (match-end 3))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
641 (header-args (match-string 4))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
642 (beg-header-args (match-beginning 4))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
643 (end-header-args (match-end 4))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
644 (body (match-string 5))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
645 (beg-body (match-beginning 5))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
646 (end-body (match-end 5)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
647 ,@body
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
648 (goto-char end-block))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
649 (unless visited-p (kill-buffer to-be-removed))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
650 (goto-char point))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
651
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
652 ;;;###autoload
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
653 (defun org-babel-execute-buffer (&optional arg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
654 "Execute source code blocks in a buffer.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
655 Call `org-babel-execute-src-block' on every source block in
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
656 the current buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
657 (interactive "P")
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
658 (org-save-outline-visibility t
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
659 (org-babel-map-src-blocks nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
660 (org-babel-execute-src-block arg))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
661
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
662 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
663 (defun org-babel-execute-subtree (&optional arg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
664 "Execute source code blocks in a subtree.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
665 Call `org-babel-execute-src-block' on every source block in
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
666 the current subtree."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
667 (interactive "P")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
668 (save-restriction
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
669 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
670 (org-narrow-to-subtree)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
671 (org-babel-execute-buffer arg)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
672 (widen))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
673
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
674 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
675 (defun org-babel-sha1-hash (&optional info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
676 "Generate an sha1 hash based on the value of info."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
677 (interactive)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
678 (let ((print-level nil)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
679 (info (or info (org-babel-get-src-block-info))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
680 (setf (nth 2 info)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
681 (sort (copy-sequence (nth 2 info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
682 (lambda (a b) (string< (car a) (car b)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
683 (let ((hash (sha1
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
684 (format "%s-%s"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
685 (mapconcat
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
686 #'identity
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
687 (delq nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
688 (mapcar
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
689 (lambda (arg)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
690 (let ((v (cdr arg)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
691 (when (and v (not (and (sequencep v)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
692 (not (consp v))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
693 (= (length v) 0))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
694 (format "%S" v))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
695 (nth 2 info))) ":")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
696 (nth 1 info)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
697 (when (interactive-p) (message hash))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
698 hash)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
699
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
700 (defun org-babel-result-hash (&optional info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
701 "Return the in-buffer hash associated with INFO."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
702 (org-babel-where-is-src-block-result nil info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
703 (org-babel-clean-text-properties (match-string 3)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
704
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
705 (defun org-babel-hide-hash ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
706 "Hide the hash in the current results line.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
707 Only the initial `org-babel-hash-show' characters of the hash
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
708 will remain visible."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
709 (add-to-invisibility-spec '(org-babel-hide-hash . t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
710 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
711 (when (and (re-search-forward org-babel-result-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
712 (match-string 3))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
713 (let* ((start (match-beginning 3))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
714 (hide-start (+ org-babel-hash-show start))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
715 (end (match-end 3))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
716 (hash (match-string 3))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
717 ov1 ov2)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
718 (setq ov1 (make-overlay start hide-start))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
719 (setq ov2 (make-overlay hide-start end))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
720 (overlay-put ov2 'invisible 'org-babel-hide-hash)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
721 (overlay-put ov1 'babel-hash hash)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
722
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
723 (defun org-babel-hide-all-hashes ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
724 "Hide the hash in the current buffer.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
725 Only the initial `org-babel-hash-show' characters of each hash
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
726 will remain visible. This function should be called as part of
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
727 the `org-mode-hook'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
728 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
729 (while (re-search-forward org-babel-result-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
730 (goto-char (match-beginning 0))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
731 (org-babel-hide-hash)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
732 (goto-char (match-end 0)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
733 (add-hook 'org-mode-hook 'org-babel-hide-all-hashes)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
734
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
735 (defun org-babel-hash-at-point (&optional point)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
736 "Return the value of the hash at POINT.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
737 The hash is also added as the last element of the kill ring.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
738 This can be called with C-c C-c."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
739 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
740 (let ((hash (car (delq nil (mapcar
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
741 (lambda (ol) (overlay-get ol 'babel-hash))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
742 (overlays-at (or point (point))))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
743 (when hash (kill-new hash) (message hash))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
744 (add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-hash-at-point)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
745
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
746 (defun org-babel-result-hide-spec ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
747 "Hide portions of results lines.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
748 Add `org-babel-hide-result' as an invisibility spec for hiding
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
749 portions of results lines."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
750 (add-to-invisibility-spec '(org-babel-hide-result . t)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
751 (add-hook 'org-mode-hook 'org-babel-result-hide-spec)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
752
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
753 (defvar org-babel-hide-result-overlays nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
754 "Overlays hiding results.")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
755
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
756 (defun org-babel-result-hide-all ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
757 "Fold all results in the current buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
758 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
759 (org-babel-show-result-all)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
760 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
761 (while (re-search-forward org-babel-result-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
762 (save-excursion (goto-char (match-beginning 0))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
763 (org-babel-hide-result-toggle-maybe)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
764
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
765 (defun org-babel-show-result-all ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
766 "Unfold all results in the current buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
767 (mapc 'delete-overlay org-babel-hide-result-overlays)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
768 (setq org-babel-hide-result-overlays nil))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
769
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
770 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
771 (defun org-babel-hide-result-toggle-maybe ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
772 "Toggle visibility of result at point."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
773 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
774 (let ((case-fold-search t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
775 (if (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
776 (beginning-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
777 (looking-at org-babel-result-regexp))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
778 (progn (org-babel-hide-result-toggle)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
779 t) ;; to signal that we took action
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
780 nil))) ;; to signal that we did not
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
781
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
782 (defun org-babel-hide-result-toggle (&optional force)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
783 "Toggle the visibility of the current result."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
784 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
785 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
786 (beginning-of-line)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
787 (if (re-search-forward org-babel-result-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
788 (let ((start (progn (beginning-of-line 2) (- (point) 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
789 (end (progn (goto-char (- (org-babel-result-end) 1)) (point)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
790 ov)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
791 (if (memq t (mapcar (lambda (overlay)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
792 (eq (overlay-get overlay 'invisible)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
793 'org-babel-hide-result))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
794 (overlays-at start)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
795 (if (or (not force) (eq force 'off))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
796 (mapc (lambda (ov)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
797 (when (member ov org-babel-hide-result-overlays)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
798 (setq org-babel-hide-result-overlays
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
799 (delq ov org-babel-hide-result-overlays)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
800 (when (eq (overlay-get ov 'invisible)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
801 'org-babel-hide-result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
802 (delete-overlay ov)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
803 (overlays-at start)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
804 (setq ov (make-overlay start end))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
805 (overlay-put ov 'invisible 'org-babel-hide-result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
806 ;; make the block accessible to isearch
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
807 (overlay-put
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
808 ov 'isearch-open-invisible
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
809 (lambda (ov)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
810 (when (member ov org-babel-hide-result-overlays)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
811 (setq org-babel-hide-result-overlays
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
812 (delq ov org-babel-hide-result-overlays)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
813 (when (eq (overlay-get ov 'invisible)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
814 'org-babel-hide-result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
815 (delete-overlay ov))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
816 (push ov org-babel-hide-result-overlays)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
817 (error "Not looking at a result line"))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
818
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
819 ;; org-tab-after-check-for-cycling-hook
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
820 (add-hook 'org-tab-first-hook 'org-babel-hide-result-toggle-maybe)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
821 ;; Remove overlays when changing major mode
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
822 (add-hook 'org-mode-hook
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
823 (lambda () (org-add-hook 'change-major-mode-hook
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
824 'org-babel-show-result-all 'append 'local)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
825
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
826 (defvar org-file-properties)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
827 (defun org-babel-params-from-properties (&optional lang)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
828 "Retrieve parameters specified as properties.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
829 Return an association list of any source block params which
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
830 may be specified in the properties of the current outline entry."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
831 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
832 (let (val sym)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
833 (delq nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
834 (mapcar
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
835 (lambda (header-arg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
836 (and (setq val
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
837 (or (condition-case nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
838 (org-entry-get (point) header-arg t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
839 (error nil))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
840 (cdr (assoc header-arg org-file-properties))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
841 (cons (intern (concat ":" header-arg))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
842 (org-babel-read val))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
843 (mapcar
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
844 'symbol-name
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
845 (append
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
846 org-babel-header-arg-names
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
847 (progn
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
848 (setq sym (intern (concat "org-babel-header-arg-names:" lang)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
849 (and (boundp sym) (eval sym))))))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
850
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
851 (defun org-babel-params-from-buffer ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
852 "Retrieve per-buffer parameters.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
853 Return an association list of any source block params which
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
854 may be specified at the top of the current buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
855 (or org-babel-current-buffer-properties
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
856 (setq org-babel-current-buffer-properties
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
857 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
858 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
859 (save-restriction
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
860 (widen)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
861 (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
862 (when (re-search-forward
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
863 (org-make-options-regexp (list "BABEL")) nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
864 (org-babel-parse-header-arguments
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
865 (org-match-string-no-properties 2)))))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
866
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
867 (defvar org-src-preserve-indentation)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
868 (defun org-babel-parse-src-block-match ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
869 "Parse the results from a match of the `org-babel-src-block-regexp'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
870 (let* ((block-indentation (length (match-string 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
871 (lang (org-babel-clean-text-properties (match-string 2)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
872 (lang-headers (intern (concat "org-babel-default-header-args:" lang)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
873 (switches (match-string 3))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
874 (body (org-babel-clean-text-properties (match-string 5)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
875 (preserve-indentation (or org-src-preserve-indentation
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
876 (string-match "-i\\>" switches))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
877 (list lang
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
878 ;; get block body less properties, protective commas, and indentation
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
879 (with-temp-buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
880 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
881 (insert (org-babel-strip-protective-commas body))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
882 (unless preserve-indentation (org-do-remove-indentation))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
883 (buffer-string)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
884 (org-babel-merge-params
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
885 org-babel-default-header-args
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
886 (org-babel-params-from-buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
887 (org-babel-params-from-properties lang)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
888 (if (boundp lang-headers) (eval lang-headers) nil)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
889 (org-babel-parse-header-arguments
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
890 (org-babel-clean-text-properties (or (match-string 4) ""))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
891 switches
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
892 block-indentation)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
893
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
894 (defun org-babel-parse-inline-src-block-match ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
895 "Parse the results from a match of the `org-babel-inline-src-block-regexp'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
896 (let* ((lang (org-babel-clean-text-properties (match-string 2)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
897 (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
898 (list lang
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
899 (org-babel-strip-protective-commas
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
900 (org-babel-clean-text-properties (match-string 5)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
901 (org-babel-merge-params
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
902 org-babel-default-inline-header-args
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
903 (org-babel-params-from-buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
904 (org-babel-params-from-properties lang)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
905 (if (boundp lang-headers) (eval lang-headers) nil)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
906 (org-babel-parse-header-arguments
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
907 (org-babel-clean-text-properties (or (match-string 4) "")))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
908
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
909 (defun org-babel-parse-header-arguments (arg-string)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
910 "Parse a string of header arguments returning an alist."
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
911 (when (> (length arg-string) 0)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
912 (delq nil
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
913 (mapcar
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
914 (lambda (arg)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
915 (if (string-match
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
916 "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
917 arg)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
918 (cons (intern (match-string 1 arg))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
919 (org-babel-read (org-babel-chomp (match-string 2 arg))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
920 (cons (intern (org-babel-chomp arg)) nil)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
921 (let ((balance 0) (partial nil) (lst nil) (last 0))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
922 (mapc (lambda (ch) ; split on [] balanced instances of [ \t]:
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
923 (setq balance (+ balance
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
924 (cond ((equal 91 ch) 1)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
925 ((equal 93 ch) -1)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
926 (t 0))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
927 (setq partial (cons ch partial))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
928 (when (and (= ch 58) (= balance 0)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
929 (or (= last 32) (= last 9)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
930 (setq lst (cons (apply #'string (nreverse (cddr partial)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
931 lst))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
932 (setq partial (list ch)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
933 (setq last ch))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
934 (string-to-list arg-string))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
935 (nreverse (cons (apply #'string (nreverse partial)) lst)))))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
936
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
937 (defun org-babel-process-params (params)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
938 "Expand variables in PARAMS and add summary parameters."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
939 (let* ((vars-and-names (org-babel-disassemble-tables
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
940 (mapcar (lambda (el)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
941 (if (consp (cdr el))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
942 (cdr el) (org-babel-ref-parse (cdr el))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
943 (org-babel-get-header params :var))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
944 (cdr (assoc :hlines params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
945 (cdr (assoc :colnames params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
946 (cdr (assoc :rownames params))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
947 (result-params (append
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
948 (split-string (or (cdr (assoc :results params)) ""))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
949 (cdr (assoc :result-params params)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
950 (append
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
951 (mapcar (lambda (var) (cons :var var)) (car vars-and-names))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
952 (list
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
953 (cons :colname-names (cadr vars-and-names))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
954 (cons :rowname-names (caddr vars-and-names))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
955 (cons :result-params result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
956 (cons :result-type (cond ((member "output" result-params) 'output)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
957 ((member "value" result-params) 'value)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
958 (t 'value))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
959 (org-babel-get-header params :var 'other))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
960
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
961 ;; row and column names
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
962 (defun org-babel-del-hlines (table)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
963 "Remove all 'hlines from TABLE."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
964 (remove 'hline table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
965
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
966 (defun org-babel-get-colnames (table)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
967 "Return the column names of TABLE.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
968 Return a cons cell, the `car' of which contains the TABLE less
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
969 colnames, and the `cdr' of which contains a list of the column
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
970 names."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
971 (if (equal 'hline (nth 1 table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
972 (cons (cddr table) (car table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
973 (cons (cdr table) (car table))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
974
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
975 (defun org-babel-get-rownames (table)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
976 "Return the row names of TABLE.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
977 Return a cons cell, the `car' of which contains the TABLE less
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
978 colnames, and the `cdr' of which contains a list of the column
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
979 names. Note: this function removes any hlines in TABLE."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
980 (flet ((trans (table) (apply #'mapcar* #'list table)))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
981 (let* ((width (apply 'max
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
982 (mapcar (lambda (el) (if (listp el) (length el) 0)) table)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
983 (table (trans (mapcar (lambda (row)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
984 (if (not (equal row 'hline))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
985 row
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
986 (setq row '())
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
987 (dotimes (n width)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
988 (setq row (cons 'hline row)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
989 row))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
990 table))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
991 (cons (mapcar (lambda (row) (if (equal (car row) 'hline) 'hline row))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
992 (trans (cdr table)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
993 (remove 'hline (car table))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
994
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
995 (defun org-babel-put-colnames (table colnames)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
996 "Add COLNAMES to TABLE if they exist."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
997 (if colnames (apply 'list colnames 'hline table) table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
998
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
999 (defun org-babel-put-rownames (table rownames)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1000 "Add ROWNAMES to TABLE if they exist."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1001 (if rownames
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1002 (mapcar (lambda (row)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1003 (if (listp row)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1004 (cons (or (pop rownames) "") row)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1005 row)) table)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1006 table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1007
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1008 (defun org-babel-pick-name (names selector)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1009 "Select one out of an alist of row or column names.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1010 SELECTOR can be either a list of names in which case those names
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1011 will be returned directly, or an index into the list NAMES in
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1012 which case the indexed names will be return."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1013 (if (listp selector)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1014 selector
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1015 (when names
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1016 (if (and selector (symbolp selector) (not (equal t selector)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1017 (cdr (assoc selector names))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1018 (if (integerp selector)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1019 (nth (- selector 1) names)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1020 (cdr (car (last names))))))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1021
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1022 (defun org-babel-disassemble-tables (vars hlines colnames rownames)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1023 "Parse tables for further processing.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1024 Process the variables in VARS according to the HLINES,
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1025 ROWNAMES and COLNAMES header arguments. Return a list consisting
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1026 of the vars, cnames and rnames."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1027 (let (cnames rnames)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1028 (list
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1029 (mapcar
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1030 (lambda (var)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1031 (when (listp (cdr var))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1032 (when (and (not (equal colnames "no"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1033 (or colnames (and (equal (nth 1 (cdr var)) 'hline)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1034 (not (member 'hline (cddr (cdr var)))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1035 (let ((both (org-babel-get-colnames (cdr var))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1036 (setq cnames (cons (cons (car var) (cdr both))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1037 cnames))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1038 (setq var (cons (car var) (car both)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1039 (when (and rownames (not (equal rownames "no")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1040 (let ((both (org-babel-get-rownames (cdr var))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1041 (setq rnames (cons (cons (car var) (cdr both))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1042 rnames))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1043 (setq var (cons (car var) (car both)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1044 (when (and hlines (not (equal hlines "yes")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1045 (setq var (cons (car var) (org-babel-del-hlines (cdr var))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1046 var)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1047 vars)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1048 cnames rnames)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1049
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1050 (defun org-babel-reassemble-table (table colnames rownames)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1051 "Add column and row names to a table.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1052 Given a TABLE and set of COLNAMES and ROWNAMES add the names
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1053 to the table for reinsertion to org-mode."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1054 (if (listp table)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1055 ((lambda (table)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1056 (if (and colnames (listp (car table)) (= (length (car table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1057 (length colnames)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1058 (org-babel-put-colnames table colnames) table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1059 (if (and rownames (= (length table) (length rownames)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1060 (org-babel-put-rownames table rownames) table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1061 table))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1062
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1063 (defun org-babel-where-is-src-block-head ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1064 "Find where the current source block begins.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1065 Return the point at the beginning of the current source
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1066 block. Specifically at the beginning of the #+BEGIN_SRC line.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1067 If the point is not on a source block then return nil."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1068 (let ((initial (point)) top bottom)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1069 (or
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1070 (save-excursion ;; on a source name line
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1071 (beginning-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1072 (and (looking-at org-babel-src-name-regexp) (forward-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1073 (looking-at org-babel-src-block-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1074 (point)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1075 (save-excursion ;; on a #+begin_src line
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1076 (beginning-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1077 (and (looking-at org-babel-src-block-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1078 (point)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1079 (save-excursion ;; inside a src block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1080 (and
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1081 (re-search-backward "^[ \t]*#\\+begin_src" nil t) (setq top (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1082 (re-search-forward "^[ \t]*#\\+end_src" nil t) (setq bottom (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1083 (< top initial) (< initial bottom)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1084 (progn (goto-char top) (beginning-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1085 (looking-at org-babel-src-block-regexp))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1086 (point))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1087
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1088 ;;;###autoload
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1089 (defun org-babel-goto-src-block-head ()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1090 "Go to the beginning of the current code block."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1091 (interactive)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1092 ((lambda (head)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1093 (if head (goto-char head) (error "not currently in a code block")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1094 (org-babel-where-is-src-block-head)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1095
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1096 ;;;###autoload
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1097 (defun org-babel-goto-named-src-block (name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1098 "Go to a named source-code block."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1099 (interactive
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1100 (let ((completion-ignore-case t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1101 (list (org-icompleting-read "source-block name: "
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1102 (org-babel-src-block-names) nil t))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1103 (let ((point (org-babel-find-named-block name)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1104 (if point
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1105 ;; taken from `org-open-at-point'
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1106 (progn (goto-char point) (org-show-context))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1107 (message "source-code block '%s' not found in this buffer" name))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1108
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1109 (defun org-babel-find-named-block (name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1110 "Find a named source-code block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1111 Return the location of the source block identified by source
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1112 NAME, or nil if no such block exists. Set match data according to
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1113 org-babel-named-src-block-regexp."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1114 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1115 (let ((case-fold-search t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1116 (regexp (org-babel-named-src-block-regexp-for-name name)) msg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1117 (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1118 (when (or (re-search-forward regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1119 (re-search-backward regexp nil t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1120 (match-beginning 0)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1121
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1122 (defun org-babel-src-block-names (&optional file)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1123 "Returns the names of source blocks in FILE or the current buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1124 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1125 (when file (find-file file)) (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1126 (let (names)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1127 (while (re-search-forward org-babel-src-name-w-name-regexp nil t)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1128 (setq names (cons (org-babel-clean-text-properties (match-string 3))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1129 names)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1130 names)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1131
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1132 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1133 (defun org-babel-goto-named-result (name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1134 "Go to a named result."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1135 (interactive
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1136 (let ((completion-ignore-case t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1137 (list (org-icompleting-read "source-block name: "
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1138 (org-babel-result-names) nil t))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1139 (let ((point (org-babel-find-named-result name)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1140 (if point
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1141 ;; taken from `org-open-at-point'
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1142 (progn (goto-char point) (org-show-context))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1143 (message "result '%s' not found in this buffer" name))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1144
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1145 (defun org-babel-find-named-result (name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1146 "Find a named result.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1147 Return the location of the result named NAME in the current
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1148 buffer or nil if no such result exists."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1149 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1150 (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1151 (when (re-search-forward
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1152 (concat org-babel-result-regexp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1153 "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]") nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1154 (beginning-of-line 0) (point))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1155
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1156 (defun org-babel-result-names (&optional file)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1157 "Returns the names of results in FILE or the current buffer."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1158 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1159 (when file (find-file file)) (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1160 (let (names)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1161 (while (re-search-forward org-babel-result-w-name-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1162 (setq names (cons (org-babel-clean-text-properties (match-string 4))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1163 names)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1164 names)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1165
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1166 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1167 (defun org-babel-next-src-block (&optional arg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1168 "Jump to the next source block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1169 With optional prefix argument ARG, jump forward ARG many source blocks."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1170 (interactive "P")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1171 (when (looking-at org-babel-src-block-regexp) (forward-char 1))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1172 (condition-case nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1173 (re-search-forward org-babel-src-block-regexp nil nil (or arg 1))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1174 (error (error "No further code blocks")))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1175 (goto-char (match-beginning 0)) (org-show-context))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1176
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1177 ;;;###autoload
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1178 (defun org-babel-previous-src-block (&optional arg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1179 "Jump to the previous source block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1180 With optional prefix argument ARG, jump backward ARG many source blocks."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1181 (interactive "P")
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1182 (condition-case nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1183 (re-search-backward org-babel-src-block-regexp nil nil (or arg 1))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1184 (error (error "No previous code blocks")))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1185 (goto-char (match-beginning 0)) (org-show-context))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1186
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1187 (defvar org-babel-load-languages)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1188
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1189 ;;;###autoload
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1190 (defun org-babel-mark-block ()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1191 "Mark current src block"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1192 (interactive)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1193 ((lambda (head)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1194 (when head
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1195 (save-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1196 (goto-char head)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1197 (looking-at org-babel-src-block-regexp))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1198 (push-mark (match-end 5) nil t)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1199 (goto-char (match-beginning 5))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1200 (org-babel-where-is-src-block-head)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1201
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1202 (defun org-babel-demarcate-block (&optional arg)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1203 "Wrap or split the code in the region or on the point.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1204 When called from inside of a code block the current block is
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1205 split. When called from outside of a code block a new code block
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1206 is created. In both cases if the region is demarcated and if the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1207 region is not active then the point is demarcated."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1208 (interactive "P")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1209 (let ((info (org-babel-get-src-block-info 'light))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1210 (stars (concat (make-string (or (org-current-level) 1) ?*) " ")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1211 (if info
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1212 (mapc
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1213 (lambda (place)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1214 (save-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1215 (goto-char place)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1216 (let ((lang (nth 0 info))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1217 (indent (make-string (nth 5 info) ? )))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1218 (when (string-match "^[[:space:]]*$"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1219 (buffer-substring (point-at-bol)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1220 (point-at-eol)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1221 (delete-region (point-at-bol) (point-at-eol)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1222 (insert (concat (if (looking-at "^") "" "\n")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1223 indent "#+end_src\n"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1224 (if arg stars indent) "\n"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1225 indent "#+begin_src " lang
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1226 (if (looking-at "[\n\r]") "" "\n")))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1227 (move-end-of-line 2))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1228 (sort (if (region-active-p) (list (mark) (point)) (list (point))) #'>))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1229 (let ((start (point))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1230 (lang (org-icompleting-read "Lang: "
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1231 (mapcar (lambda (el) (symbol-name (car el)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1232 org-babel-load-languages)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1233 (body (delete-and-extract-region
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1234 (if (region-active-p) (mark) (point)) (point))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1235 (insert (concat (if (looking-at "^") "" "\n")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1236 (if arg (concat stars "\n") "")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1237 "#+begin_src " lang "\n"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1238 body
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1239 (if (or (= (length body) 0)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1240 (string-match "[\r\n]$" body)) "" "\n")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1241 "#+end_src\n"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1242 (goto-char start) (move-end-of-line 1)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1243
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1244 (defvar org-babel-lob-one-liner-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1245 (defun org-babel-where-is-src-block-result (&optional insert info hash indent)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1246 "Find where the current source block results begin.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1247 Return the point at the beginning of the result of the current
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1248 source block. Specifically at the beginning of the results line.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1249 If no result exists for this block then create a results line
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1250 following the source block."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1251 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1252 (let* ((on-lob-line (progn (beginning-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1253 (looking-at org-babel-lob-one-liner-regexp)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1254 (name (if on-lob-line
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1255 (nth 0 (org-babel-lob-get-info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1256 (nth 4 (or info (org-babel-get-src-block-info)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1257 (head (unless on-lob-line (org-babel-where-is-src-block-head)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1258 found beg end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1259 (when head (goto-char head))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1260 (setq
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1261 found ;; was there a result (before we potentially insert one)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1262 (or
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1263 (and
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1264 ;; named results:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1265 ;; - return t if it is found, else return nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1266 ;; - if it does not need to be rebuilt, then don't set end
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1267 ;; - if it does need to be rebuilt then do set end
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1268 name (setq beg (org-babel-find-named-result name))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1269 (prog1 beg
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1270 (when (and hash (not (string= hash (match-string 3))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1271 (goto-char beg) (setq end beg) ;; beginning of result
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1272 (forward-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1273 (delete-region end (org-babel-result-end)) nil)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1274 (and
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1275 ;; unnamed results:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1276 ;; - return t if it is found, else return nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1277 ;; - if it is found, and the hash doesn't match, delete and set end
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1278 (or on-lob-line (re-search-forward "^[ \t]*#\\+end_src" nil t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1279 (progn (end-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1280 (if (eobp) (insert "\n") (forward-char 1))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1281 (setq end (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1282 (or (and (not name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1283 (progn ;; unnamed results line already exists
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1284 (re-search-forward "[^ \f\t\n\r\v]" nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1285 (beginning-of-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1286 (looking-at
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1287 (concat org-babel-result-regexp "\n")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1288 (prog1 (point)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1289 ;; must remove and rebuild if hash!=old-hash
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1290 (if (and hash (not (string= hash (match-string 3))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1291 (prog1 nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1292 (forward-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1293 (delete-region
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1294 end (org-babel-result-end)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1295 (setq end nil)))))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1296 (if (and insert end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1297 (progn
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1298 (goto-char end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1299 (unless beg
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1300 (if (looking-at "[\n\r]") (forward-char 1) (insert "\n")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1301 (insert (concat
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1302 (if indent
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1303 (mapconcat
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1304 (lambda (el) " ")
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1305 (org-number-sequence 1 indent) "")
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1306 "")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1307 "#+results"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1308 (when hash (concat "["hash"]"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1309 ":"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1310 (when name (concat " " name)) "\n"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1311 (unless beg (insert "\n") (backward-char))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1312 (beginning-of-line 0)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1313 (if hash (org-babel-hide-hash))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1314 (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1315 found))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1316
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1317 (defvar org-block-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1318 (defun org-babel-read-result ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1319 "Read the result at `point' into emacs-lisp."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1320 (let ((case-fold-search t) result-string)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1321 (cond
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1322 ((org-at-table-p) (org-babel-read-table))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1323 ((org-in-item-p) (org-babel-read-list))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1324 ((looking-at org-bracket-link-regexp) (org-babel-read-link))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1325 ((looking-at org-block-regexp) (org-babel-trim (match-string 4)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1326 ((looking-at "^[ \t]*: ")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1327 (setq result-string
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1328 (org-babel-trim
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1329 (mapconcat (lambda (line)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1330 (if (and (> (length line) 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1331 (string-match "^[ \t]*: \\(.+\\)" line))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1332 (match-string 1 line)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1333 line))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1334 (split-string
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1335 (buffer-substring
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1336 (point) (org-babel-result-end)) "[\r\n]+")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1337 "\n")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1338 (or (org-babel-number-p result-string) result-string))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1339 ((looking-at org-babel-result-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1340 (save-excursion (forward-line 1) (org-babel-read-result))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1341
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1342 (defun org-babel-read-table ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1343 "Read the table at `point' into emacs-lisp."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1344 (mapcar (lambda (row)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1345 (if (and (symbolp row) (equal row 'hline)) row
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1346 (mapcar #'org-babel-read row)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1347 (org-table-to-lisp)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1348
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1349 (defun org-babel-read-list ()
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1350 "Read the list at `point' into emacs-lisp."
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1351 (mapcar #'org-babel-read (cdr (org-list-parse-list))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1352
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1353 (defvar org-link-types-re)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1354 (defun org-babel-read-link ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1355 "Read the link at `point' into emacs-lisp.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1356 If the path of the link is a file path it is expanded using
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1357 `expand-file-name'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1358 (let* ((case-fold-search t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1359 (raw (and (looking-at org-bracket-link-regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1360 (org-babel-clean-text-properties (match-string 1))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1361 (type (and (string-match org-link-types-re raw)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1362 (match-string 1 raw))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1363 (cond
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1364 ((not type) (expand-file-name raw))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1365 ((string= type "file")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1366 (and (string-match "file\\(.*\\):\\(.+\\)" raw)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1367 (expand-file-name (match-string 2 raw))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1368 (t raw))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1369
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1370 (defun org-babel-insert-result
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1371 (result &optional result-params info hash indent lang)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1372 "Insert RESULT into the current buffer.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1373 By default RESULT is inserted after the end of the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1374 current source block. With optional argument RESULT-PARAMS
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1375 controls insertion of results in the org-mode file.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1376 RESULT-PARAMS can take the following values...
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1377
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1378 replace - (default option) insert results after the source block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1379 replacing any previously inserted results
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1380
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1381 silent -- no results are inserted
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1382
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1383 file ---- the results are interpreted as a file path, and are
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1384 inserted into the buffer using the Org-mode file syntax
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1385
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1386 list ---- the results are interpreted as an Org-mode list.
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1387
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1388 raw ----- results are added directly to the Org-mode file. This
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1389 is a good option if you code block will output org-mode
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1390 formatted text.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1391
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1392 org ----- similar in effect to raw, only the results are wrapped
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1393 in an org code block. Similar to the raw option, on
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1394 export the results will be interpreted as org-formatted
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1395 text, however by wrapping the results in an org code
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1396 block they can be replaced upon re-execution of the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1397 code block.
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1398
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1399 html ---- results are added inside of a #+BEGIN_HTML block. This
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1400 is a good option if you code block will output html
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1401 formatted text.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1402
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1403 latex --- results are added inside of a #+BEGIN_LATEX block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1404 This is a good option if you code block will output
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1405 latex formatted text.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1406
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1407 code ---- the results are extracted in the syntax of the source
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1408 code of the language being evaluated and are added
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1409 inside of a #+BEGIN_SRC block with the source-code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1410 language set appropriately. Note this relies on the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1411 optional LANG argument."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1412 (if (stringp result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1413 (progn
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1414 (setq result (org-babel-clean-text-properties result))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1415 (when (member "file" result-params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1416 (setq result (org-babel-result-to-file result))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1417 (unless (listp result) (setq result (format "%S" result))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1418 (if (and result-params (member "silent" result-params))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1419 (progn
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1420 (message (replace-regexp-in-string "%" "%%" (format "%S" result)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1421 result)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1422 (when (and (stringp result) ;; ensure results end in a newline
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1423 (> (length result) 0)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1424 (not (or (string-equal (substring result -1) "\n")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1425 (string-equal (substring result -1) "\r"))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1426 (setq result (concat result "\n")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1427 (save-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1428 (let ((existing-result (org-babel-where-is-src-block-result
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1429 t info hash indent))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1430 (results-switches
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1431 (cdr (assoc :results_switches (nth 2 info))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1432 beg end)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1433 (if (not existing-result)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1434 (setq beg (point))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1435 (goto-char existing-result)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1436 (save-excursion
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1437 (re-search-forward "#" nil t)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1438 (setq indent (- (current-column) 1)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1439 (forward-line 1)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1440 (setq beg (point))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1441 (cond
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1442 ((member "replace" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1443 (delete-region (point) (org-babel-result-end)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1444 ((member "append" result-params)
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1445 (goto-char (org-babel-result-end)) (setq beg (point-marker)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1446 ((member "prepend" result-params)))) ; already there
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1447 (setq results-switches
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1448 (if results-switches (concat " " results-switches) ""))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1449 ;; insert results based on type
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1450 (cond
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1451 ;; do nothing for an empty result
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1452 ((= (length result) 0))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1453 ;; insert a list if preferred
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1454 ((member "list" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1455 (insert
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1456 (org-babel-trim
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1457 (org-list-to-generic (cons 'unordered
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1458 (if (listp result) result (list result)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1459 '(:splicep nil :istart "- " :iend "\n")))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1460 ;; assume the result is a table if it's not a string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1461 ((not (stringp result))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1462 (goto-char beg)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1463 (insert (concat (orgtbl-to-orgtbl
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1464 (if (or (eq 'hline (car result))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1465 (and (listp (car result))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1466 (listp (cdr (car result)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1467 result (list result))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1468 '(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1469 (goto-char beg) (when (org-at-table-p) (org-table-align)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1470 ((member "file" result-params)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1471 (insert result))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1472 (t (goto-char beg) (insert result)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1473 (when (listp result) (goto-char (org-table-end)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1474 (setq end (point-marker))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1475 ;; possibly wrap result
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1476 (flet ((wrap (start finish)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1477 (goto-char beg) (insert start)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1478 (goto-char end) (insert finish)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1479 (setq end (point-marker))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1480 (cond
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1481 ((member "html" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1482 (wrap "#+BEGIN_HTML\n" "#+END_HTML"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1483 ((member "latex" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1484 (wrap "#+BEGIN_LaTeX\n" "#+END_LaTeX"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1485 ((member "code" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1486 (wrap (format "#+BEGIN_SRC %s%s\n" (or lang "none") results-switches)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1487 "#+END_SRC"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1488 ((member "org" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1489 (wrap "#+BEGIN_ORG\n" "#+END_ORG"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1490 ((member "raw" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1491 (goto-char beg) (if (org-at-table-p) (org-cycle)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1492 ((member "wrap" result-params)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1493 (when (and (stringp result) (not (member "file" result-params)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1494 (org-babel-examplize-region beg end results-switches))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1495 (wrap "#+BEGIN_RESULT\n" "#+END_RESULT"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1496 ((and (stringp result) (not (member "file" result-params)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1497 (org-babel-examplize-region beg end results-switches)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1498 (setq end (point)))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1499 ;; possibly indent the results to match the #+results line
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1500 (when (and indent (> indent 0)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1501 ;; in this case `table-align' does the work for us
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1502 (not (and (listp result)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1503 (member "append" result-params))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1504 (indent-rigidly beg end indent))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1505 (if (= (length result) 0)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1506 (if (member "value" result-params)
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1507 (message "Code block returned no value.")
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1508 (message "Code block produced no output."))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1509 (message "Code block evaluation complete."))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1510
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1511 (defun org-babel-remove-result (&optional info)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1512 "Remove the result of the current source block."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1513 (interactive)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1514 (let ((location (org-babel-where-is-src-block-result nil info)) start)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1515 (when location
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1516 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1517 (goto-char location) (setq start (point)) (forward-line 1)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1518 (delete-region start (org-babel-result-end))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1519
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1520 (defun org-babel-result-end ()
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1521 "Return the point at the end of the current set of results"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1522 (save-excursion
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1523 (cond
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1524 ((org-at-table-p) (progn (goto-char (org-table-end)) (point)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1525 ((org-in-item-p) (- (org-list-bottom-point) 1))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1526 (t
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1527 (let ((case-fold-search t)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1528 (blocks-re (regexp-opt
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1529 (list "latex" "html" "example" "src" "result"))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1530 (if (looking-at (concat "[ \t]*#\\+begin_" blocks-re))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1531 (re-search-forward (concat "[ \t]*#\\+end_" blocks-re) nil t)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1532 (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1533 (forward-line 1))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1534 (point)))))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1535
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1536 (defun org-babel-result-to-file (result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1537 "Convert RESULT into an `org-mode' link.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1538 If the `default-directory' is different from the containing
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1539 file's directory then expand relative links."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1540 (format
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1541 "[[file:%s]]"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1542 (if (and default-directory
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1543 buffer-file-name
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1544 (not (string= (expand-file-name default-directory)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1545 (expand-file-name
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1546 (file-name-directory buffer-file-name)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1547 (expand-file-name result default-directory)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1548 result)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1549
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1550 (defun org-babel-examplize-region (beg end &optional results-switches)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1551 "Comment out region using the ': ' org example quote."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1552 (interactive "*r")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1553 (let ((size (count-lines beg end)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1554 (save-excursion
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1555 (cond ((= size 0)) ; do nothing for an empty result
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1556 ((< size org-babel-min-lines-for-block-output)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1557 (goto-char beg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1558 (dotimes (n size)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1559 (beginning-of-line 1) (insert ": ") (forward-line 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1560 (t
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1561 (goto-char beg)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1562 (insert (if results-switches
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1563 (format "#+begin_example%s\n" results-switches)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1564 "#+begin_example\n"))
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1565 (if (markerp end) (goto-char end) (forward-char (- end beg)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1566 (insert "#+end_example\n"))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1567
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1568 (defun org-babel-update-block-body (new-body)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1569 "Update the body of the current code block to NEW-BODY."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1570 (if (not (org-babel-where-is-src-block-head))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1571 (error "not in source block")
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1572 (save-match-data
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1573 (replace-match (concat (org-babel-trim new-body) "\n") nil nil nil 5))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1574 (indent-rigidly (match-beginning 5) (match-end 5) 2)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1575
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1576 (defun org-babel-merge-params (&rest plists)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1577 "Combine all parameter association lists in PLISTS.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1578 Later elements of PLISTS override the values of previous element.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1579 This takes into account some special considerations for certain
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1580 parameters when merging lists."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1581 (let ((results-exclusive-groups
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1582 '(("file" "list" "vector" "table" "scalar" "raw" "org"
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1583 "html" "latex" "code" "pp" "wrap")
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1584 ("replace" "silent" "append" "prepend")
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1585 ("output" "value")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1586 (exports-exclusive-groups
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1587 '(("code" "results" "both" "none")))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1588 params results exports tangle noweb cache vars shebang comments)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1589 (flet ((e-merge (exclusive-groups &rest result-params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1590 ;; maintain exclusivity of mutually exclusive parameters
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1591 (let (output)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1592 (mapc (lambda (new-params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1593 (mapc (lambda (new-param)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1594 (mapc (lambda (exclusive-group)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1595 (when (member new-param exclusive-group)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1596 (mapcar (lambda (excluded-param)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1597 (setq output
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1598 (delete
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1599 excluded-param
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1600 output)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1601 exclusive-group)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1602 exclusive-groups)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1603 (setq output (org-uniquify
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1604 (cons new-param output))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1605 new-params))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1606 result-params)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1607 output)))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1608 (mapc
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1609 (lambda (plist)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1610 (mapc
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1611 (lambda (pair)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1612 (case (car pair)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1613 (:var
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1614 (let ((name (if (listp (cdr pair))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1615 (cadr pair)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1616 (and (string-match "^\\([^= \f\t\n\r\v]+\\)[ \t]*="
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1617 (cdr pair))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1618 (intern (match-string 1 (cdr pair)))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1619 (when name
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1620 (setq vars
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1621 (cons (cons name pair)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1622 (if (member name (mapcar #'car vars))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1623 (delq nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1624 (mapcar
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1625 (lambda (p) (unless (equal (car p) name) p))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1626 vars))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1627 vars))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1628 (:results
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1629 (setq results (e-merge results-exclusive-groups
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1630 results (split-string (cdr pair)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1631 (:file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1632 (when (cdr pair)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1633 (setq results (e-merge results-exclusive-groups
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1634 results '("file")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1635 (unless (or (member "both" exports)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1636 (member "none" exports)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1637 (member "code" exports))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1638 (setq exports (e-merge exports-exclusive-groups
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1639 exports '("results"))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1640 (setq params (cons pair (assq-delete-all (car pair) params)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1641 (:exports
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1642 (setq exports (e-merge exports-exclusive-groups
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1643 exports (split-string (cdr pair)))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1644 (:tangle ;; take the latest -- always overwrite
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1645 (setq tangle (or (list (cdr pair)) tangle)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1646 (:noweb
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1647 (setq noweb (e-merge '(("yes" "no" "tangle")) noweb
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1648 (split-string (or (cdr pair) "")))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1649 (:cache
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1650 (setq cache (e-merge '(("yes" "no")) cache
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1651 (split-string (or (cdr pair) "")))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1652 (:shebang ;; take the latest -- always overwrite
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1653 (setq shebang (or (list (cdr pair)) shebang)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1654 (:comments
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1655 (setq comments (e-merge '(("yes" "no")) comments
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1656 (split-string (or (cdr pair) "")))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1657 (t ;; replace: this covers e.g. :session
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1658 (setq params (cons pair (assq-delete-all (car pair) params))))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1659 plist))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1660 plists))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1661 (while vars (setq params (cons (cons :var (cddr (pop vars))) params)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1662 (cons (cons :comments (mapconcat 'identity comments " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1663 (cons (cons :shebang (mapconcat 'identity shebang " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1664 (cons (cons :cache (mapconcat 'identity cache " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1665 (cons (cons :noweb (mapconcat 'identity noweb " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1666 (cons (cons :tangle (mapconcat 'identity tangle " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1667 (cons (cons :exports
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1668 (mapconcat 'identity exports " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1669 (cons
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1670 (cons :results
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1671 (mapconcat 'identity results " "))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1672 params)))))))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1673
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1674 (defun org-babel-expand-noweb-references (&optional info parent-buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1675 "Expand Noweb references in the body of the current source code block.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1676
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1677 For example the following reference would be replaced with the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1678 body of the source-code block named 'example-block'.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1679
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1680 <<example-block>>
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1681
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1682 Note that any text preceding the <<foo>> construct on a line will
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1683 be interposed between the lines of the replacement text. So for
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1684 example if <<foo>> is placed behind a comment, then the entire
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1685 replacement text will also be commented.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1686
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1687 This function must be called from inside of the buffer containing
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1688 the source-code block which holds BODY.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1689
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1690 In addition the following syntax can be used to insert the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1691 results of evaluating the source-code block named 'example-block'.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1692
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1693 <<example-block()>>
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1694
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1695 Any optional arguments can be passed to example-block by placing
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1696 the arguments inside the parenthesis following the convention
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1697 defined by `org-babel-lob'. For example
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1698
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1699 <<example-block(a=9)>>
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1700
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1701 would set the value of argument \"a\" equal to \"9\". Note that
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1702 these arguments are not evaluated in the current source-code
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1703 block but are passed literally to the \"example-block\"."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1704 (let* ((parent-buffer (or parent-buffer (current-buffer)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1705 (info (or info (org-babel-get-src-block-info)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1706 (lang (nth 0 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1707 (body (nth 1 info))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1708 (new-body "") index source-name evaluate prefix)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1709 (flet ((nb-add (text)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1710 (setq new-body (concat new-body text))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1711 (with-temp-buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1712 (insert body) (goto-char (point-min))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1713 (setq index (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1714 (while (and (re-search-forward "<<\\(.+?\\)>>" nil t))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1715 (save-match-data (setf source-name (match-string 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1716 (save-match-data (setq evaluate (string-match "\(.*\)" source-name)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1717 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1718 (setq prefix
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1719 (buffer-substring (match-beginning 0)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1720 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1721 (beginning-of-line 1) (point)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1722 ;; add interval to new-body (removing noweb reference)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1723 (goto-char (match-beginning 0))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1724 (nb-add (buffer-substring index (point)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1725 (goto-char (match-end 0))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1726 (setq index (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1727 (nb-add (with-current-buffer parent-buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1728 (mapconcat ;; interpose PREFIX between every line
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1729 #'identity
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1730 (split-string
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1731 (if evaluate
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1732 (let ((raw (org-babel-ref-resolve source-name)))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1733 (if (stringp raw) raw (format "%S" raw)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1734 (save-restriction
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1735 (widen)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1736 (let ((point (org-babel-find-named-block
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1737 source-name)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1738 (if point
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1739 (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1740 (goto-char point)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1741 (org-babel-trim
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1742 (org-babel-expand-noweb-references
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1743 (org-babel-get-src-block-info))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1744 ;; optionally raise an error if named
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1745 ;; source-block doesn't exist
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1746 (if (member lang org-babel-noweb-error-langs)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1747 (error "%s"
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1748 (concat
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1749 "<<" source-name ">> "
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1750 "could not be resolved (see "
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1751 "`org-babel-noweb-error-langs')"))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1752 "")))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1753 "[\n\r]") (concat "\n" prefix)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1754 (nb-add (buffer-substring index (point-max)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1755 new-body))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1756
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1757 (defun org-babel-clean-text-properties (text)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1758 "Strip all properties from text return."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1759 (when text
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1760 (set-text-properties 0 (length text) nil text) text))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1761
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1762 (defun org-babel-strip-protective-commas (body)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1763 "Strip protective commas from bodies of source blocks."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1764 (replace-regexp-in-string "^,#" "#" body))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1765
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1766 (defun org-babel-script-escape (str)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1767 "Safely convert tables into elisp lists."
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1768 (let (in-single in-double out)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1769 (org-babel-read
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1770 (if (and (stringp str) (string-match "^\\[.+\\]$" str))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1771 (org-babel-read
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1772 (concat
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1773 "'"
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1774 (progn
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1775 (mapc
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1776 (lambda (ch)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1777 (setq
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1778 out
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1779 (case ch
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1780 (91 (if (or in-double in-single) ; [
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1781 (cons 91 out)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1782 (cons 40 out)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1783 (93 (if (or in-double in-single) ; ]
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1784 (cons 93 out)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1785 (cons 41 out)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1786 (44 (if (or in-double in-single) (cons 44 out) out)) ; ,
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1787 (39 (if in-double ; '
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1788 (cons 39 out)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1789 (setq in-single (not in-single)) (cons 34 out)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1790 (34 (if in-single ; "
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1791 (append (list 34 32) out)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1792 (setq in-double (not in-double)) (cons 34 out)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1793 (t (cons ch out)))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1794 (string-to-list str))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1795 (apply #'string (reverse out)))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1796 str))))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1797
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1798 (defun org-babel-read (cell)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1799 "Convert the string value of CELL to a number if appropriate.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1800 Otherwise if cell looks like lisp (meaning it starts with a
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1801 \"(\" or a \"'\") then read it as lisp, otherwise return it
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1802 unmodified as a string.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1803
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1804 This is taken almost directly from `org-read-prop'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1805 (if (and (stringp cell) (not (equal cell "")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1806 (or (org-babel-number-p cell)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1807 (if (or (equal "(" (substring cell 0 1))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1808 (equal "'" (substring cell 0 1))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1809 (equal "`" (substring cell 0 1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1810 (eval (read cell))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1811 (progn (set-text-properties 0 (length cell) nil cell) cell)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1812 cell))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1813
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1814 (defun org-babel-number-p (string)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1815 "If STRING represents a number return it's value."
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1816 (if (and (string-match "^-?[0-9]*\\.?[0-9]*$" string)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1817 (= (length (substring string (match-beginning 0)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1818 (match-end 0)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1819 (length string)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1820 (string-to-number string)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1821
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1822 (defun org-babel-import-elisp-from-file (file-name &optional separator)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1823 "Read the results located at FILE-NAME into an elisp table.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1824 If the table is trivial, then return it as a scalar."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1825 (let (result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1826 (save-window-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1827 (with-temp-buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1828 (condition-case nil
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1829 (progn
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1830 (org-table-import file-name separator)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1831 (delete-file file-name)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1832 (setq result (mapcar (lambda (row)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1833 (mapcar #'org-babel-string-read row))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1834 (org-table-to-lisp))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1835 (error nil)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1836 (if (null (cdr result)) ;; if result is trivial vector, then scalarize it
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1837 (if (consp (car result))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1838 (if (null (cdr (car result)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1839 (caar result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1840 result)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1841 (car result))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1842 result))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1843
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1844 (defun org-babel-string-read (cell)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1845 "Strip nested \"s from around strings."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1846 (org-babel-read (or (and (stringp cell)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1847 (string-match "\\\"\\(.+\\)\\\"" cell)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1848 (match-string 1 cell))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1849 cell)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1850
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1851 (defun org-babel-reverse-string (string)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1852 "Return the reverse of STRING."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1853 (apply 'string (reverse (string-to-list string))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1854
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1855 (defun org-babel-chomp (string &optional regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1856 "Strip trailing spaces and carriage returns from STRING.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1857 Default regexp used is \"[ \f\t\n\r\v]\" but can be
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1858 overwritten by specifying a regexp as a second argument."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1859 (let ((regexp (or regexp "[ \f\t\n\r\v]")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1860 (while (and (> (length string) 0)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1861 (string-match regexp (substring string -1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1862 (setq string (substring string 0 -1)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1863 string))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1864
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1865 (defun org-babel-trim (string &optional regexp)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1866 "Strip leading and trailing spaces and carriage returns from STRING.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1867 Like `org-babel-chomp' only it runs on both the front and back
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1868 of the string."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1869 (org-babel-chomp (org-babel-reverse-string
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1870 (org-babel-chomp (org-babel-reverse-string string) regexp))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1871 regexp))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1872
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1873 (defvar org-babel-org-babel-call-process-region-original nil)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1874 (defun org-babel-tramp-handle-call-process-region
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1875 (start end program &optional delete buffer display &rest args)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1876 "Use tramp to handle call-process-region.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1877 Fixes a bug in `tramp-handle-call-process-region'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1878 (if (and (featurep 'tramp) (file-remote-p default-directory))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1879 (let ((tmpfile (tramp-compat-make-temp-file "")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1880 (write-region start end tmpfile)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1881 (when delete (delete-region start end))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1882 (unwind-protect
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1883 ;; (apply 'call-process program tmpfile buffer display args)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1884 ;; bug in tramp
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1885 (apply 'process-file program tmpfile buffer display args)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1886 (delete-file tmpfile)))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1887 ;; org-babel-call-process-region-original is the original emacs
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1888 ;; definition. It is in scope from the let binding in
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1889 ;; org-babel-execute-src-block
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1890 (apply org-babel-call-process-region-original
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1891 start end program delete buffer display args)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1892
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1893 (defun org-babel-local-file-name (file)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1894 "Return the local name component of FILE."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1895 (if (file-remote-p file)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1896 (let (localname)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1897 (with-parsed-tramp-file-name file nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1898 localname))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1899 file))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1900
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1901 (defun org-babel-process-file-name (name &optional no-quote-p)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1902 "Prepare NAME to be used in an external process.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1903 If NAME specifies a remote location, the remote portion of the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1904 name is removed, since in that case the process will be executing
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1905 remotely. The file name is then processed by
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1906 `expand-file-name'. Unless second argument NO-QUOTE-P is non-nil,
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1907 the file name is additionally processed by
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1908 `shell-quote-argument'"
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1909 ((lambda (f) (if no-quote-p f (shell-quote-argument f)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1910 (expand-file-name (org-babel-local-file-name name))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1911
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1912 (defvar org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1913 (unless (or noninteractive (boundp 'org-babel-temporary-directory))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1914 (defvar org-babel-temporary-directory
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1915 (or (and (boundp 'org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1916 (file-exists-p org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1917 org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1918 (make-temp-file "babel-" t))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1919 "Directory to hold temporary files created to execute code blocks.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1920 Used by `org-babel-temp-file'. This directory will be removed on
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1921 Emacs shutdown."))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1922
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1923 (defun org-babel-temp-file (prefix &optional suffix)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1924 "Create a temporary file in the `org-babel-temporary-directory'.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1925 Passes PREFIX and SUFFIX directly to `make-temp-file' with the
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1926 value of `temporary-file-directory' temporarily set to the value
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1927 of `org-babel-temporary-directory'."
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1928 (if (file-remote-p default-directory)
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1929 (make-temp-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1930 (concat (file-remote-p default-directory)
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1931 (expand-file-name
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1932 prefix temporary-file-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1933 nil suffix))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1934 (let ((temporary-file-directory
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1935 (or (and (file-exists-p org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1936 org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1937 temporary-file-directory)))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1938 (make-temp-file prefix nil suffix))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1939
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1940 (defun org-babel-remove-temporary-directory ()
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1941 "Remove `org-babel-temporary-directory' on Emacs shutdown."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1942 (when (and (boundp 'org-babel-temporary-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1943 (file-exists-p org-babel-temporary-directory))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1944 ;; taken from `delete-directory' in files.el
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1945 (condition-case nil
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1946 (progn
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1947 (mapc (lambda (file)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1948 ;; This test is equivalent to
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1949 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1950 ;; but more efficient
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1951 (if (eq t (car (file-attributes file)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1952 (delete-directory file)
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1953 (delete-file file)))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1954 ;; We do not want to delete "." and "..".
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1955 (directory-files org-babel-temporary-directory 'full
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1956 "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1957 (delete-directory org-babel-temporary-directory))
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1958 (error
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1959 (message "Failed to remove temporary Org-babel directory %s"
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111521
diff changeset
1960 org-babel-temporary-directory)))))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1961
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109847
diff changeset
1962 (add-hook 'kill-emacs-hook 'org-babel-remove-temporary-directory)
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1963
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1964 (provide 'ob)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1965
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1966 ;; arch-tag: 01a7ebee-06c5-4ee4-a709-e660d28c0af1
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1967
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1968 ;;; ob.el ends here