Initial Commit
[packages] / xemacs-packages / mew / mew / mew-sort.el
1 ;;; mew-sort.el --- Sorting messages for Mew
2
3 ;; Author:  Takashi P.KATOH <p-katoh@shiratori.riec.tohoku.ac.jp>
4 ;; Created: Feb  6, 1996
5 ;; Revised: Aug 30, 1999
6
7 ;;; Code:
8
9 (defconst mew-sort-version "mew-sort.el version 0.15")
10
11 (require 'mew)
12
13 (defun mew-summary-sort-subr (msgs &optional method from)
14   (if (not (mew-summary-exclusive-p))
15       ()
16     (mew-mark-clean)
17     (let* ((folder (buffer-name))
18            (sort-key (or (cdr (assoc folder 
19                                      mew-sort-default-key-alist))
20                          mew-sort-default-key))
21            (field-mode (mew-input-sort-key sort-key))
22            (field (car field-mode))
23            (mode (cdr field-mode))
24            rbeg)
25       (if (not (listp msgs)) (setq msgs (list msgs)))
26       (setq mew-summary-buffer-process t)
27       (message "Sorting %s by %s (%s mode) ... " folder field mode)
28       (apply (function call-process)
29              mew-prog-imsort
30              nil nil nil
31              (concat "--src=" folder)
32              (concat "--field=" field)
33              (concat "--mode=" mode)
34              (append mew-prog-im-arg msgs)) ;; xxx
35       (message "Sorting %s by %s ... done" folder field)
36       (setq mew-summary-buffer-process nil)
37       (if from 
38           (progn (mew-summary-jump-message from)
39                  (setq rbeg (point)))) ;; beginning of region
40       (widen)
41       (mew-elet
42        (delete-region (or rbeg (point-min)) (point-max))) ;; for update
43       (mew-summary-scan-body mew-prog-imls
44                              'mew-summary-mode
45                              folder
46                              mew-cs-scan
47                              (mew-update-range)))))
48
49 (defun mew-summary-sort (&optional arg)
50   "Sort messages in the folder according to inputed key."
51   (interactive "P")
52   (mew-summary-only
53    (if arg
54        (mew-summary-sort-region (region-beginning) (region-end) "region")
55      (mew-summary-sort-region (point-min) (point-max)))))
56
57 (defun mew-summary-sort-region (r1 r2 &optional method)
58   "Sort messages in the region according to inputed key."
59   (interactive "r")
60   (mew-summary-only
61    (let (from to)
62      (save-excursion
63        (goto-char (min r1 r2))
64        (setq from
65              (or (mew-summary-message-number)
66                  (progn
67                    (re-search-backward mew-summary-message-regex nil t)
68                    (mew-summary-message-number))))
69        (goto-char (max r1 r2))
70        (setq to
71              (or (mew-summary-message-number)
72                  (progn
73                    (re-search-backward mew-summary-message-regex nil t)
74                    (mew-summary-message-number))))
75        (goto-char (min r1 r2))
76        (beginning-of-line)
77        (mew-summary-sort-subr (concat from "-" to) method from)))))
78
79 (defun mew-summary-mark-sort (&optional r1 r2)
80   (interactive)
81   "Sort message marked with '*'."
82   (mew-summary-only
83    (mew-summary-sort-subr
84     (mew-summary-mark-collect
85      mew-mark-review (or r1 (point-min)) (or r2 (point-max)))
86     "marked messages")))
87
88 (provide 'mew-sort)
89
90 ;;; Copyright Notice:
91
92 ;; Copyright (C) 1996, 1997, 1998, 1999 Mew developing team.
93 ;; All rights reserved.
94
95 ;; Redistribution and use in source and binary forms, with or without
96 ;; modification, are permitted provided that the following conditions
97 ;; are met:
98 ;; 
99 ;; 1. Redistributions of source code must retain the above copyright
100 ;;    notice, this list of conditions and the following disclaimer.
101 ;; 2. Redistributions in binary form must reproduce the above copyright
102 ;;    notice, this list of conditions and the following disclaimer in the
103 ;;    documentation and/or other materials provided with the distribution.
104 ;; 3. Neither the name of the team nor the names of its contributors
105 ;;    may be used to endorse or promote products derived from this software
106 ;;    without specific prior written permission.
107 ;; 
108 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
109 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
110 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
111 ;; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
112 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
113 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
114 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
115 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
116 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
117 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
118 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119
120 ;;; mew-sort.el ends here