Commit 4dc6f997d61d
Changed files (1)
dots
config
emacs
dots/config/emacs/init.el
@@ -2025,11 +2025,15 @@ Link: %a"
"List of capture template keys that should trigger refile after capture.")
(defun vde/org-capture-refile-if-needed ()
- "Refile the captured entry if the template key is in `vde/org-capture-refile-templates'."
+ "Refile the captured entry if the template key is in `vde/org-capture-refile-templates'.
+After a successful refile, delete the popup frame if applicable."
(when (and (not org-note-abort)
(member (plist-get org-capture-plist :key) vde/org-capture-refile-templates))
- (org-capture-goto-last-stored)
- (call-interactively 'org-refile)))
+ (let ((is-popup (frame-parameter nil 'vde/window-popup-frame)))
+ (org-capture-goto-last-stored)
+ (call-interactively 'org-refile)
+ (when is-popup
+ (delete-frame)))))
(add-hook 'org-capture-after-finalize-hook #'vde/org-capture-refile-if-needed)
(add-to-list 'org-capture-templates
@@ -2050,11 +2054,27 @@ Link: %a"
(display-buffer-same-window)))
(defun vde/window-delete-popup-frame (&rest _)
- "Kill selected selected frame if it has parameter `prot-window-popup-frame'.
-Use this function via a hook."
- (when (frame-parameter nil 'vde/window-popup-frame)
+ "Kill selected selected frame if it has parameter `vde/window-popup-frame'.
+Use this function via a hook.
+Skip deletion when:
+- `org-capture-refile' (C-c C-w) is running (it handles cleanup via advice)
+- the capture template auto-refiles via `vde/org-capture-refile-templates'"
+ (when (and (frame-parameter nil 'vde/window-popup-frame)
+ (not (eq this-command 'org-capture-refile))
+ (not (and (bound-and-true-p org-capture-plist)
+ (member (plist-get org-capture-plist :key)
+ vde/org-capture-refile-templates)
+ (not org-note-abort))))
(delete-frame)))
+ (advice-add 'org-capture-refile :around
+ (lambda (orig-fn &rest args)
+ "Delete the popup frame after org-capture-refile completes."
+ (let ((is-popup (frame-parameter nil 'vde/window-popup-frame)))
+ (apply orig-fn args)
+ (when is-popup
+ (delete-frame)))))
+
;; (add-to-list 'org-capture-templates
;; `("w" "Writing"))
(declare-function vde/window-delete-popup-frame "init")