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: Richard M. Stallman
Subject: [Emacs-diffs] emacs/lisp/mail pmailsort.el
Date: Sat, 10 Jan 2009 21:12:48 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Richard M. Stallman <rms>       09/01/10 21:12:48

Modified files:
        lisp/mail      : pmailsort.el 

Log message:
        (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.

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

Patches:
Index: pmailsort.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/mail/pmailsort.el,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- pmailsort.el        5 Jan 2009 03:22:35 -0000       1.11
+++ pmailsort.el        10 Jan 2009 21:12:48 -0000      1.12
@@ -31,8 +31,6 @@
   (require 'sort)
   (require 'pmail))
 
-(require 'pmailhdr)
-
 (autoload 'timezone-make-date-sortable "timezone")
 
 (declare-function pmail-update-summary "pmailsum" (&rest ignore))
@@ -48,7 +46,7 @@
                       (function
                        (lambda (msg)
                          (pmail-make-date-sortable
-                          (pmail-fetch-field msg "Date"))))))
+                          (pmail-get-header "Date" msg))))))
 
 ;;;###autoload
 (defun pmail-sort-by-subject (reverse)
@@ -58,7 +56,7 @@
   (pmail-sort-messages reverse
                       (function
                        (lambda (msg)
-                         (let ((key (or (pmail-fetch-field msg "Subject") ""))
+                         (let ((key (or (pmail-get-header "Subject" msg) ""))
                                (case-fold-search t))
                            ;; Remove `Re:'
                            (if (string-match "^\\(re:[ \t]*\\)*" key)
@@ -75,8 +73,8 @@
                        (lambda (msg)
                          (downcase     ;Canonical name
                           (mail-strip-quoted-names
-                           (or (pmail-fetch-field msg "From")
-                               (pmail-fetch-field msg "Sender") "")))))))
+                           (or (pmail-get-header "From" msg)
+                               (pmail-get-header "Sender" msg) "")))))))
 
 ;;;###autoload
 (defun pmail-sort-by-recipient (reverse)
@@ -88,8 +86,8 @@
                        (lambda (msg)
                          (downcase     ;Canonical name
                           (mail-strip-quoted-names
-                           (or (pmail-fetch-field msg "To")
-                               (pmail-fetch-field msg "Apparently-To") "")
+                           (or (pmail-get-header "To" msg)
+                               (pmail-get-header "Apparently-To" msg) "")
                            ))))))
 
 ;;;###autoload
@@ -111,7 +109,7 @@
            ;; NB despite the name, this lives in mail-utils.el.
            (rmail-dont-reply-to
             (mail-strip-quoted-names
-             (or (pmail-fetch-field msg (car fields)) ""))))
+             (or (pmail-get-header (car fields) msg) ""))))
       (setq fields (cdr fields)))
     ans))
 
@@ -160,12 +158,13 @@
   "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."
-  (pmail-swap-buffers-maybe)
   (with-current-buffer pmail-buffer
-    (let ((buffer-read-only nil)
-         (point-offset (- (point) (point-min)))
+    (let ((return-to-point
+          (if (pmail-buffers-swapped-p)
+              (point)))
          (predicate nil)                       ;< or string-lessp
          (sort-lists nil))
+      (pmail-swap-buffers-maybe)
       (message "Finding sort keys...")
       (widen)
       (let ((msgnum 1))
@@ -193,13 +192,15 @@
       ;; Now we enter critical region.  So, keyboard quit is disabled.
       (message "Reordering messages...")
       (let ((inhibit-quit t)           ;Inhibit quit
+           (inhibit-read-only t)
            (current-message nil)
            (msgnum 1)
            (msginfo nil))
        ;; There's little hope that we can easily undo after that.
        (buffer-disable-undo (current-buffer))
        (goto-char (pmail-msgbeg 1))
-       ;; To force update of all markers.
+       ;; To force update of all markers,
+       ;; keep the new copies separated from the remaining old messages.
        (insert-before-markers ?Z)
        (backward-char 1)
        ;; Now reorder messages.
@@ -208,8 +209,10 @@
          (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"))
+         (unless (bobp)
+           (insert "\n"))
+         (unless (looking-back "\n\n")
+           (insert "\n"))
          (delete-region (nth 2 msginfo) (nth 3 msginfo))
          ;; Is current message?
          (if (nth 1 msginfo)
@@ -217,24 +220,16 @@
          (if (zerop (% msgnum 10))
              (message "Reordering messages...%d" msgnum))
          (setq msgnum (1+ msgnum)))
-       ;; Delete the garbage inserted before.
+       ;; Delete the dummy separator Z inserted before.
        (delete-char 1)
        (setq quit-flag nil)
-       (buffer-enable-undo)
        (pmail-set-message-counters)
        (pmail-show-message current-message)
-       (goto-char (+ point-offset (point-min)))
+       (if return-to-point
+           (goto-char return-to-point))
        (if (pmail-summary-exists)
            (pmail-select-summary (pmail-update-summary)))))))
 
-(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-msgbeg msg) (pmail-msgend msg))
-    (pmail-header-get-header field)))
-
 (defun pmail-make-date-sortable (date)
   "Make DATE sortable using the function string-lessp."
   ;; Assume the default time zone is GMT.




reply via email to

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