annotate lisp/vm/vm-sort.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 441bb1e64a06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; Sorting and moving messages inside VM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Copyright (C) 1993, 1994 Kyle E. Jones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; the Free Software Foundation; either version 1, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 (provide 'vm-sort)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 (defun vm-move-message-forward (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 "Move a message forward in a VM folder.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 Prefix arg COUNT causes the current message to be moved COUNT messages forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 A negative COUNT causes movement to be backward instead of forward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 COUNT defaults to 1. The current message remains selected after being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 moved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 If vm-move-messages-physically is non-nil, the physical copy of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 the message in the folder is moved. A nil value means just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 change the presentation order and leave the physical order of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 the folder undisturbed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (vm-follow-summary-cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (vm-error-if-folder-empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (if vm-move-messages-physically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (vm-error-if-folder-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (vm-display nil nil '(vm-move-message-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 vm-move-message-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 vm-move-message-forward-physically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 vm-move-message-backward-physically)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (list this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (let* ((ovmp vm-message-pointer) vmp-prev ovmp-prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (vm-message-pointer vm-message-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (direction (if (> count 0) 'forward 'backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (count (vm-abs count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (while (not (zerop count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (vm-move-message-pointer direction)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (vm-decrement count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (if (> (string-to-int (vm-number-of (car vm-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (string-to-int (vm-number-of (car ovmp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (setq vm-message-pointer (cdr vm-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (if (eq vm-message-pointer ovmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (if (null vm-message-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (setq vmp-prev (vm-last vm-message-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (setq vmp-prev (vm-reverse-link-of (car vm-message-pointer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (setq ovmp-prev (vm-reverse-link-of (car ovmp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; lock out interrupts to preserve message list integrity.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (if ovmp-prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (setcdr ovmp-prev (cdr ovmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (and (cdr ovmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (vm-set-reverse-link-of (car (cdr ovmp)) ovmp-prev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq vm-message-list (cdr ovmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (vm-set-reverse-link-of (car vm-message-list) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if vmp-prev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (setcdr vmp-prev ovmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (vm-set-reverse-link-of (car ovmp) vmp-prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (setq vm-message-list ovmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (vm-set-reverse-link-of (car vm-message-list) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setcdr ovmp vm-message-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (and vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (vm-set-reverse-link-of (car vm-message-pointer) ovmp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (if (and vm-move-messages-physically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (not (eq major-mode 'vm-virtual-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (vm-physically-move-message (car ovmp) (car vm-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq vm-ml-sort-keys nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (if (not vm-folder-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (setq vm-message-order-changed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (vm-set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (vm-clear-modification-flag-undos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (cond ((null ovmp-prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq vm-numbering-redo-start-point vm-message-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 vm-numbering-redo-end-point vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 vm-summary-pointer (car vm-message-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ((null vmp-prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq vm-numbering-redo-start-point vm-message-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 vm-numbering-redo-end-point (cdr ovmp-prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 vm-summary-pointer (car ovmp-prev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ((or (not vm-message-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (< (string-to-int (vm-number-of (car ovmp-prev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (string-to-int (vm-number-of (car vm-message-pointer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq vm-numbering-redo-start-point (cdr ovmp-prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 vm-numbering-redo-end-point (cdr ovmp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 vm-summary-pointer (car (cdr ovmp-prev))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq vm-numbering-redo-start-point ovmp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 vm-numbering-redo-end-point (cdr ovmp-prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 vm-summary-pointer (car ovmp-prev))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (if vm-summary-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (let (list mp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (vm-copy-local-variables vm-summary-buffer 'vm-summary-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq vm-need-summary-pointer-update t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq mp vm-numbering-redo-start-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (while (not (eq mp vm-numbering-redo-end-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (vm-mark-for-summary-update (car mp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq list (cons (car mp) list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 mp (cdr mp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (vm-mapc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (lambda (m p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (vm-set-su-start-of m (car p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (vm-set-su-end-of m (car (cdr p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq list (nreverse list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (lambda (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (list (vm-su-start-of p) (vm-su-end-of p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (lambda (p q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (< (car p) (car q))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if vm-move-messages-physically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; clip region is messed up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (vm-preview-current-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (vm-update-summary-and-mode-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun vm-move-message-backward (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "Move a message backward in a VM folder.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Prefix arg COUNT causes the current message to be moved COUNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 messages backward. A negative COUNT causes movement to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 forward instead of backward. COUNT defaults to 1. The current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 message remains selected after being moved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 If vm-move-messages-physically is non-nil, the physical copy of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 the message in the folder is moved. A nil value means just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 change the presentation order and leave the physical order of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 the folder undisturbed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (vm-move-message-forward (- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defun vm-move-message-forward-physically (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "Like vm-move-message-forward but always move the message physically."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let ((vm-move-messages-physically t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (vm-move-message-forward count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (defun vm-move-message-backward-physically (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 "Like vm-move-message-backward but always move the message physically."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let ((vm-move-messages-physically t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (vm-move-message-backward count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; move message m to be before m-dest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; and fix up the location markers afterwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; m better not equal m-dest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; of m-dest is nil, move m to the end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; consider carefully the effects of insertion on markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; and variables containg markers before you modify this code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defun vm-physically-move-message (m m-dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (vm-save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; Make sure vm-headers-of and vm-text-of are non-nil in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; their slots before we try to move them. (Simply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; referencing the slot with their slot function is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; sufficient to guarantee this.) Otherwise, they be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; initialized in the middle of the message move and get the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; offset applied to them twice by way of a relative offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; from one of the other location markers that has already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; been moved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Also, and more importantly, vm-vheaders-of might run
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; vm-reorder-message-headers, which can add text to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; message. This MUST NOT happen after offsets have been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; computed for the message move or varying levels of chaos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; will ensue. In the case of BABYL files, where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; vm-reorder-message-headers can add a lot of new text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; folder curroption can be massive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (vm-text-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (vm-vheaders-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (let ((dest-start (if m-dest (vm-start-of m-dest) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 offset doomed-start doomed-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (goto-char dest-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (insert-buffer-substring (current-buffer) (vm-start-of m) (vm-end-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq doomed-start (marker-position (vm-start-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 doomed-end (marker-position (vm-end-of m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 offset (- (vm-start-of m) dest-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (set-marker (vm-start-of m) (- (vm-start-of m) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (set-marker (vm-headers-of m) (- (vm-headers-of m) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (set-marker (vm-text-end-of m) (- (vm-text-end-of m) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (set-marker (vm-end-of m) (- (vm-end-of m) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (set-marker (vm-text-of m) (- (vm-text-of m) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (set-marker (vm-vheaders-of m) (- (vm-vheaders-of m) offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; now fix the start of m-dest since it didn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; move forward with its message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (and m-dest (set-marker (vm-start-of m-dest) (vm-end-of m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; delete the old copy of the message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (delete-region doomed-start doomed-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun vm-so-sortable-datestring (m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (or (vm-sortable-datestring-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (vm-set-sortable-datestring-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (timezone-make-date-sortable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (or (vm-get-header-contents m "Date:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (vm-grok-From_-date m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Thu, 1 Jan 1970 00:00:00 GMT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "GMT" "GMT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (vm-sortable-datestring-of m))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (defun vm-so-sortable-subject (m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (or (vm-sortable-subject-of m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (vm-set-sortable-subject-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 m
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (let ((case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (subject (vm-su-subject m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (and vm-subject-ignored-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (string-match vm-subject-ignored-prefix subject)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (zerop (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq subject (substring subject (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (if (and vm-subject-ignored-suffix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (string-match vm-subject-ignored-suffix subject)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (= (match-end 0) (length subject)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq subject (substring subject 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 subject ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (vm-sortable-subject-of m))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun vm-sort-messages (keys &optional lets-get-physical)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Sort message in a folder by the specified KEYS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 You may sort by more than one particular message key. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 messages compare equal by the first key, the second key will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 compared and so on. When called interactively the keys will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 read from the minibuffer. Valid keys are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 \"date\" \"reversed-date\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 \"author\" \"reversed-author\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 \"subject\" \"reversed-subject\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 \"recipients\" \"reversed-recipients\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 \"line-count\" \"reversed-line-count\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 \"byte-count\" \"reversed-byte-count\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 \"physical-order\" \"reversed-physical-order\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 Optional second arg (prefix arg interactively) means the sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 should change the physical order of the messages in the folder.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 Normally VM changes presentation order only, leaving the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 folder in the order in which the messages arrived."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (let ((last-command last-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (this-command this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (list (vm-read-string (if (or current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 vm-move-messages-physically)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 "Physically sort messages by: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "Sort messages by: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 vm-supported-sort-keys t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (vm-select-folder-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (vm-check-for-killed-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; only squawk if interactive. The thread display uses this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; function and doesn't expect errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (vm-error-if-folder-empty))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; ditto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if (and (interactive-p) (or vm-move-messages-physically lets-get-physical))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (vm-error-if-folder-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (vm-display nil nil '(vm-sort-messages) '(vm-sort-messages))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (let (key-list key-funcs key ml-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 physical-order-list old-message-list new-message-list mp-old mp-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 old-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 doomed-start doomed-end offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (order-did-change nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 virtual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 physical)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (setq key-list (vm-parse keys "[ \t]*\\([^ \t]+\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ml-keys (and key-list (mapconcat (function identity) key-list "/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 key-funcs nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 old-message-list vm-message-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 virtual (eq major-mode 'vm-virtual-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 physical (and (or lets-get-physical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 vm-move-messages-physically)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (not vm-folder-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (not virtual)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (or key-list (error "No sort keys specified."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (while key-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setq key (car key-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (cond ((equal key "thread")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (vm-build-threads-if-unbuilt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (setq key-funcs (cons 'vm-sort-compare-thread key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ((equal key "author")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq key-funcs (cons 'vm-sort-compare-author key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ((equal key "reversed-author")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq key-funcs (cons 'vm-sort-compare-author-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ((equal key "date")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (setq key-funcs (cons 'vm-sort-compare-date key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ((equal key "reversed-date")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq key-funcs (cons 'vm-sort-compare-date-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ((equal key "subject")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq key-funcs (cons 'vm-sort-compare-subject key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ((equal key "reversed-subject")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (setq key-funcs (cons 'vm-sort-compare-subject-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 ((equal key "recipients")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (setq key-funcs (cons 'vm-sort-compare-recipients key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ((equal key "reversed-recipients")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (setq key-funcs (cons 'vm-sort-compare-recipients-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ((equal key "byte-count")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (setq key-funcs (cons 'vm-sort-compare-byte-count key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ((equal key "reversed-byte-count")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq key-funcs (cons 'vm-sort-compare-byte-count-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ((equal key "line-count")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq key-funcs (cons 'vm-sort-compare-line-count key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ((equal key "reversed-line-count")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (setq key-funcs (cons 'vm-sort-compare-line-count-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ((equal key "physical-order")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (setq key-funcs (cons 'vm-sort-compare-physical-order key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ((equal key "reversed-physical-order")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (setq key-funcs (cons 'vm-sort-compare-physical-order-r key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (t (error "Unknown key: %s" key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (setq key-list (cdr key-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (vm-unsaved-message "Sorting...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((vm-key-functions (nreverse key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq new-message-list (sort (copy-sequence old-message-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 'vm-sort-compare-xxxxxx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ;; only need to do this sort if we're going to physically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; move messages later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if physical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (setq vm-key-functions '(vm-sort-compare-physical-order)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 physical-order-list (sort (copy-sequence old-message-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 'vm-sort-compare-xxxxxx))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (vm-unsaved-message "Sorting... done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (setq mp-old old-message-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 mp-new new-message-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (while mp-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (if (eq (car mp-old) (car mp-new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (setq mp-old (cdr mp-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 mp-new (cdr mp-new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (setq order-did-change t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; unless a full redo has been requested, the numbering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; start point now points to a cons in the old message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; list. therefore we just change the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; directly to avoid the list scan that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; vm-set-numbering-redo-start-point does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (cond ((not (eq vm-numbering-redo-start-point t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq vm-numbering-redo-start-point mp-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 vm-numbering-redo-end-point nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (if vm-summary-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (setq vm-need-summary-pointer-update t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; same logic as numbering reset above...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (cond ((not (eq vm-summary-redo-start-point t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (setq vm-summary-redo-start-point mp-new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ;; start point of this message's summary is now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;; wrong relative to where it is in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; message list. fix it and the summary rebuild
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; will take care of the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (vm-set-su-start-of (car mp-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (vm-su-start-of (car mp-old)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (setq mp-new nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (if (and order-did-change physical)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; the folder is being physically ordered so we don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ;; need a message order header to be stuffed, nor do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 ;; we need to retain one in the folder buffer. so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ;; strip out any existing message order header and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ;; say there are no changes to prevent a message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; order header from being stuffed later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (vm-remove-message-order)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq vm-message-order-changed nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (vm-unsaved-message "Moving messages... ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (setq mp-old physical-order-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 mp-new new-message-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (setq old-start (vm-start-of (car mp-old)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (while mp-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (if (< (vm-start-of (car mp-old)) old-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; already moved this message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (setq mp-old (cdr mp-old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (if (eq (car mp-old) (car mp-new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (setq mp-old (cdr mp-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 mp-new (cdr mp-new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ;; move message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (vm-physically-move-message (car mp-new) (car mp-old))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 ;; record start position. if vm-start-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; mp-old ever becomes less than old-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; we're running into messages that have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; already been moved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq old-start (vm-start-of (car mp-old)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ;; move mp-new but not mp-old because we moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;; mp-old down one message by inserting a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 ;; message in front of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq mp-new (cdr mp-new)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (vm-unsaved-message "Moving messages... done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (vm-set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (vm-clear-modification-flag-undos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (if (and order-did-change (not vm-folder-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (setq vm-message-order-changed t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (vm-set-buffer-modified-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (vm-clear-modification-flag-undos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (setq vm-ml-sort-keys ml-keys)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (intern (buffer-name) vm-buffers-needing-display-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (cond (order-did-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (setq vm-message-list new-message-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (vm-reverse-link-messages)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (setq vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (or (cdr (vm-reverse-link-of (car vm-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 vm-message-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (if vm-last-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (setq vm-last-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (or (cdr (vm-reverse-link-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (car vm-last-message-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 vm-message-list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (if (and vm-message-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 order-did-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (or lets-get-physical vm-move-messages-physically))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ;; clip region is most likely messed up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (vm-preview-current-message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (vm-update-summary-and-mode-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defun vm-sort-compare-xxxxxx (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (let ((key-funcs vm-key-functions) result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (while (and key-funcs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (eq '= (setq result (funcall (car key-funcs) m1 m2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (setq key-funcs (cdr key-funcs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (and key-funcs result) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (defun vm-sort-compare-thread (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (let ((list1 (vm-th-thread-list m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (list2 (vm-th-thread-list m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (if (not (eq (car list1) (car list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (let ((date1 (get (car list1) 'oldest-date))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (date2 (get (car list2) 'oldest-date)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (cond ((string-lessp date1 date2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ((string-equal date1 date2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (while (and list1 list2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (cond ((string-lessp (car list1) (car list2)) (throw 'done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ((not (string-equal (car list1) (car list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (throw 'done nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (setq list1 (cdr list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 list2 (cdr list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (cond ((and list1 (not list2)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ((and list2 (not list1)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (t '=))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (defun vm-sort-compare-author (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (let ((s1 (vm-su-from m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (s2 (vm-su-from m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (cond ((string-lessp s1 s2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defun vm-sort-compare-author-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (let ((s1 (vm-su-from m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (s2 (vm-su-from m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (cond ((string-lessp s1 s2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (defun vm-sort-compare-date (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (let ((s1 (vm-so-sortable-datestring m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (s2 (vm-so-sortable-datestring m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (cond ((string-lessp s1 s2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (defun vm-sort-compare-date-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (let ((s1 (vm-so-sortable-datestring m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (s2 (vm-so-sortable-datestring m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (cond ((string-lessp s1 s2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun vm-sort-compare-recipients (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (let ((s1 (vm-su-to m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (s2 (vm-su-to m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (cond ((string-lessp s1 s2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (defun vm-sort-compare-recipients-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (let ((s1 (vm-su-to m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (s2 (vm-su-to m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (cond ((string-lessp s1 s2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (defun vm-sort-compare-subject (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (let ((s1 (vm-so-sortable-subject m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (s2 (vm-so-sortable-subject m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (cond ((string-lessp s1 s2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (defun vm-sort-compare-subject-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (let ((s1 (vm-so-sortable-subject m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (s2 (vm-so-sortable-subject m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (cond ((string-lessp s1 s2) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ((string-equal s1 s2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (defun vm-sort-compare-line-count (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (let ((n1 (string-to-int (vm-su-line-count m1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (n2 (string-to-int (vm-su-line-count m2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (cond ((< n1 n2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ((= n1 n2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (defun vm-sort-compare-line-count-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (let ((n1 (string-to-int (vm-su-line-count m1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (n2 (string-to-int (vm-su-line-count m2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (cond ((> n1 n2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ((= n1 n2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (defun vm-sort-compare-byte-count (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (let ((n1 (string-to-int (vm-su-byte-count m1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (n2 (string-to-int (vm-su-byte-count m2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (cond ((< n1 n2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ((= n1 n2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (defun vm-sort-compare-byte-count-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (let ((n1 (string-to-int (vm-su-byte-count m1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (n2 (string-to-int (vm-su-byte-count m2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (cond ((> n1 n2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ((= n1 n2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (defun vm-sort-compare-physical-order (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (let ((n1 (vm-start-of m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (n2 (vm-start-of m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (cond ((< n1 n2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ((= n1 n2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defun vm-sort-compare-physical-order-r (m1 m2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (let ((n1 (vm-start-of m1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (n2 (vm-start-of m2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (cond ((> n1 n2) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ((= n1 n2) '=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (t nil))))