Browse Source

New capture property :kill-buffer

* lisp/org-capture.el (org-capture-templates): New capture
property `:kill-buffer'. (org-capture-finalize): Kill target buffer
if that is desired.
(org-capture-target-buffer): Remember if we have to make the buffer.

Proposal by Samuel Wales.
Carsten Dominik 14 years ago
parent
commit
7635429d44
2 changed files with 24 additions and 3 deletions
  1. 4 0
      doc/org.texi
  2. 20 3
      lisp/org-capture.el

+ 4 - 0
doc/org.texi

@@ -6152,6 +6152,10 @@ with the capture.
 @item :unnarrowed
 @item :unnarrowed
 Do not narrow the target buffer, simply show the full buffer.  Default is to
 Do not narrow the target buffer, simply show the full buffer.  Default is to
 narrow it so that you only see the new material.
 narrow it so that you only see the new material.
+
+@item :kill-buffer
+If the target file was not yet visited when capture was invoked, kill the
+buffer again after capture is completed.
 @end table
 @end table
 @end table
 @end table
 
 

+ 20 - 3
lisp/org-capture.el

@@ -186,6 +186,10 @@ properties are:
                      which means that the new line should become the third
                      which means that the new line should become the third
                      line before the second horizontal separator line.
                      line before the second horizontal separator line.
 
 
+ :kill-buffer        If the target file was not yet visited by a buffer when
+                     capture was invoked, kill the buffer again after capture
+                     is finalized.
+
 The template defines the text to be inserted.  Often this is an org-mode
 The template defines the text to be inserted.  Often this is an org-mode
 entry (so the first line should start with a star) that will be filed as a
 entry (so the first line should start with a star) that will be filed as a
 child of the target headline.  It can also be freely formatted text.
 child of the target headline.  It can also be freely formatted text.
@@ -301,7 +305,8 @@ calendar                |  %:type %:date"
 			    ((const :format "%v " :empty-lines) (const 1))
 			    ((const :format "%v " :empty-lines) (const 1))
 			    ((const :format "%v " :clock-in) (const t))
 			    ((const :format "%v " :clock-in) (const t))
 			    ((const :format "%v " :clock-resume) (const t))
 			    ((const :format "%v " :clock-resume) (const t))
-			    ((const :format "%v " :unnarrowed) (const t))))))))
+			    ((const :format "%v " :unnarrowed) (const t))
+			    ((const :format "%v " :kill-buffer) (const t))))))))
 
 
 (defcustom org-capture-before-finalize-hook nil
 (defcustom org-capture-before-finalize-hook nil
   "Hook that is run right before a remember process is finalized.
   "Hook that is run right before a remember process is finalized.
@@ -529,8 +534,19 @@ bypassed."
 
 
     ;; Kill the indirect buffer
     ;; Kill the indirect buffer
     (save-buffer)
     (save-buffer)
-    (let ((return-wconf (org-capture-get :return-to-wconf 'local)))
+    (let ((return-wconf (org-capture-get :return-to-wconf 'local))
+	  (new-buffer (org-capture-get :new-buffer 'local))
+	  (kill-buffer (org-capture-get :kill-buffer 'local))
+	  (base-buffer (buffer-base-buffer (current-buffer))))
+
+      ;; Kill the indiret buffer
       (kill-buffer (current-buffer))
       (kill-buffer (current-buffer))
+
+      ;; Kill the target buffer if that is desired
+      (when (and base-buffer new-buffer kill-buffer)
+	(with-current-buffer base-buffer (save-buffer))
+	(kill-buffer base-buffer))
+
       ;; Restore the window configuration before capture
       ;; Restore the window configuration before capture
       (set-window-configuration return-wconf))
       (set-window-configuration return-wconf))
     (when abort-note
     (when abort-note
@@ -667,7 +683,8 @@ already gone."
 		 org-default-notes-file
 		 org-default-notes-file
 		 (error "No notes file specified, and no default available")))
 		 (error "No notes file specified, and no default available")))
   (or (org-find-base-buffer-visiting file)
   (or (org-find-base-buffer-visiting file)
-      (find-file-noselect (expand-file-name file org-directory))))
+      (progn (org-capture-put :new-buffer t)
+	     (find-file-noselect (expand-file-name file org-directory)))))
 
 
 (defun org-capture-steal-local-variables (buffer)
 (defun org-capture-steal-local-variables (buffer)
   "Install Org-mode local variables."
   "Install Org-mode local variables."