Browse Source

org-capture: Fix error on capture abort

* lisp/org-capture.el (org-capture-finalize): Do not set `abort-note'
  to `dirty' too easily.

Reported-by: Brad Knotwell <bknotwell@yahoo.com>
<http://lists.gnu.org/r/emacs-orgmode/2018-04/msg00183.html>
Nicolas Goaziou 6 years ago
parent
commit
cb63ccb78e
1 changed files with 6 additions and 13 deletions
  1. 6 13
      lisp/org-capture.el

+ 6 - 13
lisp/org-capture.el

@@ -743,9 +743,7 @@ captured item after finalizing."
 	  (org-with-point-at clock-in-task (org-clock-in)))
 	(message "Interrupted clock has been resumed"))))
 
-  (let ((beg (point-min))
-	(end (point-max))
-	(abort-note nil))
+  (let ((abort-note nil))
     ;; Store the size of the capture buffer
     (org-capture-put :captured-entry-size (- (point-max) (point-min)))
     (widen)
@@ -753,16 +751,11 @@ captured item after finalizing."
     (org-capture-put :insertion-point (point))
 
     (if org-note-abort
-	(let ((m1 (org-capture-get :begin-marker 'local))
-	      (m2 (org-capture-get :end-marker 'local)))
-	  (if (and m1 m2 (= m1 beg) (= m2 end))
-	      (progn
-		(setq m2 (if (cdr (assq 'heading org-blank-before-new-entry))
-			     m2 (1+ m2))
-		      m2 (if (< (point-max) m2) (point-max) m2))
-		(setq abort-note 'clean)
-		(kill-region m1 m2))
-	    (setq abort-note 'dirty)))
+	(let ((beg (org-capture-get :begin-marker 'local))
+	      (end (org-capture-get :end-marker 'local)))
+	  (if (not (and beg end)) (setq abort-note 'dirty)
+	    (setq abort-note t)
+	    (org-with-wide-buffer (kill-region beg end))))
 
       ;; Postprocessing:  Update Statistics cookies, do the sorting
       (when (derived-mode-p 'org-mode)