From: Eric Schulte Date: Sun, 8 Sep 2013 10:41:05 +0000 (-0600) Subject: condition code execution by org-element-context X-Git-Tag: release_8.1.2~21 X-Git-Url: https://repo.or.cz/w/org-mode.git/commitdiff_plain/9a3d30626e66f03b750cffc27c691b7cd1199761 condition code execution by org-element-context Thanks to Nicolas Goaziou for suggesting this change. --- diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 8fa0c1345..d57806bc6 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -938,6 +938,10 @@ evaluation mechanisms." (defvar org-bracket-link-regexp) +(defun org-babel-active-location-p () + (memq (car (save-match-data (org-element-context))) + '(babel-call inline-babel-call inline-src-block src-block))) + ;;;###autoload (defun org-babel-open-src-block-result (&optional re-run) "If `point' is on a src block then open the results of the @@ -998,24 +1002,25 @@ end-body --------- point at the end of the body" (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-src-block-regexp nil t) - (goto-char (match-beginning 0)) - (let ((full-block (match-string 0)) - (beg-block (match-beginning 0)) - (end-block (match-end 0)) - (lang (match-string 2)) - (beg-lang (match-beginning 2)) - (end-lang (match-end 2)) - (switches (match-string 3)) - (beg-switches (match-beginning 3)) - (end-switches (match-end 3)) - (header-args (match-string 4)) - (beg-header-args (match-beginning 4)) - (end-header-args (match-end 4)) - (body (match-string 5)) - (beg-body (match-beginning 5)) - (end-body (match-end 5))) - ,@body - (goto-char end-block)))) + (when (org-babel-active-location-p) + (goto-char (match-beginning 0)) + (let ((full-block (match-string 0)) + (beg-block (match-beginning 0)) + (end-block (match-end 0)) + (lang (match-string 2)) + (beg-lang (match-beginning 2)) + (end-lang (match-end 2)) + (switches (match-string 3)) + (beg-switches (match-beginning 3)) + (end-switches (match-end 3)) + (header-args (match-string 4)) + (beg-header-args (match-beginning 4)) + (end-header-args (match-end 4)) + (body (match-string 5)) + (beg-body (match-beginning 5)) + (end-body (match-end 5))) + ,@body + (goto-char end-block))))) (unless visited-p (kill-buffer to-be-removed)) (goto-char point)))) (def-edebug-spec org-babel-map-src-blocks (form body)) @@ -1036,8 +1041,9 @@ buffer." (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-inline-src-block-regexp nil t) - (goto-char (match-beginning 1)) - (save-match-data ,@body) + (when (org-babel-active-location-p) + (goto-char (match-beginning 1)) + (save-match-data ,@body)) (goto-char (match-end 0)))) (unless visited-p (kill-buffer to-be-removed)) (goto-char point)))) @@ -1061,8 +1067,9 @@ buffer." (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-lob-one-liner-regexp nil t) - (goto-char (match-beginning 1)) - (save-match-data ,@body) + (when (org-babel-active-location-p) + (goto-char (match-beginning 1)) + (save-match-data ,@body)) (goto-char (match-end 0)))) (unless visited-p (kill-buffer to-be-removed)) (goto-char point)))) @@ -1085,9 +1092,11 @@ buffer." (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward ,rx nil t) - (goto-char (match-beginning 1)) - (when (looking-at org-babel-inline-src-block-regexp)(forward-char 1)) - (save-match-data ,@body) + (when (org-babel-active-location-p) + (goto-char (match-beginning 1)) + (when (looking-at org-babel-inline-src-block-regexp) + (forward-char 1)) + (save-match-data ,@body)) (goto-char (match-end 0)))) (unless visited-p (kill-buffer to-be-removed)) (goto-char point))))