From 0dc04f4210879bf842f796f89bc4872433bcbd2f Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sun, 5 May 2013 09:56:54 -0400 Subject: [PATCH] Don't let an empty summary change current message. * mail/rmailsum.el (rmail-summary-rmail-update): Detect empty summary and don't change selected message. (rmail-summary-goto-msg): Likewise. --- lisp/ChangeLog | 6 ++ lisp/mail/rmailsum.el | 136 ++++++++++++++++++++++-------------------- 2 files changed, 78 insertions(+), 64 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f18d856a4d..268a716fd0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-05-05 Richard Stallman + + * mail/rmailsum.el (rmail-summary-rmail-update): + Detect empty summary and don't change selected message. + (rmail-summary-goto-msg): Likewise. + 2013-05-05 Alan Mackenzie * progmodes/cc-defs.el (c-version): Increment to 5.32.5. diff --git a/lisp/mail/rmailsum.el b/lisp/mail/rmailsum.el index 13cd7c3f05..ccd76cd6ba 100644 --- a/lisp/mail/rmailsum.el +++ b/lisp/mail/rmailsum.el @@ -490,8 +490,7 @@ message." ;; we "don't have" a summary. (setq rmail-summary-buffer nil) ;; I have not a clue what this clause is doing. If you read this - ;; chunk of code and have a clue, then please email that clue to - ;; pmr@pajato.com + ;; chunk of code and have a clue, then please write it here. (if rmail-enable-mime (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil))) @@ -1122,57 +1121,59 @@ Search, the `unseen' attribute is restored.") (forward-line -1)) (beginning-of-line) (skip-chars-forward " ") - (let ((msg-num (string-to-number (buffer-substring - (point) - (progn (skip-chars-forward "0-9") - (point)))))) - ;; Always leave `unseen' removed - ;; if we get out of isearch mode. - ;; Don't let a subsequent isearch restore that `unseen'. - (if (not isearch-mode) - (setq rmail-summary-put-back-unseen nil)) - - (or (eq rmail-current-message msg-num) - (let ((window (get-buffer-window rmail-buffer t)) - (owin (selected-window))) - (if isearch-mode - (progn - ;; If we first saw the previous message in this search, - ;; and we have gone to a different message while searching, - ;; put back `unseen' on the former one. - (when rmail-summary-put-back-unseen - (rmail-set-attribute rmail-unseen-attr-index t - rmail-current-message) - (save-excursion - (goto-char rmail-summary-put-back-unseen) - (rmail-summary-mark-seen rmail-current-message t t))) - ;; Arrange to do that later, for the new current message, - ;; if it still has `unseen'. - (setq rmail-summary-put-back-unseen - (if (rmail-message-unseen-p msg-num) - (point)))) - (setq rmail-summary-put-back-unseen nil)) - ;; Go to the desired message. - (setq rmail-current-message msg-num) - ;; Update the summary to show the message has been seen. - (rmail-summary-mark-seen msg-num t) - (if window - ;; Using save-window-excursion would cause the new value - ;; of point to get lost. - (unwind-protect - (progn - (select-window window) - (rmail-show-message msg-num t)) - (select-window owin)) - (if (buffer-name rmail-buffer) - (with-current-buffer rmail-buffer - (rmail-show-message msg-num t)))) - ;; In linum mode, the message buffer must be specially - ;; updated (Bug#4878). - (and (fboundp 'linum-update) - (buffer-name rmail-buffer) - (linum-update rmail-buffer)))) - (rmail-summary-update-highlight nil))))) + ;; If the summary is empty, don't do anything. + (unless (eobp) + (let ((msg-num (string-to-number (buffer-substring + (point) + (progn (skip-chars-forward "0-9") + (point)))))) + ;; Always leave `unseen' removed + ;; if we get out of isearch mode. + ;; Don't let a subsequent isearch restore that `unseen'. + (if (not isearch-mode) + (setq rmail-summary-put-back-unseen nil)) + + (or (eq rmail-current-message msg-num) + (let ((window (get-buffer-window rmail-buffer t)) + (owin (selected-window))) + (if isearch-mode + (progn + ;; If we first saw the previous message in this search, + ;; and we have gone to a different message while searching, + ;; put back `unseen' on the former one. + (when rmail-summary-put-back-unseen + (rmail-set-attribute rmail-unseen-attr-index t + rmail-current-message) + (save-excursion + (goto-char rmail-summary-put-back-unseen) + (rmail-summary-mark-seen rmail-current-message t t))) + ;; Arrange to do that later, for the new current message, + ;; if it still has `unseen'. + (setq rmail-summary-put-back-unseen + (if (rmail-message-unseen-p msg-num) + (point)))) + (setq rmail-summary-put-back-unseen nil)) + ;; Go to the desired message. + (setq rmail-current-message msg-num) + ;; Update the summary to show the message has been seen. + (rmail-summary-mark-seen msg-num t) + (if window + ;; Using save-window-excursion would cause the new value + ;; of point to get lost. + (unwind-protect + (progn + (select-window window) + (rmail-show-message msg-num t)) + (select-window owin)) + (if (buffer-name rmail-buffer) + (with-current-buffer rmail-buffer + (rmail-show-message msg-num t)))) + ;; In linum mode, the message buffer must be specially + ;; updated (Bug#4878). + (and (fboundp 'linum-update) + (buffer-name rmail-buffer) + (linum-update rmail-buffer)))) + (rmail-summary-update-highlight nil)))))) (defun rmail-summary-save-buffer () "Save the buffer associated with this RMAIL summary." @@ -1208,6 +1209,10 @@ Returns non-nil if message N was found." (buffer-substring (point) (min (point-max) (+ 6 (point)))))) (total (with-current-buffer buf rmail-total-messages))) + ;; CURMSG should be nil when there's no current summary message + ;; (for instance, if the summary is empty). + (if (= curmsg 0) + (setq curmsg nil)) ;; If message number N was specified, find that message's line ;; or set message-not-found. ;; If N wasn't specified or that message can't be found. @@ -1228,17 +1233,20 @@ Returns non-nil if message N was found." (setq n curmsg) (setq message-not-found t) (goto-char cur)))) - (rmail-summary-mark-seen n) - (rmail-summary-update-highlight message-not-found) - (beginning-of-line) - (unless skip-rmail - (let ((selwin (selected-window))) - (unwind-protect - (progn (rmail-pop-to-buffer buf) - (rmail-show-message n)) - (select-window selwin) - ;; The actions above can alter the current buffer. Preserve it. - (set-buffer obuf)))) + ;; N can be nil now, along with CURMSG, + ;; if the summary is empty. + (when n + (rmail-summary-mark-seen n) + (rmail-summary-update-highlight message-not-found) + (beginning-of-line) + (unless skip-rmail + (let ((selwin (selected-window))) + (unwind-protect + (progn (rmail-pop-to-buffer buf) + (rmail-show-message n)) + (select-window selwin) + ;; The actions above can alter the current buffer. Preserve it. + (set-buffer obuf))))) (not message-not-found))) ;; Update the highlighted line in an rmail summary buffer. -- 2.20.1