emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/lisp/mail pmailsort.el


From: Chong Yidong
Subject: [Emacs-diffs] emacs/lisp/mail pmailsort.el
Date: Thu, 04 Dec 2008 22:48:57 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Chong Yidong <cyd>      08/12/04 22:48:57

Modified files:
        lisp/mail      : pmailsort.el 

Log message:
        Sync with pmailsort.el.
        (pmail-sort-messages): Insert two newlines at the end of the
        message if they do not exist.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/mail/pmailsort.el?cvsroot=emacs&r1=1.8&r2=1.9

Patches:
Index: pmailsort.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/mail/pmailsort.el,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- pmailsort.el        4 Dec 2008 03:24:41 -0000       1.8
+++ pmailsort.el        4 Dec 2008 22:48:57 -0000       1.9
@@ -29,7 +29,8 @@
 (eval-when-compile
   (require 'mail-utils)
   (require 'sort)
-  (require 'pmail))
+  (require 'pmail)
+  (require 'pmailhdr))
 
 (autoload 'timezone-make-date-sortable "timezone")
 
@@ -121,8 +122,8 @@
   (pmail-sort-messages reverse
                       (function
                        (lambda (msg)
-                         (count-lines (pmail-desc-get-start msg)
-                                      (pmail-desc-get-end msg))))))
+                         (count-lines (pmail-msgbeg msg)
+                                      (pmail-msgend msg))))))
 
 ;;;###autoload
 (defun pmail-sort-by-labels (reverse labels)
@@ -158,10 +159,8 @@
   "Sort messages of current Pmail file.
 If 1st argument REVERSE is non-nil, sort them in reverse order.
 2nd argument KEYFUN is called with a message number, and should return a key."
-  (save-current-buffer
-    ;; If we are in a summary buffer, operate on the Pmail buffer.
-    (if (eq major-mode 'pmail-summary-mode)
-       (set-buffer pmail-buffer))
+  (pmail-swap-buffers-maybe)
+  (with-current-buffer pmail-buffer
     (let ((buffer-read-only nil)
          (point-offset (- (point) (point-min)))
          (predicate nil)                       ;< or string-lessp
@@ -173,8 +172,8 @@
          (setq sort-lists
                (cons (list (funcall keyfun msgnum) ;Make sorting key
                            (eq pmail-current-message msgnum) ;True if current
-                           (pmail-desc-get-start msgnum)
-                           (pmail-desc-get-end msgnum))
+                           (aref pmail-message-vector msgnum)
+                           (aref pmail-message-vector (1+ msgnum)))
                      sort-lists))
          (if (zerop (% msgnum 10))
              (message "Finding sort keys...%d" msgnum))
@@ -198,21 +197,22 @@
            (msginfo nil))
        ;; There's little hope that we can easily undo after that.
        (buffer-disable-undo (current-buffer))
-       (goto-char (pmail-desc-get-start 1))
+       (goto-char (pmail-msgbeg 1))
        ;; To force update of all markers.
        (insert-before-markers ?Z)
        (backward-char 1)
        ;; Now reorder messages.
-       (while sort-lists
-         (setq msginfo (car sort-lists))
+       (dolist (msginfo sort-lists)
          ;; Swap two messages.
          (insert-buffer-substring
           (current-buffer) (nth 2 msginfo) (nth 3 msginfo))
+         ;; The last message may not have \n\n after it.
+         (unless (eq (char-before) ?\n)
+           (insert "\n\n"))
          (delete-region  (nth 2 msginfo) (nth 3 msginfo))
          ;; Is current message?
          (if (nth 1 msginfo)
              (setq current-message msgnum))
-         (setq sort-lists (cdr sort-lists))
          (if (zerop (% msgnum 10))
              (message "Reordering messages...%d" msgnum))
          (setq msgnum (1+ msgnum)))
@@ -220,22 +220,18 @@
        (delete-char 1)
        (setq quit-flag nil)
        (buffer-enable-undo)
-        (goto-char (point-min))
-       (pmail-initialize-messages)
+       (pmail-set-message-counters)
        (pmail-show-message current-message)
+       (goto-char (+ point-offset (point-min)))
        (if (pmail-summary-exists)
-           (pmail-select-summary
-            (pmail-update-summary)))))))
+           (pmail-select-summary (pmail-update-summary)))))))
 
-;; mbox: ready
 (defun pmail-fetch-field (msg field)
   "Return the value of the header FIELD of MSG.
 Arguments are MSG and FIELD."
   (save-restriction
     (widen)
-    (narrow-to-region
-     (pmail-desc-get-start msg)
-     (pmail-desc-get-end msg))
+    (narrow-to-region (pmail-msgbeg msg) (pmail-msgend msg))
     (pmail-header-get-header field)))
 
 (defun pmail-make-date-sortable (date)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]