From 32bbd3f3bb1bead35b6ce00ecb2cd75cbf869d08 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 22 Mar 2010 08:49:35 -0600 Subject: [PATCH 1/2] babel: variable references which look like lisp forms are now evaluated for example, the following simple example #+begin_src emacs-lisp :var two=(+ 1 1) (sqrt two) #+end_src #+results: : 1.4142135623730951 Or this more interesting usage, which pulls variable values from headline properties *** example headline w/property :PROPERTIES: :special: 89 :last-name: schulte :END: #+begin_src emacs-lisp :var special=(string-to-number (org-entry-get nil "special" t)) (+ special 1) #+end_src #+results: : 90 #+begin_src emacs-lisp :var last-name=(org-entry-get nil "last-name" t)) (message "hello %s" last-name) #+end_src #+results: : hello schulte --- contrib/babel/lisp/org-babel.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el index d01e6d6f7..f7c0941ae 100644 --- a/contrib/babel/lisp/org-babel.el +++ b/contrib/babel/lisp/org-babel.el @@ -1057,7 +1057,7 @@ This is taken almost directly from `org-read-prop'." (or (org-babel-number-p cell) (if (or (equal "(" (substring cell 0 1)) (equal "'" (substring cell 0 1))) - (read cell) + (eval (read cell)) (progn (set-text-properties 0 (length cell) nil cell) cell))) cell)) From 727aa263cb96fa3eff8daac0266f518c2c8c0551 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 22 Mar 2010 11:09:37 -0600 Subject: [PATCH 2/2] babel: src block regexps are more robust to embedded "[begin|end]_src" in block body --- contrib/babel/lisp/org-babel.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el index f7c0941ae..767fb588b 100644 --- a/contrib/babel/lisp/org-babel.el +++ b/contrib/babel/lisp/org-babel.el @@ -139,7 +139,7 @@ can not be resolved.") "\\)[ \t]*" "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)" ;; (2) switches "\\([^\n]*\\)\n" ;; (3) header arguments - "\\([^\000]+?\\)#\\+end_src")) ;; (4) body + "\\([^\000]+?\n\\)[ \t]*#\\+end_src"));; (4) body (setq org-babel-inline-src-block-regexp (concat "[ \f\t\n\r\v]\\(src_" ;; (1) replacement target "\\(" ;; (2) lang @@ -605,8 +605,8 @@ If the point is not on a source block then return nil." (point))) (save-excursion ;; inside a src block (and - (re-search-backward "#\\+begin_src" nil t) (setq top (point)) - (re-search-forward "#\\+end_src" nil t) (setq bottom (point)) + (re-search-backward "^[ \t]*#\\+begin_src" nil t) (setq top (point)) + (re-search-forward "^[ \t]*#\\+end_src" nil t) (setq bottom (point)) (< top initial) (< initial bottom) (goto-char top) (move-beginning-of-line 1) (looking-at org-babel-src-block-regexp) @@ -656,7 +656,7 @@ following the source block." (head (unless on-lob-line (org-babel-where-is-src-block-head))) end) (when head (goto-char head)) (or (and name (org-babel-find-named-result name)) - (and (or on-lob-line (re-search-forward "#\\+end_src" nil t)) + (and (or on-lob-line (re-search-forward "^[ \t]*#\\+end_src" nil t)) (progn (move-end-of-line 1) (if (eobp) (insert "\n") (forward-char 1)) (setq end (point))