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