mu4e-compose: try to avoid buffer/frame mishaps

... when closing a message. Should hopefully be a bit less bad than
before.
This commit is contained in:
Dirk-Jan C. Binnema 2024-02-18 18:02:54 +02:00
parent 309df647b8
commit 91eb777946
1 changed files with 28 additions and 35 deletions

View File

@ -453,19 +453,21 @@ appropriate flag at the message forwarded or replied-to."
(setq mu4e-sent-func #'mu4e-sent-handler) (setq mu4e-sent-func #'mu4e-sent-handler)
(mu4e--server-sent (buffer-file-name))) (mu4e--server-sent (buffer-file-name)))
(defun mu4e-message-kill-buffer () ;; (defun mu4e-message-kill-buffer ()
"Wrapper around `message-kill-buffer'. ;; "Wrapper around `message-kill-buffer'.
It attempts to restore some mu4e window layout after killing the ;; It attempts to restore some mu4e window layout after killing the
compose-buffer." ;; compose-buffer."
(interactive) ;; (interactive)
(let ((view (save-selected-window (mu4e-get-view-buffer))) ;; (let ((view (save-selected-window (mu4e-get-view-buffer)))
(hdrs (mu4e-get-headers-buffer))) ;; (hdrs (mu4e-get-headers-buffer)))
(message-kill-buffer) ;; (message-kill-buffer)
;; try to go back to some mu window if it is live; otherwise do nothing. ;; ;; try to go back to some mu window if it is live; otherwise do nothing.
(if (buffer-live-p view) ;; (if (buffer-live-p view)
(switch-to-buffer view) ;; (switch-to-buffer view)
(when (and (buffer-live-p hdrs)) ;; (when (and (buffer-live-p hdrs))
(switch-to-buffer hdrs))))) ;; (switch-to-buffer hdrs)))))
(defalias 'mu4e-message-kill-buffer 'message-kill-buffer)
;;; Crypto ;;; Crypto
(defun mu4e--compose-setup-crypto (parent compose-type) (defun mu4e--compose-setup-crypto (parent compose-type)
@ -748,21 +750,6 @@ Is this address yours?"
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(undo-boundary)) (undo-boundary))
(defun mu4e--maybe-delete-frame ()
"Delete frame if there are multiple and current one has a single
window."
;; XXX: this doesn't quite work; need a way to filter out
;; the one _real_ frame I'm looking at; but I always get 3 or so.
;; Only consider _real_ frames with some size
;; (when (one-window-p)
;; (let ((real-frames
;; (seq-filter (lambda (frame);; only count live visible parent frames.
;; (not (frame-parent frame)))
;; (visible-frame-list))))
;; (when (> (length real-frames) 1)
;; (delete-frame))))
)
(defun mu4e--compose-setup (compose-type compose-func &optional switch) (defun mu4e--compose-setup (compose-type compose-func &optional switch)
"Set up a new buffer for mu4e message composition. "Set up a new buffer for mu4e message composition.
@ -782,7 +769,7 @@ Optionally, SWITCH determines how to find a buffer for the message
(mu4e-message-at-point))) (mu4e-message-at-point)))
(mu4e-compose-parent-message parent) (mu4e-compose-parent-message parent)
(mu4e-compose-type compose-type) (mu4e-compose-type compose-type)
(actions '(mu4e--maybe-delete-frame)) (oldframe (selected-frame))
(buf)) (buf))
(advice-add 'message-is-yours-p :around #'mu4e--message-is-yours-p) (advice-add 'message-is-yours-p :around #'mu4e--message-is-yours-p)
(run-hooks 'mu4e-compose-pre-hook) ;; run the pre-hook. Still useful? (run-hooks 'mu4e-compose-pre-hook) ;; run the pre-hook. Still useful?
@ -794,12 +781,18 @@ Optionally, SWITCH determines how to find a buffer for the message
(set-visited-file-name ;; make it a draft file (set-visited-file-name ;; make it a draft file
(mu4e--draft-message-path (mu4e--message-basename) parent))) (mu4e--draft-message-path (mu4e--message-basename) parent)))
(mu4e--compose-setup-post compose-type parent) (mu4e--compose-setup-post compose-type parent)
;; handle closing of frames. (setq buf (current-buffer))
(setq-local ;;message-kill-actions actions (switch-to-buffer buf)
message-postpone-actions actions (let* ((msgframe (selected-frame))
message-send-actions actions) (actions (list
(setq buf (current-buffer))) (lambda () ;; kill frame when it was created for this
(switch-to-buffer buf))) (unless (eq oldframe msgframe)
(delete-frame msgframe))))))
;; handle closing of frames.
(setq-local ;;message-kill-actions actions
message-return-actions actions
message-send-actions actions
message-kill-actions actions)))))
;;;###autoload ;;;###autoload