aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2009-01-10 21:12:48 +0000
committerRichard M. Stallman2009-01-10 21:12:48 +0000
commit851a3f9261edd6f2170a4c5934f028733bc12e79 (patch)
tree8fa56e637973a7443603246f3e8b2cb83e21e1ea
parent29b51c384ba9e924be51f930f4b4e698991b77c4 (diff)
downloademacs-851a3f9261edd6f2170a4c5934f028733bc12e79.tar.gz
emacs-851a3f9261edd6f2170a4c5934f028733bc12e79.zip
(pmailhdr): Don't require it.
(pmail-fetch-field): Function deleted. Callers use pmail-get-header. (pmail-sort-messages): Replace point-offset with return-to-point, which can be nil. Call pmail-swap-buffers-maybe after that. Don't bind buffer-read-only. Bind inhibit-read-only. Be more careful in making blank line at end of msg. Don't enable undo at end.
-rw-r--r--lisp/mail/pmailsort.el47
1 files changed, 21 insertions, 26 deletions
diff --git a/lisp/mail/pmailsort.el b/lisp/mail/pmailsort.el
index d8af7bca2e0..d55e82118a2 100644
--- a/lisp/mail/pmailsort.el
+++ b/lisp/mail/pmailsort.el
@@ -31,8 +31,6 @@
31 (require 'sort) 31 (require 'sort)
32 (require 'pmail)) 32 (require 'pmail))
33 33
34(require 'pmailhdr)
35
36(autoload 'timezone-make-date-sortable "timezone") 34(autoload 'timezone-make-date-sortable "timezone")
37 35
38(declare-function pmail-update-summary "pmailsum" (&rest ignore)) 36(declare-function pmail-update-summary "pmailsum" (&rest ignore))
@@ -48,7 +46,7 @@ If prefix argument REVERSE is non-nil, sort them in reverse order."
48 (function 46 (function
49 (lambda (msg) 47 (lambda (msg)
50 (pmail-make-date-sortable 48 (pmail-make-date-sortable
51 (pmail-fetch-field msg "Date")))))) 49 (pmail-get-header "Date" msg))))))
52 50
53;;;###autoload 51;;;###autoload
54(defun pmail-sort-by-subject (reverse) 52(defun pmail-sort-by-subject (reverse)
@@ -58,7 +56,7 @@ If prefix argument REVERSE is non-nil, sort them in reverse order."
58 (pmail-sort-messages reverse 56 (pmail-sort-messages reverse
59 (function 57 (function
60 (lambda (msg) 58 (lambda (msg)
61 (let ((key (or (pmail-fetch-field msg "Subject") "")) 59 (let ((key (or (pmail-get-header "Subject" msg) ""))
62 (case-fold-search t)) 60 (case-fold-search t))
63 ;; Remove `Re:' 61 ;; Remove `Re:'
64 (if (string-match "^\\(re:[ \t]*\\)*" key) 62 (if (string-match "^\\(re:[ \t]*\\)*" key)
@@ -75,8 +73,8 @@ If prefix argument REVERSE is non-nil, sort them in reverse order."
75 (lambda (msg) 73 (lambda (msg)
76 (downcase ;Canonical name 74 (downcase ;Canonical name
77 (mail-strip-quoted-names 75 (mail-strip-quoted-names
78 (or (pmail-fetch-field msg "From") 76 (or (pmail-get-header "From" msg)
79 (pmail-fetch-field msg "Sender") ""))))))) 77 (pmail-get-header "Sender" msg) "")))))))
80 78
81;;;###autoload 79;;;###autoload
82(defun pmail-sort-by-recipient (reverse) 80(defun pmail-sort-by-recipient (reverse)
@@ -88,8 +86,8 @@ If prefix argument REVERSE is non-nil, sort them in reverse order."
88 (lambda (msg) 86 (lambda (msg)
89 (downcase ;Canonical name 87 (downcase ;Canonical name
90 (mail-strip-quoted-names 88 (mail-strip-quoted-names
91 (or (pmail-fetch-field msg "To") 89 (or (pmail-get-header "To" msg)
92 (pmail-fetch-field msg "Apparently-To") "") 90 (pmail-get-header "Apparently-To" msg) "")
93 )))))) 91 ))))))
94 92
95;;;###autoload 93;;;###autoload
@@ -111,7 +109,7 @@ If prefix argument REVERSE is non-nil, sort them in reverse order."
111 ;; NB despite the name, this lives in mail-utils.el. 109 ;; NB despite the name, this lives in mail-utils.el.
112 (rmail-dont-reply-to 110 (rmail-dont-reply-to
113 (mail-strip-quoted-names 111 (mail-strip-quoted-names
114 (or (pmail-fetch-field msg (car fields)) "")))) 112 (or (pmail-get-header (car fields) msg) ""))))
115 (setq fields (cdr fields))) 113 (setq fields (cdr fields)))
116 ans)) 114 ans))
117 115
@@ -160,12 +158,13 @@ KEYWORDS is a comma-separated list of labels."
160 "Sort messages of current Pmail file. 158 "Sort messages of current Pmail file.
161If 1st argument REVERSE is non-nil, sort them in reverse order. 159If 1st argument REVERSE is non-nil, sort them in reverse order.
1622nd argument KEYFUN is called with a message number, and should return a key." 1602nd argument KEYFUN is called with a message number, and should return a key."
163 (pmail-swap-buffers-maybe)
164 (with-current-buffer pmail-buffer 161 (with-current-buffer pmail-buffer
165 (let ((buffer-read-only nil) 162 (let ((return-to-point
166 (point-offset (- (point) (point-min))) 163 (if (pmail-buffers-swapped-p)
164 (point)))
167 (predicate nil) ;< or string-lessp 165 (predicate nil) ;< or string-lessp
168 (sort-lists nil)) 166 (sort-lists nil))
167 (pmail-swap-buffers-maybe)
169 (message "Finding sort keys...") 168 (message "Finding sort keys...")
170 (widen) 169 (widen)
171 (let ((msgnum 1)) 170 (let ((msgnum 1))
@@ -193,13 +192,15 @@ If 1st argument REVERSE is non-nil, sort them in reverse order.
193 ;; Now we enter critical region. So, keyboard quit is disabled. 192 ;; Now we enter critical region. So, keyboard quit is disabled.
194 (message "Reordering messages...") 193 (message "Reordering messages...")
195 (let ((inhibit-quit t) ;Inhibit quit 194 (let ((inhibit-quit t) ;Inhibit quit
195 (inhibit-read-only t)
196 (current-message nil) 196 (current-message nil)
197 (msgnum 1) 197 (msgnum 1)
198 (msginfo nil)) 198 (msginfo nil))
199 ;; There's little hope that we can easily undo after that. 199 ;; There's little hope that we can easily undo after that.
200 (buffer-disable-undo (current-buffer)) 200 (buffer-disable-undo (current-buffer))
201 (goto-char (pmail-msgbeg 1)) 201 (goto-char (pmail-msgbeg 1))
202 ;; To force update of all markers. 202 ;; To force update of all markers,
203 ;; keep the new copies separated from the remaining old messages.
203 (insert-before-markers ?Z) 204 (insert-before-markers ?Z)
204 (backward-char 1) 205 (backward-char 1)
205 ;; Now reorder messages. 206 ;; Now reorder messages.
@@ -208,8 +209,10 @@ If 1st argument REVERSE is non-nil, sort them in reverse order.
208 (insert-buffer-substring 209 (insert-buffer-substring
209 (current-buffer) (nth 2 msginfo) (nth 3 msginfo)) 210 (current-buffer) (nth 2 msginfo) (nth 3 msginfo))
210 ;; The last message may not have \n\n after it. 211 ;; The last message may not have \n\n after it.
211 (unless (eq (char-before) ?\n) 212 (unless (bobp)
212 (insert "\n\n")) 213 (insert "\n"))
214 (unless (looking-back "\n\n")
215 (insert "\n"))
213 (delete-region (nth 2 msginfo) (nth 3 msginfo)) 216 (delete-region (nth 2 msginfo) (nth 3 msginfo))
214 ;; Is current message? 217 ;; Is current message?
215 (if (nth 1 msginfo) 218 (if (nth 1 msginfo)
@@ -217,24 +220,16 @@ If 1st argument REVERSE is non-nil, sort them in reverse order.
217 (if (zerop (% msgnum 10)) 220 (if (zerop (% msgnum 10))
218 (message "Reordering messages...%d" msgnum)) 221 (message "Reordering messages...%d" msgnum))
219 (setq msgnum (1+ msgnum))) 222 (setq msgnum (1+ msgnum)))
220 ;; Delete the garbage inserted before. 223 ;; Delete the dummy separator Z inserted before.
221 (delete-char 1) 224 (delete-char 1)
222 (setq quit-flag nil) 225 (setq quit-flag nil)
223 (buffer-enable-undo)
224 (pmail-set-message-counters) 226 (pmail-set-message-counters)
225 (pmail-show-message current-message) 227 (pmail-show-message current-message)
226 (goto-char (+ point-offset (point-min))) 228 (if return-to-point
229 (goto-char return-to-point))
227 (if (pmail-summary-exists) 230 (if (pmail-summary-exists)
228 (pmail-select-summary (pmail-update-summary))))))) 231 (pmail-select-summary (pmail-update-summary)))))))
229 232
230(defun pmail-fetch-field (msg field)
231 "Return the value of the header FIELD of MSG.
232Arguments are MSG and FIELD."
233 (save-restriction
234 (widen)
235 (narrow-to-region (pmail-msgbeg msg) (pmail-msgend msg))
236 (pmail-header-get-header field)))
237
238(defun pmail-make-date-sortable (date) 233(defun pmail-make-date-sortable (date)
239 "Make DATE sortable using the function string-lessp." 234 "Make DATE sortable using the function string-lessp."
240 ;; Assume the default time zone is GMT. 235 ;; Assume the default time zone is GMT.