Browse Source

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 <kaushal.modi@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2017-11/msg00384.html>
Nicolas Goaziou 1 month ago
parent
commit
d7940ae2a7
1 changed files with 12 additions and 6 deletions
  1. 12 6
      lisp/ob-core.el

+ 12 - 6
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.