summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2026-04-08 00:30:44 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2026-04-08 00:30:44 +0300
commit03045b9fc6949897f82d83ebd392bcdf7de0ef50 (patch)
tree481962e822c6d140d4fb32450e93aa9c391dee13
parent772d052a1a74b41cdb5c76875fc38bcf879fe896 (diff)
mu4e: be more careful deleting frames
Remember the exact frame we created, and only kill that one. Ensure mu4e-compose-post-hook fires at most once.
-rw-r--r--NEWS.org4
-rw-r--r--mu4e/mu4e-compose.el2
-rw-r--r--mu4e/mu4e-draft.el32
3 files changed, 26 insertions, 12 deletions
diff --git a/NEWS.org b/NEWS.org
index cc4f30e..bcae3e9 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -19,7 +19,9 @@
- ~mu4e-compose-reply-include-mime-types~ specifies the mime-types for message
attachments that should be included in replies, with the default set to
"text/x-patch" -- i.e., patches are included in replies, so you can comment
- on them. Set to nil to disable.
+ on them. Set to nil to disable. (1.14.0)
+
+ - ~mu4e-compose-post-hook~ only runs once per message (buffer) (1.14.1)
*** scm
diff --git a/mu4e/mu4e-compose.el b/mu4e/mu4e-compose.el
index b559314..3c5642c 100644
--- a/mu4e/mu4e-compose.el
+++ b/mu4e/mu4e-compose.el
@@ -91,8 +91,6 @@ This multiplexes the `message-mode' hooks `message-send-actions',
:type 'hook
:group 'mu4e-compose)
-
-
(defvar mu4e-captured-message)
(defun mu4e-compose-attach-captured-message ()
"Insert the last captured message file as an attachment.
diff --git a/mu4e/mu4e-draft.el b/mu4e/mu4e-draft.el
index 547a592..9bb6424 100644
--- a/mu4e/mu4e-draft.el
+++ b/mu4e/mu4e-draft.el
@@ -716,16 +716,20 @@ view buffer is showing, if any."
(defvar mu4e--draft-activation-frame nil
"Frame from which composition was activated.
-Used internally for mu4e-compose-post-kill-frame.")
+Used internally for `mu4e-compose-post-kill-frame'.")
+
+(defvar mu4e--draft-compose-frame nil
+ "Frame in which the composition buffer is displayed.
+Used internally for `mu4e-compose-post-kill-frame'.")
(defun mu4e-compose-post-kill-frame ()
"Function that might kill the composition frame.
This is for use in `mu4e-compose-post-hook'."
- (let ((msgframe (selected-frame)))
- (when (and mu4e--draft-activation-frame
- (frame-live-p msgframe)
- (not (eq mu4e--draft-activation-frame msgframe)))
- (delete-frame msgframe))))
+ (when-let* ((compose-frame mu4e--draft-compose-frame)
+ (activation-frame mu4e--draft-activation-frame))
+ (when (and (frame-live-p compose-frame)
+ (not (eq activation-frame compose-frame)))
+ (delete-frame compose-frame))))
(defvar mu4e-message-post-action nil
"Runtime variable for use with `mu4e-compose-post-hook'.
@@ -733,15 +737,24 @@ It contains a symbol denoting the action that triggered the hook,
either `send', `exit', `kill' or `postpone'.")
(defvar mu4e-compose-post-hook)
+(defvar-local mu4e--post-hook-done nil
+ "Whether `mu4e-compose-post-hook' has already run for this buffer.")
+
(defun mu4e--message-post-actions (trigger)
"Invoked after we're done with a message with TRIGGER.
See `mu4e-message-post-action' for the available triggers.
I.e. this multiplexes the `message-(send|exit|kill|postpone)-actions';
-with the mu4e-message-post-action set accordingly."
- (setq mu4e-message-post-action trigger)
- (run-hooks 'mu4e-compose-post-hook))
+with the mu4e-message-post-action set accordingly.
+
+The hook is run at most once per compose buffer; e.g. send-and-exit
+triggers both `send' and `exit' actions but only the first one
+fires the hook."
+ (unless mu4e--post-hook-done
+ (setq mu4e--post-hook-done t)
+ (setq mu4e-message-post-action trigger)
+ (run-hooks 'mu4e-compose-post-hook)))
(defun mu4e--prepare-post (&optional oldframe oldwindconf)
"Prepare the `mu4e-compose-post-hook` handling.
@@ -754,6 +767,7 @@ window configuration."
;; each composition buffer tracks its *own* activation context, which is
;; needed when multiple compositions exist simultaneously.
(setq-local mu4e--draft-activation-frame oldframe
+ mu4e--draft-compose-frame (selected-frame)
mu4e--before-draft-window-config oldwindconf)
;; make message's "post" hooks local, and multiplex them