summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2010-10-26 17:44:34 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2010-10-26 17:46:48 +0200
commit7635429d44db66cb5a681c6fca4de4893cd43dbd (patch)
tree599465722466ddd52343784cf4c7326835394918
parent8e12716f686a9af26c176881743b870a3d27a2fe (diff)
downloadorg-mode-7635429d44db66cb5a681c6fca4de4893cd43dbd.tar.gz
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.
-rw-r--r--doc/org.texi4
-rw-r--r--lisp/org-capture.el23
2 files changed, 24 insertions, 3 deletions
diff --git a/doc/org.texi b/doc/org.texi
index f46bf36..4e8eb63 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6152,6 +6152,10 @@ with the capture.
@item :unnarrowed
Do not narrow the target buffer, simply show the full buffer. Default is to
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
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index ef58252..e7f1537 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -186,6 +186,10 @@ properties are:
which means that the new line should become the third
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
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.
@@ -301,7 +305,8 @@ calendar | %:type %:date"
((const :format "%v " :empty-lines) (const 1))
((const :format "%v " :clock-in) (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
"Hook that is run right before a remember process is finalized.
@@ -529,8 +534,19 @@ bypassed."
;; Kill the indirect 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 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
(set-window-configuration return-wconf))
(when abort-note
@@ -667,7 +683,8 @@ already gone."
org-default-notes-file
(error "No notes file specified, and no default available")))
(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)
"Install Org-mode local variables."