annotate lisp/gnus/gnus-range.el @ 35:279432d5c479

Added tag r19-15b100 for changeset d620409f5eb8
author cvs
date Mon, 13 Aug 2007 08:53:21 +0200
parents ec9a17fef872
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
1 ;;; gnus-range.el --- range and sequence functions for Gnus
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
3
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
5 ;; Keywords: news
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
6
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
8
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
12 ;; any later version.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
13
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
18
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
23
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
24 ;;; Commentary:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
25
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
26 ;;; Code:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
27
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
28 ;;; List and range functions
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
29
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
30 (defun gnus-last-element (list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
31 "Return last element of LIST."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
32 (while (cdr list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
33 (setq list (cdr list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
34 (car list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
35
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
36 (defun gnus-copy-sequence (list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
37 "Do a complete, total copy of a list."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
38 (let (out)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
39 (while (consp list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
40 (if (consp (car list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
41 (push (gnus-copy-sequence (pop list)) out)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
42 (push (pop list) out)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
43 (if list
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
44 (nconc (nreverse out) list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
45 (nreverse out))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
46
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
47 (defun gnus-set-difference (list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
48 "Return a list of elements of LIST1 that do not appear in LIST2."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
49 (let ((list1 (copy-sequence list1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
50 (while list2
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
51 (setq list1 (delq (car list2) list1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
52 (setq list2 (cdr list2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
53 list1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
54
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
55 (defun gnus-sorted-complement (list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
56 "Return a list of elements of LIST1 that do not appear in LIST2.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
57 Both lists have to be sorted over <."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
58 (let (out)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
59 (if (or (null list1) (null list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
60 (or list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
61 (while (and list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
62 (cond ((= (car list1) (car list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
63 (setq list1 (cdr list1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
64 list2 (cdr list2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
65 ((< (car list1) (car list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
66 (setq out (cons (car list1) out))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
67 (setq list1 (cdr list1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
68 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
69 (setq out (cons (car list2) out))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
70 (setq list2 (cdr list2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
71 (nconc (nreverse out) (or list1 list2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
72
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
73 (defun gnus-intersection (list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
74 (let ((result nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
75 (while list2
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
76 (when (memq (car list2) list1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
77 (setq result (cons (car list2) result)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
78 (setq list2 (cdr list2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
79 result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
80
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
81 (defun gnus-sorted-intersection (list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
82 ;; LIST1 and LIST2 have to be sorted over <.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
83 (let (out)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
84 (while (and list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
85 (cond ((= (car list1) (car list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
86 (setq out (cons (car list1) out)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
87 list1 (cdr list1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
88 list2 (cdr list2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
89 ((< (car list1) (car list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
90 (setq list1 (cdr list1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
91 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
92 (setq list2 (cdr list2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
93 (nreverse out)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
94
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
95 (defun gnus-set-sorted-intersection (list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
96 ;; LIST1 and LIST2 have to be sorted over <.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
97 ;; This function modifies LIST1.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
98 (let* ((top (cons nil list1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
99 (prev top))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
100 (while (and list1 list2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
101 (cond ((= (car list1) (car list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
102 (setq prev list1
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
103 list1 (cdr list1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
104 list2 (cdr list2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
105 ((< (car list1) (car list2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
106 (setcdr prev (cdr list1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
107 (setq list1 (cdr list1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
108 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
109 (setq list2 (cdr list2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
110 (setcdr prev nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
111 (cdr top)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
112
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
113 (defun gnus-compress-sequence (numbers &optional always-list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
114 "Convert list of numbers to a list of ranges or a single range.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
115 If ALWAYS-LIST is non-nil, this function will always release a list of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
116 ranges."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
117 (let* ((first (car numbers))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
118 (last (car numbers))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
119 result)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
120 (if (null numbers)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
121 nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
122 (if (not (listp (cdr numbers)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
123 numbers
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
124 (while numbers
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
125 (cond ((= last (car numbers)) nil) ;Omit duplicated number
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
126 ((= (1+ last) (car numbers)) ;Still in sequence
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
127 (setq last (car numbers)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
128 (t ;End of one sequence
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
129 (setq result
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
130 (cons (if (= first last) first
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
131 (cons first last))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
132 result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
133 (setq first (car numbers))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
134 (setq last (car numbers))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
135 (setq numbers (cdr numbers)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
136 (if (and (not always-list) (null result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
137 (if (= first last) (list first) (cons first last))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
138 (nreverse (cons (if (= first last) first (cons first last))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
139 result)))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
140
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
141 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
142 (defun gnus-uncompress-range (ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
143 "Expand a list of ranges into a list of numbers.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
144 RANGES is either a single range on the form `(num . num)' or a list of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
145 these ranges."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
146 (let (first last result)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
147 (cond
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
148 ((null ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
149 nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
150 ((not (listp (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
151 (setq first (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
152 (setq last (cdr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
153 (while (<= first last)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
154 (setq result (cons first result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
155 (setq first (1+ first)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
156 (nreverse result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
157 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
158 (while ranges
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
159 (if (atom (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
160 (when (numberp (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
161 (setq result (cons (car ranges) result)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
162 (setq first (caar ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
163 (setq last (cdar ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
164 (while (<= first last)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
165 (setq result (cons first result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
166 (setq first (1+ first))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
167 (setq ranges (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
168 (nreverse result)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
169
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
170 (defun gnus-add-to-range (ranges list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
171 "Return a list of ranges that has all articles from both RANGES and LIST.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
172 Note: LIST has to be sorted over `<'."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
173 (if (not ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
174 (gnus-compress-sequence list t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
175 (setq list (copy-sequence list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
176 (unless (listp (cdr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
177 (setq ranges (list ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
178 (let ((out ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
179 ilist lowest highest temp)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
180 (while (and ranges list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
181 (setq ilist list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
182 (setq lowest (or (and (atom (car ranges)) (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
183 (caar ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
184 (while (and list (cdr list) (< (cadr list) lowest))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
185 (setq list (cdr list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
186 (when (< (car ilist) lowest)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
187 (setq temp list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
188 (setq list (cdr list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
189 (setcdr temp nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
190 (setq out (nconc (gnus-compress-sequence ilist t) out)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
191 (setq highest (or (and (atom (car ranges)) (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
192 (cdar ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
193 (while (and list (<= (car list) highest))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
194 (setq list (cdr list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
195 (setq ranges (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
196 (when list
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
197 (setq out (nconc (gnus-compress-sequence list t) out)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
198 (setq out (sort out (lambda (r1 r2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
199 (< (or (and (atom r1) r1) (car r1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
200 (or (and (atom r2) r2) (car r2))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
201 (setq ranges out)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
202 (while ranges
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
203 (if (atom (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
204 (when (cdr ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
205 (if (atom (cadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
206 (when (= (1+ (car ranges)) (cadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
207 (setcar ranges (cons (car ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
208 (cadr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
209 (setcdr ranges (cddr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
210 (when (= (1+ (car ranges)) (caadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
211 (setcar (cadr ranges) (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
212 (setcar ranges (cadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
213 (setcdr ranges (cddr ranges)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
214 (when (cdr ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
215 (if (atom (cadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
216 (when (= (1+ (cdar ranges)) (cadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
217 (setcdr (car ranges) (cadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
218 (setcdr ranges (cddr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
219 (when (= (1+ (cdar ranges)) (caadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
220 (setcdr (car ranges) (cdadr ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
221 (setcdr ranges (cddr ranges))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
222 (setq ranges (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
223 out)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
224
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
225 (defun gnus-remove-from-range (ranges list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
226 "Return a list of ranges that has all articles from LIST removed from RANGES.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
227 Note: LIST has to be sorted over `<'."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
228 ;; !!! This function shouldn't look like this, but I've got a headache.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
229 (gnus-compress-sequence
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
230 (gnus-sorted-complement
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
231 (gnus-uncompress-range ranges) list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
232
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
233 (defun gnus-member-of-range (number ranges)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
234 (if (not (listp (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
235 (and (>= number (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
236 (<= number (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
237 (let ((not-stop t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
238 (while (and ranges
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
239 (if (numberp (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
240 (>= number (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
241 (>= number (caar ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
242 not-stop)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
243 (when (if (numberp (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
244 (= number (car ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
245 (and (>= number (caar ranges))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
246 (<= number (cdar ranges))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
247 (setq not-stop nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
248 (setq ranges (cdr ranges)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
249 (not not-stop))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
250
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
251 (defun gnus-range-length (range)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
252 "Return the length RANGE would have if uncompressed."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
253 (length (gnus-uncompress-range range)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
254
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
255 (defun gnus-sublist-p (list sublist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
256 "Test whether all elements in SUBLIST are members of LIST."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
257 (let ((sublistp t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
258 (while sublist
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
259 (unless (memq (pop sublist) list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
260 (setq sublistp nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
261 sublist nil)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
262 sublistp))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
263
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
264 (defun gnus-range-add (range1 range2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
265 "Add RANGE2 to RANGE1 destructively."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
266 (cond
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
267 ;; If either are nil, then the job is quite easy.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
268 ((or (null range1) (null range2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
269 (or range1 range2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
270 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
271 ;; I don't like thinking.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
272 (gnus-compress-sequence
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
273 (sort
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
274 (nconc
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
275 (gnus-uncompress-range range1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
276 (gnus-uncompress-range range2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
277 '<)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
278
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
279 (provide 'gnus-range)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
280
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
281 ;;; gnus-range.el ends here