From fdf7e79ed152c652c5666ce9e5ab3f1270bf72c5 Mon Sep 17 00:00:00 2001 From: chasberry Date: Tue, 11 Nov 2014 15:32:41 -0800 Subject: [PATCH 5/5] lisp/ob-core.el: Enable removable inline src results * lisp/ob-core.al (org-babel-inline-result-wrap, org-babel-insert-result, org-babel-delete-babel-snippet): Inline src blocks results are export-snippets with a faux `:back-end' of `babel'. (org-babel-inline-result-wrap): Now `@@babel:%s@@'. (org-babel-delete-babel-snippet): Remove a babel export-snippet. (org-babel-insert-result): Remove a babel export snippet. The treatment of inline src block results as verbatim, e.g. `=result=', makes finding and removing them programatically tricky and risky. By wrapping them as `@@babel:result@@' they can be found and removed. --- lisp/ob-core.el | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 6c38677..471ff25 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -156,7 +156,7 @@ See also `org-babel-noweb-wrap-start'." :group 'org-babel :type 'string) -(defcustom org-babel-inline-result-wrap "=%s=" +(defcustom org-babel-inline-result-wrap "@@babel:%s@@" "Format string used to wrap inline results. This string must include a \"%s\" which will be replaced by the results." :group 'org-babel @@ -2136,8 +2136,9 @@ code ---- the results are extracted in the syntax of the source (goto-char (match-end 0)) (insert (if (listp result) "\n" " ")) (point)))) - (existing-result (unless inlinep - (org-babel-where-is-src-block-result + (existing-result (if inlinep + (org-babel-delete-babel-snippet) + (org-babel-where-is-src-block-result t info hash indent))) (results-switches (cdr (assoc :results_switches (nth 2 info)))) @@ -2279,6 +2280,22 @@ code ---- the results are extracted in the syntax of the source (if keep-keyword (1+ (match-end 0)) (1- (match-beginning 0))) (progn (forward-line 1) (org-babel-result-end)))))))) +(defun org-babel-delete-babel-snippet (&optional info) + "When point is before a babel export-snippet, delete it." + (let ((location (org-babel-where-is-src-block-result nil info))) + (when location + (save-excursion + (goto-char location) + (when + (looking-at "\\([[:space:]]*\\)\\([@]\\)") + (goto-char (match-end 1)) + (let ((export-snippet (org-element-export-snippet-parser))) + (if export-snippet + (let ((start (org-element-property :begin export-snippet)) + (end (org-element-property :end export-snippet))) + (and (eq (org-export-snippet-backend export-snippet) 'babel) + (delete-region start end)))))))))) + (defun org-babel-remove-result-one-or-many (x) "Remove the result of the current source block. If called with a prefix argument, remove all result blocks -- 1.9.3 (Apple Git-50)