diff options
| author | Chong Yidong | 2008-12-04 22:48:57 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-12-04 22:48:57 +0000 |
| commit | 76cc2f62c07161c4b97a0becae3e9f05217a2cce (patch) | |
| tree | da41365a8fe5bc39671080cc434483f62a5f9153 | |
| parent | f76fa02a3b89a09ec0d4ef8d8ff6bf19dd0006d7 (diff) | |
| download | emacs-76cc2f62c07161c4b97a0becae3e9f05217a2cce.tar.gz emacs-76cc2f62c07161c4b97a0becae3e9f05217a2cce.zip | |
Sync with pmailsort.el.
(pmail-sort-messages): Insert two newlines at the end of the
message if they do not exist.
| -rw-r--r-- | lisp/mail/pmailsort.el | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/lisp/mail/pmailsort.el b/lisp/mail/pmailsort.el index 621cca86168..6396f2b3bfa 100644 --- a/lisp/mail/pmailsort.el +++ b/lisp/mail/pmailsort.el | |||
| @@ -29,7 +29,8 @@ | |||
| 29 | (eval-when-compile | 29 | (eval-when-compile |
| 30 | (require 'mail-utils) | 30 | (require 'mail-utils) |
| 31 | (require 'sort) | 31 | (require 'sort) |
| 32 | (require 'pmail)) | 32 | (require 'pmail) |
| 33 | (require 'pmailhdr)) | ||
| 33 | 34 | ||
| 34 | (autoload 'timezone-make-date-sortable "timezone") | 35 | (autoload 'timezone-make-date-sortable "timezone") |
| 35 | 36 | ||
| @@ -121,8 +122,8 @@ If prefix argument REVERSE is non-nil, sort them in reverse order." | |||
| 121 | (pmail-sort-messages reverse | 122 | (pmail-sort-messages reverse |
| 122 | (function | 123 | (function |
| 123 | (lambda (msg) | 124 | (lambda (msg) |
| 124 | (count-lines (pmail-desc-get-start msg) | 125 | (count-lines (pmail-msgbeg msg) |
| 125 | (pmail-desc-get-end msg)))))) | 126 | (pmail-msgend msg)))))) |
| 126 | 127 | ||
| 127 | ;;;###autoload | 128 | ;;;###autoload |
| 128 | (defun pmail-sort-by-labels (reverse labels) | 129 | (defun pmail-sort-by-labels (reverse labels) |
| @@ -158,10 +159,8 @@ KEYWORDS is a comma-separated list of labels." | |||
| 158 | "Sort messages of current Pmail file. | 159 | "Sort messages of current Pmail file. |
| 159 | If 1st argument REVERSE is non-nil, sort them in reverse order. | 160 | If 1st argument REVERSE is non-nil, sort them in reverse order. |
| 160 | 2nd argument KEYFUN is called with a message number, and should return a key." | 161 | 2nd argument KEYFUN is called with a message number, and should return a key." |
| 161 | (save-current-buffer | 162 | (pmail-swap-buffers-maybe) |
| 162 | ;; If we are in a summary buffer, operate on the Pmail buffer. | 163 | (with-current-buffer pmail-buffer |
| 163 | (if (eq major-mode 'pmail-summary-mode) | ||
| 164 | (set-buffer pmail-buffer)) | ||
| 165 | (let ((buffer-read-only nil) | 164 | (let ((buffer-read-only nil) |
| 166 | (point-offset (- (point) (point-min))) | 165 | (point-offset (- (point) (point-min))) |
| 167 | (predicate nil) ;< or string-lessp | 166 | (predicate nil) ;< or string-lessp |
| @@ -173,8 +172,8 @@ If 1st argument REVERSE is non-nil, sort them in reverse order. | |||
| 173 | (setq sort-lists | 172 | (setq sort-lists |
| 174 | (cons (list (funcall keyfun msgnum) ;Make sorting key | 173 | (cons (list (funcall keyfun msgnum) ;Make sorting key |
| 175 | (eq pmail-current-message msgnum) ;True if current | 174 | (eq pmail-current-message msgnum) ;True if current |
| 176 | (pmail-desc-get-start msgnum) | 175 | (aref pmail-message-vector msgnum) |
| 177 | (pmail-desc-get-end msgnum)) | 176 | (aref pmail-message-vector (1+ msgnum))) |
| 178 | sort-lists)) | 177 | sort-lists)) |
| 179 | (if (zerop (% msgnum 10)) | 178 | (if (zerop (% msgnum 10)) |
| 180 | (message "Finding sort keys...%d" msgnum)) | 179 | (message "Finding sort keys...%d" msgnum)) |
| @@ -198,21 +197,22 @@ If 1st argument REVERSE is non-nil, sort them in reverse order. | |||
| 198 | (msginfo nil)) | 197 | (msginfo nil)) |
| 199 | ;; There's little hope that we can easily undo after that. | 198 | ;; There's little hope that we can easily undo after that. |
| 200 | (buffer-disable-undo (current-buffer)) | 199 | (buffer-disable-undo (current-buffer)) |
| 201 | (goto-char (pmail-desc-get-start 1)) | 200 | (goto-char (pmail-msgbeg 1)) |
| 202 | ;; To force update of all markers. | 201 | ;; To force update of all markers. |
| 203 | (insert-before-markers ?Z) | 202 | (insert-before-markers ?Z) |
| 204 | (backward-char 1) | 203 | (backward-char 1) |
| 205 | ;; Now reorder messages. | 204 | ;; Now reorder messages. |
| 206 | (while sort-lists | 205 | (dolist (msginfo sort-lists) |
| 207 | (setq msginfo (car sort-lists)) | ||
| 208 | ;; Swap two messages. | 206 | ;; Swap two messages. |
| 209 | (insert-buffer-substring | 207 | (insert-buffer-substring |
| 210 | (current-buffer) (nth 2 msginfo) (nth 3 msginfo)) | 208 | (current-buffer) (nth 2 msginfo) (nth 3 msginfo)) |
| 211 | (delete-region (nth 2 msginfo) (nth 3 msginfo)) | 209 | ;; The last message may not have \n\n after it. |
| 210 | (unless (eq (char-before) ?\n) | ||
| 211 | (insert "\n\n")) | ||
| 212 | (delete-region (nth 2 msginfo) (nth 3 msginfo)) | ||
| 212 | ;; Is current message? | 213 | ;; Is current message? |
| 213 | (if (nth 1 msginfo) | 214 | (if (nth 1 msginfo) |
| 214 | (setq current-message msgnum)) | 215 | (setq current-message msgnum)) |
| 215 | (setq sort-lists (cdr sort-lists)) | ||
| 216 | (if (zerop (% msgnum 10)) | 216 | (if (zerop (% msgnum 10)) |
| 217 | (message "Reordering messages...%d" msgnum)) | 217 | (message "Reordering messages...%d" msgnum)) |
| 218 | (setq msgnum (1+ msgnum))) | 218 | (setq msgnum (1+ msgnum))) |
| @@ -220,22 +220,18 @@ If 1st argument REVERSE is non-nil, sort them in reverse order. | |||
| 220 | (delete-char 1) | 220 | (delete-char 1) |
| 221 | (setq quit-flag nil) | 221 | (setq quit-flag nil) |
| 222 | (buffer-enable-undo) | 222 | (buffer-enable-undo) |
| 223 | (goto-char (point-min)) | 223 | (pmail-set-message-counters) |
| 224 | (pmail-initialize-messages) | ||
| 225 | (pmail-show-message current-message) | 224 | (pmail-show-message current-message) |
| 225 | (goto-char (+ point-offset (point-min))) | ||
| 226 | (if (pmail-summary-exists) | 226 | (if (pmail-summary-exists) |
| 227 | (pmail-select-summary | 227 | (pmail-select-summary (pmail-update-summary))))))) |
| 228 | (pmail-update-summary))))))) | ||
| 229 | 228 | ||
| 230 | ;; mbox: ready | ||
| 231 | (defun pmail-fetch-field (msg field) | 229 | (defun pmail-fetch-field (msg field) |
| 232 | "Return the value of the header FIELD of MSG. | 230 | "Return the value of the header FIELD of MSG. |
| 233 | Arguments are MSG and FIELD." | 231 | Arguments are MSG and FIELD." |
| 234 | (save-restriction | 232 | (save-restriction |
| 235 | (widen) | 233 | (widen) |
| 236 | (narrow-to-region | 234 | (narrow-to-region (pmail-msgbeg msg) (pmail-msgend msg)) |
| 237 | (pmail-desc-get-start msg) | ||
| 238 | (pmail-desc-get-end msg)) | ||
| 239 | (pmail-header-get-header field))) | 235 | (pmail-header-get-header field))) |
| 240 | 236 | ||
| 241 | (defun pmail-make-date-sortable (date) | 237 | (defun pmail-make-date-sortable (date) |