1 ;;; range.el --- range functions
3 ;; Copyright (C) 1987 .. 1996 Free Software Foundation, Inc.
5 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;; $Id: range.el,v 1.1.1.1 1998-01-14 06:27:57 steve Exp $
12 ;; This file is part of tl (Tiny Library).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with This program; see the file COPYING. If not, write to
26 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; These functions were imported from September Gnus 0.40.
33 (defun compress-sorted-numbers (numbers &optional always-list)
34 "Convert list of numbers to a list of ranges or a single range.
35 If ALWAYS-LIST is non-nil, this function will always release a list of
37 (let* ((first (car numbers))
42 (if (not (listp (cdr numbers)))
45 (cond ((= last (car numbers)) nil) ;Omit duplicated number
46 ((= (1+ last) (car numbers)) ;Still in sequence
47 (setq last (car numbers)))
48 (t ;End of one sequence
50 (cons (if (= first last) first
51 (cons first last)) result))
52 (setq first (car numbers))
53 (setq last (car numbers))))
54 (setq numbers (cdr numbers)))
55 (if (and (not always-list) (null result))
56 (if (= first last) (list first) (cons first last))
57 (nreverse (cons (if (= first last) first (cons first last))
60 (defun expand-range (range)
61 "Expand a range into a list of numbers. [range.el]"
62 (cond ((numberp range)
64 ((numberp (cdr range))
65 (index (car range)(cdr range))
71 (setq ret (expand-range sec))
83 (defun member-of-range (number range)
84 "Return t if NUMBER is a member of RANGE. [range.el]"
85 (cond ((numberp range)
88 ((numberp (cdr range))
89 (and (<= (car range) number)
90 (<= number (cdr range))
96 (if (member-of-range number (car range))
99 (setq range (cdr range))
109 ;;; range.el ends here