Browse Source

org-capture.el: Fix bugs about handling the :clock-keep parameter.

* org-capture.el (org-capture-clock-keep): New local variable.
(org-capture, org-capture-finalize): Use it and fix a bug when
:clock-keep is set to `t'.
Bastien Guerry 8 years ago
parent
commit
8cf35f0ab1
1 changed files with 20 additions and 18 deletions
  1. 20 18
      lisp/org-capture.el

+ 20 - 18
lisp/org-capture.el

@@ -347,6 +347,9 @@ The remember buffer is still current when this hook runs."
   "Local variable holding the plist in a capture buffer.
 This is used to store the plist for use when finishing a capture process.
 Another such process might have changed the global variable by then.")
+(defvar org-capture-clock-keep nil
+  "Local variable to store the value of the :clock-keep parameter.
+This is needed in case org-capture-finalize is called interactively.")
 
 (defun org-capture-put (&rest stuff)
   (while stuff
@@ -447,6 +450,7 @@ bypassed."
 	   (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
 	   (error "Capture abort: %s" error)))
 
+	(setq org-capture-clock-keep (org-capture-get :clock-keep))
 	(if (equal goto 0)
 	    ;;insert at point
 	    (org-capture-insert-template-here)
@@ -460,19 +464,19 @@ bypassed."
 	     (error "Capture template `%s': %s"
 		    (org-capture-get :key)
 		    (nth 1 error))))
+	  (if (and (org-mode-p)
+		   (org-capture-get :clock-in))
+	      (condition-case nil
+		  (progn
+		    (if (org-clock-is-active)
+			(org-capture-put :interrupted-clock
+					 (copy-marker org-clock-marker)))
+		    (org-clock-in)
+		    (org-set-local 'org-capture-clock-was-started t))
+		(error
+		 "Could not start the clock in this capture buffer")))
 	  (if (org-capture-get :immediate-finish)
-	      (org-capture-finalize nil (org-capture-get :clock-keep))
-	    (if (and (org-mode-p)
-		     (org-capture-get :clock-in))
-		(condition-case nil
-		    (progn
-		      (if (org-clock-is-active)
-			  (org-capture-put :interrupted-clock
-					   (copy-marker org-clock-marker)))
-		      (org-clock-in)
-		      (org-set-local 'org-capture-clock-was-started t))
-		  (error
-		   "Could not start the clock in this capture buffer")))))))))))
+	      (org-capture-finalize nil)))))))))
 
 (defun org-capture-get-template ()
   "Get the template from a file or a function if necessary."
@@ -492,12 +496,10 @@ bypassed."
      (t (setq txt "* Invalid capture template")))
     (org-capture-put :template txt)))
 
-(defun org-capture-finalize (&optional stay-with-capture clock-keep)
+(defun org-capture-finalize (&optional stay-with-capture)
   "Finalize the capture process.
 With prefix argument STAY-WITH-CAPTURE, jump to the location of the
-captured item after finalizing.
-A second optional argument tells whether finalizing the capture
-process should keep the clock running in the filed entry."
+captured item after finalizing."
   (interactive "P")
   (unless (and org-capture-mode
 	       (buffer-base-buffer (current-buffer)))
@@ -510,8 +512,8 @@ process should keep the clock running in the filed entry."
 	     (> org-clock-marker (point-min))
 	     (< org-clock-marker (point-max)))
     ;; Looks like the clock we started is still running.  Clock out.
-    (when (not clock-keep) (let (org-log-note-clock-out) (org-clock-out)))
-    (when (and (not clock-keep)
+    (when (not org-capture-clock-keep) (let (org-log-note-clock-out) (org-clock-out)))
+    (when (and (not org-capture-clock-keep)
 	       (org-capture-get :clock-resume 'local)
 	       (markerp (org-capture-get :interrupted-clock 'local))
 	       (buffer-live-p (marker-buffer