annotate lisp/mail/rmailsort.el @ 110402:c848ff4a679b

* lisp/obsolete/old-whitespace.el (whitespace-rescan-files-in-buffers): Use with-current-buffer.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 18 Sep 2010 00:28:10 +0200
parents 280c8ae2476d
children 417b1e4d63cd
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
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
9 ;; Package: rmail
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
10
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
12
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
13 ;; 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
14 ;; 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
15 ;; 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
16 ;; (at your option) any later version.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
17
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
18 ;; 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
19 ;; 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
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
22
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
23 ;; 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
24 ;; 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
25
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
26 ;;; Commentary:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
27
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
28 ;; Functions for sorting messages in an Rmail buffer.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
29
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
30 ;;; Code:
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
31
101918
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
32 (require 'rmail)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
33
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
34 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
35 (defun rmail-sort-by-date (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
36 "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
37 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
38 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
39 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
40 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
41 (rmail-make-date-sortable
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
42 (rmail-get-header "Date" msg)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
43
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
44 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
45 (defun rmail-sort-by-subject (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
46 "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
47 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
48 non-nil, sorts in reverse order."
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
49 ;; Note this is a case-sensitive sort.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
50 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
51 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
52 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
53 (let ((key (or (rmail-get-header "Subject" msg) ""))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
54 (case-fold-search t))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
55 ;; Remove `Re:'
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
56 (if (string-match "^\\(re:[ \t]*\\)*" key)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
57 (substring key (match-end 0))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
58 key)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
59
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
60 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
61 (defun rmail-sort-by-author (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
62 "Sort messages of current Rmail buffer by author.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
63 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
64 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
65 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
66 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
67 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
68 (downcase ; canonical name
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
69 (mail-strip-quoted-names
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
70 (or (rmail-get-header "From" msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
71 (rmail-get-header "Sender" msg) ""))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
72
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
73 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
74 (defun rmail-sort-by-recipient (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
75 "Sort messages of current Rmail buffer by recipient.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
76 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
77 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
78 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
79 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
80 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
81 (downcase ; canonical name
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
82 (mail-strip-quoted-names
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
83 (or (rmail-get-header "To" msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
84 (rmail-get-header "Apparently-To" msg) ""))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
85
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
86 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
87 (defun rmail-sort-by-correspondent (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
88 "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
89 This uses either the \"From\", \"Sender\", \"To\", or
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
90 \"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
91 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
92 REVERSE is non-nil, sorts in reverse order."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
93 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
94 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
95 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
96 (downcase
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
97 (rmail-select-correspondent
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
98 msg
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
99 '("From" "Sender" "To" "Apparently-To"))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
100
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
101 (defun rmail-select-correspondent (msg fields)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
102 "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
103 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
104 (let ((ans ""))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
105 (while (and fields (string= ans ""))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
106 (setq ans
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
107 ;; 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
108 (rmail-dont-reply-to
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
109 (mail-strip-quoted-names
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
110 (or (rmail-get-header (car fields) msg) ""))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
111 (setq fields (cdr fields)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
112 ans))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
113
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
114 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
115 (defun rmail-sort-by-lines (reverse)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
116 "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
117 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
118 (interactive "P")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
119 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
120 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
121 (count-lines (rmail-msgbeg msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
122 (rmail-msgend msg)))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
123
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
124 ;;;###autoload
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
125 (defun rmail-sort-by-labels (reverse labels)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
126 "Sort messages of current Rmail buffer by labels.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
127 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
128 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
129 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
130 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
131 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
132 (interactive "P\nsSort by labels: ")
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
133 (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
134 (error "No labels specified"))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
135 ;; Remove leading whitespace, add trailing comma.
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
136 (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
137 (let (labelvec nmax)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
138 ;; Convert "l1,..." into "\\(, \\|\\`\\)l1\\(,\\|\\'\\)" "..." ...
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
139 (while (string-match "[ \t]*,[ \t]*" labels)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
140 (setq labelvec (cons
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
141 (concat "\\(, \\|\\`\\)"
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
142 (substring labels 0 (match-beginning 0))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
143 "\\(,\\|\\'\\)")
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
144 labelvec))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
145 (setq labels (substring labels (match-end 0))))
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
146 (setq labelvec (apply 'vector (nreverse labelvec))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
147 nmax (length labelvec))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
148 (rmail-sort-messages reverse
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
149 ;; If no labels match, returns nmax; if they
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
150 ;; match the first specified in LABELS,
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
151 ;; 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
152 ;; Hence sorts as described in the doc-string.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
153 (lambda (msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
154 (let ((n 0)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
155 (str (concat (rmail-get-attr-names msg)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
156 ", "
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
157 (rmail-get-keywords msg))))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
158 ;; No labels: can't match anything.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
159 (if (string-equal ", " str)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
160 nmax
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
161 (while (and (< n nmax)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
162 (not (string-match (aref labelvec n)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
163 str)))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
164 (setq n (1+ n)))
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
165 n))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
166
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
167 ;; Basic functions
101918
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
168 (declare-function rmail-update-summary "rmailsum" (&rest ignore))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
169
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
170 (defun rmail-sort-messages (reverse keyfun)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
171 "Sort messages of current Rmail buffer.
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
172 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
173 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
174 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
175 (with-current-buffer rmail-buffer
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
176 (let ((return-to-point
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
177 (if (rmail-buffers-swapped-p)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
178 (point)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
179 (sort-lists nil))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
180 (rmail-swap-buffers-maybe)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
181 (message "Finding sort keys...")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
182 (widen)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
183 (let ((msgnum 1))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
184 (while (>= rmail-total-messages msgnum)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
185 (setq sort-lists
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
186 (cons (list (funcall keyfun msgnum) ;Make sorting key
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
187 (eq rmail-current-message msgnum) ;True if current
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
188 (aref rmail-message-vector msgnum)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
189 (aref rmail-message-vector (1+ msgnum)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
190 sort-lists))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
191 (if (zerop (% msgnum 10))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
192 (message "Finding sort keys...%d" msgnum))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
193 (setq msgnum (1+ msgnum))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
194 (or reverse (setq sort-lists (nreverse sort-lists)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
195 (setq sort-lists
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
196 (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
197 ;; 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
198 (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
199 'car-less-than-car
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
200 (lambda (a b)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
201 (string-lessp (car a) (car b))))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
202 (if reverse (setq sort-lists (nreverse sort-lists)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
203 ;; 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
204 (message "Reordering messages...")
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
205 (let ((inhibit-quit t) ;Inhibit quit
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
206 (inhibit-read-only t)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
207 (current-message nil)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
208 (msgnum 1)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
209 (msginfo nil)
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
210 (undo (not (eq buffer-undo-list t))))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
211 ;; 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
212 (buffer-disable-undo (current-buffer))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
213 (goto-char (rmail-msgbeg 1))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
214 ;; To force update of all markers,
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
215 ;; 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
216 (insert-before-markers ?Z)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
217 (backward-char 1)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
218 ;; Now reorder messages.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
219 (dolist (msginfo sort-lists)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
220 ;; Swap two messages.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
221 (insert-buffer-substring
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
222 (current-buffer) (nth 2 msginfo) (nth 3 msginfo))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
223 ;; 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
224 (rmail-ensure-blank-line)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
225 (delete-region (nth 2 msginfo) (nth 3 msginfo))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
226 ;; Is current message?
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
227 (if (nth 1 msginfo)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
228 (setq current-message msgnum))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
229 (if (zerop (% msgnum 10))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
230 (message "Reordering messages...%d" msgnum))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
231 (setq msgnum (1+ msgnum)))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
232 ;; Delete the dummy separator Z inserted before.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
233 (delete-char 1)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
234 (setq quit-flag nil)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
235 ;; 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
236 ;; 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
237 (if undo (buffer-enable-undo))
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
238 (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
239 (rmail-show-message-1 current-message)
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
240 (if return-to-point
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
241 (goto-char return-to-point))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
242 (if (rmail-summary-exists)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
243 (rmail-select-summary (rmail-update-summary)))))))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
244
101918
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
245 (autoload 'timezone-make-date-sortable "timezone")
97184480e9dc Just require rmail.
Glenn Morris <rgm@gnu.org>
parents: 101725
diff changeset
246
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
247 (defun rmail-make-date-sortable (date)
102387
7592f552ba10 Replace `(function (lambda' by `(lambda' throughout.
Glenn Morris <rgm@gnu.org>
parents: 101993
diff changeset
248 "Make DATE sortable using the function `string-lessp'."
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
249 ;; Assume the default time zone is GMT.
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
250 (timezone-make-date-sortable date "GMT" "GMT"))
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
251
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
252 (provide 'rmailsort)
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
253
104907
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
254 ;; Local Variables:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
255 ;; generated-autoload-file: "rmail.el"
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
256 ;; End:
6a35503cf20b Put autoloads in rmail.el rather than loaddefs.el.
Glenn Morris <rgm@gnu.org>
parents: 102406
diff changeset
257
101360
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
258 ;; arch-tag: 665da245-f6a7-4115-ad8c-ba19216988d5
b10df8502c4a Renamed all pmail* files to rmail*.
Bastien Guerry <bzg@altern.org>
parents:
diff changeset
259 ;;; rmailsort.el ends here