From d7940ae2a7ca01f01d17ba85e113ad7cc65b10ea Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 27 Nov 2017 23:23:04 +0100 Subject: [PATCH] ob-core: Fix removal of elements after RESULTS * lisp/ob-core.el (org-babel-result-end): Ignore elements that do not correspond to a valid result type (e.g., a headline). Fixes commit 1d8126385cf979cfaade0e6a82040884bd6af56b. Reported-by: Kaushal Modi --- lisp/ob-core.el | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 106cfbd24..0bf86dfce 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2460,12 +2460,18 @@ in the buffer." (cond ((looking-at-p "^[ \t]*$") (point)) ;no result ((looking-at-p (format "^[ \t]*%s[ \t]*$" org-bracket-link-regexp)) (line-beginning-position 2)) - (t (save-excursion - (goto-char - (min (point-max) ;for narrowed buffers - (org-element-property :end (org-element-at-point)))) - (skip-chars-backward " \r\t\n") - (line-beginning-position 2))))) + (t + (let ((element (org-element-at-point))) + (if (memq (org-element-type element) + ;; Possible results types. + '(drawer export-block fixed-width item plain-list src-block + table)) + (save-excursion + (goto-char (min (point-max) ;for narrowed buffers + (org-element-property :end element))) + (skip-chars-backward " \r\t\n") + (line-beginning-position 2)) + (point)))))) (defun org-babel-result-to-file (result &optional description) "Convert RESULT into an `org-mode' link with optional DESCRIPTION.