From 131db505304e84eebfe8b604b39d1c31c1ac3fd9 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 6 Jul 2024 10:32:39 +0300 Subject: [PATCH] Fix returning to original TTY frame after 'rmail-reply' * lisp/mail/rmail.el (rmail-start-mail): Record the frame from which an Rmail command, such as 'rmail-mail' or 'rmail-reply', was invoked. (rmail--find-orig-rmail-frame): New function. (rmail-mail-return): Use 'rmail--find-orig-rmail-frame' to find the original frame, and make it the top frame on its TTY terminal. (Bug#69738) (cherry picked from commit 1b5cf29431a0727329d5e223be68ea2499d872ea) --- lisp/mail/rmail.el | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 2b119c7a5c7..f22161f766d 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el @@ -3686,7 +3686,12 @@ If BUFFER is not swapped, yank out of its message viewer buffer." other-headers) (let ((switch-function (cond (same-window nil) - (rmail-mail-new-frame 'switch-to-buffer-other-frame) + (rmail-mail-new-frame + (progn + ;; Record the frame from which we invoked this command. + (modify-frame-parameters (selected-frame) + '((rmail-orig-frame . t))) + 'switch-to-buffer-other-frame)) (t 'switch-to-buffer-other-window))) yank-action) (if replybuffer @@ -3716,6 +3721,11 @@ If BUFFER is not swapped, yank out of its message viewer buffer." (modify-frame-parameters (selected-frame) '((mail-dedicated-frame . t))))))) +(defun rmail--find-orig-rmail-frame () + (car (filtered-frame-list + (lambda (frame) + (eq (frame-parameter frame 'rmail-orig-frame) t))))) + (defun rmail-mail-return (&optional newbuf) "Try to return to Rmail from the mail window. If optional argument NEWBUF is specified, it is the Rmail buffer @@ -3757,9 +3767,19 @@ to switch to." ;; probably wants to delete it now. ((display-multi-frame-p) (delete-frame)) - ;; The previous frame is where normally they have the Rmail buffer - ;; displayed. - (t (other-frame -1)))) + (t + ;; Try to find the original Rmail frame and make it the top frame. + (let ((fr (selected-frame)) + (orig-fr (rmail--find-orig-rmail-frame))) + (if orig-fr + (progn + (modify-frame-parameters orig-fr '((rmail-orig-frame . nil))) + (select-frame-set-input-focus orig-fr)) + ;; If we cannot find the frame from which we started, punt, and + ;; display the previous frame, which is where they normally have + ;; the Rmail buffer displayed. + (other-frame -1)) + (delete-frame fr))))) (defun rmail-mail () "Send mail in another window. -- 2.39.2