annotate lisp/mail/rmailsort.el @ 111159:89ed069d5e26

* lisp/erc/erc-backend.el (erc-process-sentinel): Check that buffer is alive before setting it as current buffer.
author Glenn Morris <rgm@gnu.org>
date Sat, 23 Oct 2010 12:35:22 -0700
parents 1d1d5d9bd884
children 280c8ae2476d 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
1 ;;; rmailsort.el --- Rmail: sort messages
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
2
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
3 ;; Copyright (C) 1990, 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 104907
diff changeset
4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
5
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
6 ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
7 ;; Maintainer: FSF
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
8 ;; Keywords: mail
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
9
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
11
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
15 ;; (at your option) any later version.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
16
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
21
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
24
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
25 ;;; Commentary:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
26
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
27 ;; Functions for sorting messages in an Rmail buffer.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
28
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
29 ;;; Code:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
30
101918
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
31 (require 'rmail)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
32
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
33 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
34 (defun rmail-sort-by-date (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
35 "Sort messages of current Rmail buffer by \"Date\" header.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
36 If prefix argument REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
37 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
38 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
39 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
40 (rmail-make-date-sortable
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
41 (rmail-get-header "Date" msg)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
42
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
43 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
44 (defun rmail-sort-by-subject (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
45 "Sort messages of current Rmail buffer by \"Subject\" header.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
46 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
47 non-nil, sorts in reverse order."
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
48 ;; Note this is a case-sensitive sort.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
49 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
50 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
51 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
52 (let ((key (or (rmail-get-header "Subject" msg) ""))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
53 (case-fold-search t))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
54 ;; Remove `Re:'
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
55 (if (string-match "^\\(re:[ \t]*\\)*" key)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
56 (substring key (match-end 0))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
57 key)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
58
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
59 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
60 (defun rmail-sort-by-author (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
61 "Sort messages of current Rmail buffer by author.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
62 This uses either the \"From\" or \"Sender\" header, downcased.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
63 If prefix argument REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
64 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
65 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
66 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
67 (downcase ; canonical name
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
68 (mail-strip-quoted-names
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
69 (or (rmail-get-header "From" msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
70 (rmail-get-header "Sender" msg) ""))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
71
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
72 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
73 (defun rmail-sort-by-recipient (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
74 "Sort messages of current Rmail buffer by recipient.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
75 This uses either the \"To\" or \"Apparently-To\" header, downcased.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
76 If prefix argument REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
77 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
78 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
79 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
80 (downcase ; canonical name
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
81 (mail-strip-quoted-names
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
82 (or (rmail-get-header "To" msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
83 (rmail-get-header "Apparently-To" msg) ""))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
84
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
85 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
86 (defun rmail-sort-by-correspondent (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
87 "Sort messages of current Rmail buffer by other correspondent.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
88 This uses either the \"From\", \"Sender\", \"To\", or
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
89 \"Apparently-To\" header, downcased. Uses the first header not
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
90 excluded by `rmail-dont-reply-to-names'. If prefix argument
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
91 REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
92 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
93 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
94 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
95 (downcase
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
96 (rmail-select-correspondent
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
97 msg
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
98 '("From" "Sender" "To" "Apparently-To"))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
99
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
100 (defun rmail-select-correspondent (msg fields)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
101 "Find the first header not excluded by `rmail-dont-reply-to-names'.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
102 MSG is a message number. FIELDS is a list of header names."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
103 (let ((ans ""))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
104 (while (and fields (string= ans ""))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
105 (setq ans
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
106 ;; NB despite the name, this lives in mail-utils.el.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
107 (rmail-dont-reply-to
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
108 (mail-strip-quoted-names
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
109 (or (rmail-get-header (car fields) msg) ""))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
110 (setq fields (cdr fields)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
111 ans))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
112
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
113 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
114 (defun rmail-sort-by-lines (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
115 "Sort messages of current Rmail buffer by the number of lines.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
116 If prefix argument REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
117 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
118 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
119 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
120 (count-lines (rmail-msgbeg msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
121 (rmail-msgend msg)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
122
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
123 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
124 (defun rmail-sort-by-labels (reverse labels)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
125 "Sort messages of current Rmail buffer by labels.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
126 LABELS is a comma-separated list of labels. The order of these
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
127 labels specifies the order of messages: messages with the first
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
128 label come first, messages with the second label come second, and
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
129 so on. Messages that have none of these labels come last.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
130 If prefix argument REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
131 (interactive "P\nsSort by labels: ")
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
132 (or (string-match "[^ \t]" labels) ; need some non-whitespace
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
133 (error "No labels specified"))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
134 ;; Remove leading whitespace, add trailing comma.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
135 (setq labels (concat (substring labels (match-beginning 0)) ","))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
136 (let (labelvec nmax)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
137 ;; Convert "l1,..." into "\\(, \\|\\`\\)l1\\(,\\|\\'\\)" "..." ...
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
138 (while (string-match "[ \t]*,[ \t]*" labels)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
139 (setq labelvec (cons
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
140 (concat "\\(, \\|\\`\\)"
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
141 (substring labels 0 (match-beginning 0))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
142 "\\(,\\|\\'\\)")
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
143 labelvec))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
144 (setq labels (substring labels (match-end 0))))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
145 (setq labelvec (apply 'vector (nreverse labelvec))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
146 nmax (length labelvec))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
147 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
148 ;; If no labels match, returns nmax; if they
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
149 ;; match the first specified in LABELS,
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
150 ;; returns 0; if they match the second, returns 1; etc.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
151 ;; Hence sorts as described in the doc-string.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
152 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
153 (let ((n 0)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
154 (str (concat (rmail-get-attr-names msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
155 ", "
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
156 (rmail-get-keywords msg))))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
157 ;; No labels: can't match anything.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
158 (if (string-equal ", " str)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
159 nmax
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
160 (while (and (< n nmax)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
161 (not (string-match (aref labelvec n)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
162 str)))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
163 (setq n (1+ n)))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
164 n))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
165
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
166 ;; Basic functions
101918
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
167 (declare-function rmail-update-summary "rmailsum" (&rest ignore))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
168
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
169 (defun rmail-sort-messages (reverse keyfun)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
170 "Sort messages of current Rmail buffer.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
171 If REVERSE is non-nil, sorts in reverse order. Calls the
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
172 function KEYFUN with a message number (it should return a sort key).
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
173 Numeric keys are sorted numerically, all others as strings."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
174 (with-current-buffer rmail-buffer
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
175 (let ((return-to-point
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
176 (if (rmail-buffers-swapped-p)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
177 (point)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
178 (sort-lists nil))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
179 (rmail-swap-buffers-maybe)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
180 (message "Finding sort keys...")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
181 (widen)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
182 (let ((msgnum 1))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
183 (while (>= rmail-total-messages msgnum)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
184 (setq sort-lists
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
185 (cons (list (funcall keyfun msgnum) ;Make sorting key
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
186 (eq rmail-current-message msgnum) ;True if current
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
187 (aref rmail-message-vector msgnum)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
188 (aref rmail-message-vector (1+ msgnum)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
189 sort-lists))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
190 (if (zerop (% msgnum 10))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
191 (message "Finding sort keys...%d" msgnum))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
192 (setq msgnum (1+ msgnum))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
193 (or reverse (setq sort-lists (nreverse sort-lists)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
194 (setq sort-lists
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
195 (sort sort-lists
101725
9e2e923d8eb3 (rmail-sort-messages): Use car-less-than-car if possible.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101377
diff changeset
196 ;; Decide predicate: < or string-lessp
9e2e923d8eb3 (rmail-sort-messages): Use car-less-than-car if possible.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101377
diff changeset
197 (if (numberp (car (car sort-lists))) ;Is a key numeric?
9e2e923d8eb3 (rmail-sort-messages): Use car-less-than-car if possible.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101377
diff changeset
198 'car-less-than-car
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
199 (lambda (a b)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
200 (string-lessp (car a) (car b))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
201 (if reverse (setq sort-lists (nreverse sort-lists)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
202 ;; Now we enter critical region. So, keyboard quit is disabled.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
203 (message "Reordering messages...")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
204 (let ((inhibit-quit t) ;Inhibit quit
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
205 (inhibit-read-only t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
206 (current-message nil)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
207 (msgnum 1)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
208 (msginfo nil)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
209 (undo (not (eq buffer-undo-list t))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
210 ;; There's little hope that we can easily undo after that.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
211 (buffer-disable-undo (current-buffer))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
212 (goto-char (rmail-msgbeg 1))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
213 ;; To force update of all markers,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
214 ;; keep the new copies separated from the remaining old messages.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
215 (insert-before-markers ?Z)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
216 (backward-char 1)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
217 ;; Now reorder messages.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
218 (dolist (msginfo sort-lists)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
219 ;; Swap two messages.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
220 (insert-buffer-substring
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
221 (current-buffer) (nth 2 msginfo) (nth 3 msginfo))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
222 ;; The last message may not have \n\n after it.
102406
8717f0e9d25a (rmail-sort-messages): Use rmail-ensure-blank-line.
Glenn Morris <rgm@gnu.org>
parents: 102387
diff changeset
223 (rmail-ensure-blank-line)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
224 (delete-region (nth 2 msginfo) (nth 3 msginfo))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
225 ;; Is current message?
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
226 (if (nth 1 msginfo)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
227 (setq current-message msgnum))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
228 (if (zerop (% msgnum 10))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
229 (message "Reordering messages...%d" msgnum))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
230 (setq msgnum (1+ msgnum)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
231 ;; Delete the dummy separator Z inserted before.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
232 (delete-char 1)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
233 (setq quit-flag nil)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
234 ;; If undo was on before, re-enable it. But note that it is
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
235 ;; disabled in mbox Rmail, so this is kind of pointless.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
236 (if undo (buffer-enable-undo))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
237 (rmail-set-message-counters)
101993
1bb96ade4801 Update for rmail-show-message -> rmail-show-message-1 name change.
Glenn Morris <rgm@gnu.org>
parents: 101918
diff changeset
238 (rmail-show-message-1 current-message)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
239 (if return-to-point
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
240 (goto-char return-to-point))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
241 (if (rmail-summary-exists)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
242 (rmail-select-summary (rmail-update-summary)))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
243
101918
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
244 (autoload 'timezone-make-date-sortable "timezone")
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
245
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
246 (defun rmail-make-date-sortable (date)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
247 "Make DATE sortable using the function `string-lessp'."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
248 ;; Assume the default time zone is GMT.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
249 (timezone-make-date-sortable date "GMT" "GMT"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
250
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
251 (provide 'rmailsort)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
252
104907
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
253 ;; Local Variables:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
254 ;; generated-autoload-file: "rmail.el"
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
255 ;; End:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
256
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
257 ;; arch-tag: 665da245-f6a7-4115-ad8c-ba19216988d5
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
258 ;;; rmailsort.el ends here