comparison lisp/mail/rmailsum.el @ 88166:d20b1cfca610

(rmail-new-summary): Make sure summary buffer is current when selecting message. (rmail-summary-browse-body): Deleted. (rmail-summary-rmail-update, rmail-summary-get-message-at-point, rmail-summary-goto-msg): Use string-to-number. (rmail-summary-toggle-header, rmail-summary-add-label, rmail-summary-kill-label): Use with-current-buffer. (rmail-summary-previous-msg): Add docstring.
author Henrik Enberg <henrik.enberg@telia.com>
date Mon, 16 Jan 2006 21:06:36 +0000
parents a271a865e911
children c506eb58293b
comparison
equal deleted inserted replaced
88165:fd1a32d32b23 88166:d20b1cfca610
212 (let ((summary-msgs ()) 212 (let ((summary-msgs ())
213 (new-summary-line-count 0) 213 (new-summary-line-count 0)
214 (msgnum 1) 214 (msgnum 1)
215 current-message sumbuf was-in-summary) 215 current-message sumbuf was-in-summary)
216 (save-excursion 216 (save-excursion
217
218 ;; Go to the Rmail buffer. 217 ;; Go to the Rmail buffer.
219 (if (eq major-mode 'rmail-summary-mode) 218 (if (eq major-mode 'rmail-summary-mode)
220 (setq was-in-summary t)) 219 (setq was-in-summary t))
221 (set-buffer rmail-buffer) 220 (set-buffer rmail-buffer)
222
223 ;; Find its summary buffer, or make one. 221 ;; Find its summary buffer, or make one.
224 (setq current-message rmail-current-message 222 (setq current-message rmail-current-message
225 sumbuf 223 sumbuf
226 (if (and rmail-summary-buffer 224 (if (and rmail-summary-buffer
227 (buffer-name rmail-summary-buffer)) 225 (buffer-name rmail-summary-buffer))
228 rmail-summary-buffer 226 rmail-summary-buffer
229 (generate-new-buffer (concat (buffer-name) "-summary")))) 227 (generate-new-buffer (concat (buffer-name) "-summary"))))
230
231 ;; Collect the message summaries based on the filtering 228 ;; Collect the message summaries based on the filtering
232 ;; argument (FUNCTION). 229 ;; argument (FUNCTION).
233 (while (>= rmail-total-messages msgnum) 230 (while (>= rmail-total-messages msgnum)
234 (if (or (null function) 231 (if (or (null function)
235 (apply function (cons msgnum args))) 232 (apply function (cons msgnum args)))
236 (setq summary-msgs 233 (setq summary-msgs
237 (cons (cons msgnum (rmail-summary-get-summary msgnum)) 234 (cons (cons msgnum (rmail-summary-get-summary msgnum))
238 summary-msgs))) 235 summary-msgs)))
239 (setq msgnum (1+ msgnum))) 236 (setq msgnum (1+ msgnum)))
240 (setq summary-msgs (nreverse summary-msgs)) 237 (setq summary-msgs (nreverse summary-msgs))
241
242 ;; Place the collected summaries into the summary buffer. 238 ;; Place the collected summaries into the summary buffer.
243 (setq rmail-summary-buffer nil) 239 (setq rmail-summary-buffer nil)
244 (save-excursion 240 (save-excursion
245 (let ((rbuf (current-buffer)) 241 (let ((rbuf (current-buffer))
246 (vbuf rmail-view-buffer) 242 (vbuf rmail-view-buffer)
262 rmail-view-buffer vbuf 258 rmail-view-buffer vbuf
263 rmail-summary-redo redo-form 259 rmail-summary-redo redo-form
264 rmail-total-messages total 260 rmail-total-messages total
265 rmail-current-message current-message))) 261 rmail-current-message current-message)))
266 (setq rmail-summary-buffer sumbuf)) 262 (setq rmail-summary-buffer sumbuf))
267
268 ;; Now display the summary buffer and go to the right place in it. 263 ;; Now display the summary buffer and go to the right place in it.
269 (or was-in-summary 264 (or was-in-summary
270 (progn 265 (progn
271 (if (and (one-window-p) 266 (if (and (one-window-p)
272 pop-up-windows (not pop-up-frames)) 267 pop-up-windows (not pop-up-frames))
281 (delete-other-windows))) 276 (delete-other-windows)))
282 (pop-to-buffer sumbuf)) 277 (pop-to-buffer sumbuf))
283 (set-buffer rmail-buffer) 278 (set-buffer rmail-buffer)
284 ;; This is how rmail makes the summary buffer reappear. 279 ;; This is how rmail makes the summary buffer reappear.
285 ;; We do this here to make the window the proper size. 280 ;; We do this here to make the window the proper size.
286 (rmail-select-summary nil))) 281 (rmail-select-summary nil)
287 282 (set-buffer rmail-summary-buffer)))
288 (rmail-summary-goto-msg current-message nil t) 283 (rmail-summary-goto-msg current-message nil t)
289 (rmail-summary-construct-io-menu) 284 (rmail-summary-construct-io-menu)
290 (message "Computing summary lines...done"))) 285 (message "Computing summary lines...done")))
291 286
292 ;;;; Low levels of generating a summary. 287 ;;;; Low levels of generating a summary.
525 (display-buffer rmail-buffer)) 520 (display-buffer rmail-buffer))
526 521
527 ;;; mbox: ready 522 ;;; mbox: ready
528 (defun rmail-summary-next-msg (&optional number) 523 (defun rmail-summary-next-msg (&optional number)
529 "Display next non-deleted msg from rmail file. 524 "Display next non-deleted msg from rmail file.
530 With optional prefix argument NUMBER, moves forward this number of non-deleted 525 With optional prefix argument NUMBER, moves forward this number of
531 messages, or backward if NUMBER is negative." 526 non-deleted messages, or backward if NUMBER is negative."
532 (interactive "p") 527 (interactive "p")
533 (let (msg) 528 (let (msg)
534 (with-current-buffer rmail-buffer 529 (with-current-buffer rmail-buffer
535 (rmail-next-undeleted-message number) 530 (rmail-next-undeleted-message number)
536 (setq msg rmail-current-message)) 531 (setq msg rmail-current-message))
537 (rmail-summary-goto-msg msg))) 532 (rmail-summary-goto-msg msg)))
538 533
539 ;;; mbox: ready 534 ;;; mbox: ready
540 (defun rmail-summary-previous-msg (&optional number) 535 (defun rmail-summary-previous-msg (&optional number)
536 "Display previous non-deleted msg from rmail file.
537 With optional prefix argument NUMBER, moves backward this number of
538 non-deleted messages."
541 (interactive "p") 539 (interactive "p")
542 (rmail-summary-next-msg (- (if number number 1)))) 540 (rmail-summary-next-msg (- (if number number 1))))
543 541
544 (defun rmail-summary-next-labeled-message (n labels) 542 (defun rmail-summary-next-labeled-message (n labels)
545 "Show next message with LABEL. Defaults to last labels used. 543 "Show next message with LABEL. Defaults to last labels used.
773 (if (eobp) 771 (if (eobp)
774 (forward-line -1)) 772 (forward-line -1))
775 ;; Determine the message number correpsonding to line point is on. 773 ;; Determine the message number correpsonding to line point is on.
776 (beginning-of-line) 774 (beginning-of-line)
777 (skip-chars-forward " ") 775 (skip-chars-forward " ")
778 (let ((msg-num (string-to-int (buffer-substring 776 (let ((msg-num (string-to-number (buffer-substring
779 (point) 777 (point)
780 (progn (skip-chars-forward "0-9") 778 (progn (skip-chars-forward "0-9")
781 (point)))))) 779 (point))))))
782 780
783 ;; Always leave `unseen' removed if we get out of isearch mode. 781 ;; Always leave `unseen' removed if we get out of isearch mode.
784 ;; Don't let a subsequent isearch restore `unseen'. 782 ;; Don't let a subsequent isearch restore `unseen'.
785 (if (not isearch-mode) 783 (if (not isearch-mode)
786 (setq rmail-summary-put-back-unseen nil)) 784 (setq rmail-summary-put-back-unseen nil))
1030 1028
1031 (defun rmail-summary-get-message-at-point () 1029 (defun rmail-summary-get-message-at-point ()
1032 "Return the message number corresponding to the line containing point. 1030 "Return the message number corresponding to the line containing point.
1033 If the summary buffer contains no messages, nil is returned." 1031 If the summary buffer contains no messages, nil is returned."
1034 (save-excursion 1032 (save-excursion
1035
1036 ;; Position point at the beginning of a line. 1033 ;; Position point at the beginning of a line.
1037 (if (eobp) 1034 (if (eobp)
1038 (forward-line -1) 1035 (forward-line -1)
1039 (forward-line 0)) 1036 (forward-line 0))
1040
1041 ;; Parse the message number. 1037 ;; Parse the message number.
1042 (string-to-int 1038 (string-to-number
1043 (buffer-substring (point) (min (point-max) (+ 4 (point))))))) 1039 (buffer-substring (point) (min (point-max) (+ 4 (point)))))))
1044 1040
1045 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail) 1041 (defun rmail-summary-goto-msg (&optional n nowarn skip-rmail)
1046 "Go to message N in the summary buffer and the Rmail buffer. 1042 "Go to message N in the summary buffer and the Rmail buffer.
1047 If N is nil, use the message corresponding to point in the summary 1043 If N is nil, use the message corresponding to point in the summary
1054 ;; Do the end of buffer adjustment. 1050 ;; Do the end of buffer adjustment.
1055 (if (eobp) (forward-line -1)) 1051 (if (eobp) (forward-line -1))
1056 (beginning-of-line) 1052 (beginning-of-line)
1057 ;; Set N to the current message unless it was already set by the 1053 ;; Set N to the current message unless it was already set by the
1058 ;; caller. 1054 ;; caller.
1059 (unless n 1055 (unless n (setq n (rmail-summary-get-message-at-point)))
1060 (setq n (rmail-summary-get-message-at-point)))
1061
1062 (let* ((obuf (current-buffer)) 1056 (let* ((obuf (current-buffer))
1063 (buf rmail-buffer) 1057 (buf rmail-buffer)
1064 (cur (point)) 1058 (cur (point))
1065 message-not-found 1059 message-not-found
1066 (curmsg (string-to-int 1060 (curmsg (string-to-number
1067 (buffer-substring (point) 1061 (buffer-substring (point)
1068 (min (point-max) (+ 6 (point)))))) 1062 (min (point-max) (+ 6 (point))))))
1069 (total (save-excursion 1063 (total (with-current-buffer buf
1070 (set-buffer buf)
1071 rmail-total-messages))) 1064 rmail-total-messages)))
1072
1073 ;; Do a validity check on N. If it is valid then set the current 1065 ;; Do a validity check on N. If it is valid then set the current
1074 ;; summary message to N. `rmail-summary-rmail-update' will then 1066 ;; summary message to N. `rmail-summary-rmail-update' will then
1075 ;; actually move point to the selected message. 1067 ;; actually move point to the selected message.
1076 (if (< n 1) 1068 (if (< n 1)
1077 (progn (message "No preceding message") 1069 (progn (message "No preceding message")
1094 (let ((buffer-read-only nil)) 1086 (let ((buffer-read-only nil))
1095 (delete-char 1) 1087 (delete-char 1)
1096 (insert " ")))) 1088 (insert " "))))
1097 (rmail-summary-update-highlight message-not-found) 1089 (rmail-summary-update-highlight message-not-found)
1098 (beginning-of-line) 1090 (beginning-of-line)
1099
1100 ;; Determine if the Rmail buffer needs to be processed. 1091 ;; Determine if the Rmail buffer needs to be processed.
1101 (if skip-rmail 1092 (if skip-rmail
1102 nil 1093 nil
1103 ;; It does. 1094 ;; It does.
1104 (let ((selwin (selected-window))) 1095 (let ((selwin (selected-window)))
1394 1385
1395 ;;; mbox: ready 1386 ;;; mbox: ready
1396 (defun rmail-summary-toggle-header () 1387 (defun rmail-summary-toggle-header ()
1397 "Show original message header if pruned header currently shown, or vice versa." 1388 "Show original message header if pruned header currently shown, or vice versa."
1398 (interactive) 1389 (interactive)
1399 (save-excursion 1390 (with-current-buffer rmail-buffer
1400 (set-buffer rmail-buffer)
1401 (rmail-toggle-header))) 1391 (rmail-toggle-header)))
1402 1392
1403 ;;; mbox: ready 1393 ;;; mbox: ready
1404 (defun rmail-summary-add-label (label) 1394 (defun rmail-summary-add-label (label)
1405 "Add LABEL to labels associated with current Rmail message. 1395 "Add LABEL to labels associated with current Rmail message.
1406 Completion is performed over known labels when reading." 1396 Completion is performed over known labels when reading."
1407 (interactive (list (save-excursion 1397 (interactive (list (with-current-buffer rmail-buffer
1408 (set-buffer rmail-buffer)
1409 (rmail-read-label "Add label")))) 1398 (rmail-read-label "Add label"))))
1410 (save-excursion 1399 (with-current-buffer rmail-buffer
1411 (set-buffer rmail-buffer)
1412 (rmail-add-label label))) 1400 (rmail-add-label label)))
1413 1401
1414 (defun rmail-summary-kill-label (label) 1402 (defun rmail-summary-kill-label (label)
1415 "Remove LABEL from labels associated with current Rmail message. 1403 "Remove LABEL from labels associated with current Rmail message.
1416 Completion is performed over known labels when reading." 1404 Completion is performed over known labels when reading."
1417 (interactive (list (save-excursion 1405 (interactive (list (with-current-buffer rmail-buffer
1418 (set-buffer rmail-buffer)
1419 (rmail-read-label "Kill label")))) 1406 (rmail-read-label "Kill label"))))
1420 (save-excursion 1407 (with-current-buffer rmail-buffer
1421 (set-buffer rmail-buffer)
1422 (rmail-set-label label nil))) 1408 (rmail-set-label label nil)))
1423 1409
1424 ;;;; *** Rmail Summary Mailing Commands *** 1410 ;;;; *** Rmail Summary Mailing Commands ***
1425 1411
1426 (defun rmail-summary-override-mail-send-and-exit () 1412 (defun rmail-summary-override-mail-send-and-exit ()
1725 (goto-char (+ (point) offset)) 1711 (goto-char (+ (point) offset))
1726 (unless (looking-at char) 1712 (unless (looking-at char)
1727 (delete-char 1) 1713 (delete-char 1)
1728 (insert char))))))) 1714 (insert char)))))))
1729 1715
1730 ;;;; Browser related functions.
1731
1732 (defun rmail-summary-browse-body ()
1733 "Send the message body to the browser."
1734 (interactive)
1735 (save-excursion
1736 (set-buffer rmail-buffer)
1737 (rmail-browse-body)))
1738
1739 (provide 'rmailsum) 1716 (provide 'rmailsum)
1740 1717
1741 ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1 1718 ;;; arch-tag: 556079ee-75c1-47f5-9884-2e0a0bc6c5a1
1742 ;;; rmailsum.el ends here 1719 ;;; rmailsum.el ends here