annotate lisp/emacs-lisp/ring.el @ 10219:d97313bb6f39

(bibtex-string, bibtex-preamble): Use forward-line. (sort-subr): Don't call autload for this--that's done in loaddefs.el. (bibtex-mode): Add autoload cookie. Changed keybinding for bibtex-print-help-message (from \C-ch to \C-c?). Therefore, describe-mode is not longer on \C-c?. Also, changed prefix \C-cn for bibtex-narrow functions to \C-c\C-r. (bibtex-string-files): Changed documentation. (bibtex-mode-map): Inscriptions of menu bar changed from "Entry Types" to "Entry-Types" and "Bibtex Edit" to "BibTeX-Edit". (bibtex-string-files): Changed documentation. (bibtex-mode): If environment variable BIBINPUTS isn't defined, string files are searched in the current directory. (bibtex-completion-candidates): Now buffer-local to allow evaluation of different bibtex-string-files in different buffers. (bibtex-autokey-edit-before-use, bibtex-clean-entry): New variable that determines, if the user is allowed to edit auto-generated reference keys before they are used. (bibtex-generate-autokey, bibtex-clean-entry): New function to generate an autokey if necessary. (bibtex-autokey-names, bibtex-autokey-name-change-strings, bibtex-autokey-name-length, bibtex-autokey-name-separator, bibtex-autokey-year-length, bibtex-autokey-titlewords, bibtex-autokey-title-terminators, bibtex-autokey-titlewords-stretch, bibtex-autokey-titleword-first-ignore, bibtex-autokey-titleword-abbrevs, bibtex-autokey-titleword-change-strings, bibtex-autokey-titleword-length, bibtex-autokey-titleword-separator, bibtex-autokey-name-year-separator, bibtex-autokey-year-title-separator): New variables related to bibtex-generate-autokey. (bibtex-find-entry-location): Optional second parameter maybedup to tell it that entering a duplicate entry isn't to report by an error but by the return value of the function (necessary for bibtex-clean-entry to find the correct position of an entry with an autogenerated key without disturbing the user with unwanted messages). (bibtex-help-message): New variable to avoid printing of help messages in the echo area. (assoc-of-regexp): New function to match an alist of regexps. (bibtex-string-files, bibtex-completion-candidates, bibtex-mode): New variables to allow bibtex-complete-string to work on strings initialized from a variable and from @String definitions in a list of files, too. (bibtex-predefined-strings, bibtex-entry-field-alist): Changed to user options. (bibtex-mode): Changed doc string. (many functions and variables): Changed documentation strings of variables and functions to hold a complete sentence in the first line. (bibtex-print-help-message): Now line dependent and reports if it is called outside a BibTeX field. (validate-bibtex-buffer): Completely rewritten to validate, if buffer is syntactically correct. (find-bibtex-duplicates): Moved into validate-bibtex-buffer. (ispell-abstract, bibtex-ispell-abstract, ispell-bibtex-entry, bibtex-ispell-entry, beginning-of-bibtex-entry, bibtex-beginning-of-entry, end-of-bibtex-entry, bibtex-end-of-entry, hide-bibtex-entry-bodies, bibtex-hide-entry-bodies, narrow-to-bibtex-entry, bibtex-narrow-to-entry, sort-bibtex-entries, bibtex-sort-entries, validate-bibtex-buffer, bibtex-validate-buffer, find-bibtex-entry-location, bibtex-find-entry-location): All interactive functions are renamed, so that any interface function begins with "bibtex-". Mapping: ispell-abstract --> bibtex-ispell-abstract ispell-bibtex-entry --> bibtex-ispell-entry beginning-of-bibtex-entry --> bibtex-beginning-of-entry end-of-bibtex-entry --> bibtex-end-of-entry hide-bibtex-entry-bodies --> bibtex-hide-entry-bodies narrow-to-bibtex-entry --> bibtex-narrow-to-entry sort-bibtex-entries --> bibtex-sort-entries validate-bibtex-buffer --> bibtex-validate-buffer find-bibtex-entry-location --> bibtex-find-entry-location (bibtex-maintain-sorted-entries, bibtex-sort-ignore-string-entries): Default is now t. (bibtex-complete-string): String list is built from additional string list bibtex-predefined-string and current strings in file. (string-equalp): Deleted and substituted by string-equal. (assoc-string-equalp): Renamed to assoc-ignore-case. (bibtex-entry): Reference key can be entered with completion. All reference keys that are defined in buffer and all labels that appear in crossreference entries are object to completion. (Entry types): Changed order of entries in menu "entry types". (bibtex-entry-field-alist): Changed order of entries slightly to be more conform with standard BibTeX style layouts. (bibtex-mode-map): Uniform keybindings for \C-c\C-e prefix (often used types on control keys, sometimes used types on normal keys, rarely used types on shift keys, almost never used types on meta keys). (bibtex-mode-map): Function narrow-to-bibtex-entry and counterpart widen and function hide-bibtex-entry-bodies and counterpart show-all bounded to appropriate local keys. (bibtex-abbrev-table): Deleted (bibtex-current-entry-label, put-string-on-kill-ring): Deleted (AUCTeX provides all the functionality needed for citation completion). (bibtex-enclosing-reference, bibtex-pop-previous, bibtex-pop-next, bibtex-clean-entry): Hacked for speed (bibtex-pop-previous and bibtex-pop-next were to slow for larger BibTeX files). (bibtex-pop-previous, bibtex-pop-next): Delimiters from previous or next entry are changed to actual delimters if necessary. (bibtex-entry): Fixed bug (False entry wasn't reported in error message if bibtex-entry was called with undefined reference name). (bibtex-entry-field-alist, bibtex-entry, bibtex-make-field, bibtex-next-field, bibtex-clean-entry): Every reference entry now contains a comment in addition to the name of the reference. This comment appears in the echo area if you start editing that field (after calling bibtex-next-field). (bibtex-include-OPTcrossref, bibtex-entry): Changed bibtex-include-OPTcrossref from single boolean variable to hold a list of reference names which should have a crossref field. (bibtex-complete-word): New function, which completes word fragment before point to the longest prefix of predefined strings in the buffer in the same way that ispell-complete-word operates for words found in the dictionary. (bibtex-reference-head): Start of bibtex-reference-head changed from "^[ \t]*\\(" to "^\\( \\|\t\\)*\\(" (bibtex-pop-previous and bibtex-pop-next didn't work, probably due to a bug in re-search-forward). (several functions): Added support for {} as field delimiters (better than '"' for accented characters. (bibtex-clean-entry): If optional field crossref is empty or missing, former optional fields (if bibtex-include-OPTcrossref was t) are necessary again. bibtex-clean-entry complains if they are empty but not if they are missing, so you can intenionally omit them, e. g. for a pseudo @Journal entry (needed for crossreferences) made out of an @article with missing non-optional fields. Menu bar entries aren't centered anymore.
author Richard M. Stallman <rms@gnu.org>
date Fri, 23 Dec 1994 04:18:29 +0000
parents 4b45aa6d5d76
children 83f275dcd93a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2424
dbdccee84df3 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 905
diff changeset
1 ;;; ring.el --- handle rings of items
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
5 ;; Maintainer: FSF
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
6 ;; Keywords: extensions
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
7
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
8 ;; This file is part of GNU Emacs.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
9
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
13 ;; any later version.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
14
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
18 ;; GNU General Public License for more details.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
19
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
20 ;; You should have received a copy of the GNU General Public License
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
23
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
24 ;;; Commentary:
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
25
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
26 ;;; This code defines a ring data structure. A ring is a
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
27 ;;; (hd-index length . vector)
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
28 ;;; list. You can insert to, remove from, and rotate a ring. When the ring
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
29 ;;; fills up, insertions cause the oldest elts to be quietly dropped.
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
30 ;;;
2574
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
31 ;;; In ring-ref, 0 is the index of the newest element. Higher indexes
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
32 ;;; correspond to older elements until they wrap.
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
33 ;;;
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
34 ;;; hd-index = index of the newest item on the ring.
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
35 ;;; length = number of ring items.
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
36 ;;;
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
37 ;;; These functions are used by the input history mechanism, but they can
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
38 ;;; be used for other purposes as well.
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
39
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
40 ;;; Code:
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 658
diff changeset
41
905
48e4034a2176 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
42 ;;;###autoload
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
43 (defun ring-p (x)
2574
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
44 "Returns t if X is a ring; nil otherwise."
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
45 (and (consp x) (integerp (car x))
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
46 (consp (cdr x)) (integerp (car (cdr x)))
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
47 (vectorp (cdr (cdr x)))))
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
48
905
48e4034a2176 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
49 ;;;###autoload
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
50 (defun make-ring (size)
2574
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
51 "Make a ring that can contain SIZE elements."
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
52 (cons 0 (cons 0 (make-vector size nil))))
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
53
8031
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
54 (defun ring-insert-at-beginning (ring item)
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
55 "Add to RING the item ITEM. Add it at the front (the early end)."
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
56 (let* ((vec (cdr (cdr ring)))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
57 (veclen (length vec))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
58 (hd (car ring))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
59 (ln (car (cdr ring))))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
60 (setq ln (min veclen (1+ ln))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
61 hd (ring-minus1 hd veclen))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
62 (aset vec hd item)
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
63 (setcar ring hd)
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
64 (setcar (cdr ring) ln)))
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
65
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
66 (defun ring-plus1 (index veclen)
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
67 "INDEX+1, with wraparound"
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
68 (let ((new-index (+ index 1)))
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
69 (if (= new-index veclen) 0 new-index)))
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
70
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
71 (defun ring-minus1 (index veclen)
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
72 "INDEX-1, with wraparound"
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
73 (- (if (= 0 index) veclen index) 1))
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
74
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
75 (defun ring-length (ring)
2574
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
76 "Number of elements in the ring."
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
77 (car (cdr ring)))
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
78
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
79 (defun ring-empty-p (ring)
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
80 (= 0 (car (cdr ring))))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
81
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
82 (defun ring-index (index head ringlen veclen)
4516
95b9760d19e3 (ring-mod): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 2582
diff changeset
83 (setq index (mod index ringlen))
95b9760d19e3 (ring-mod): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 2582
diff changeset
84 (mod (1- (+ head (- ringlen index))) veclen))
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
85
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
86 (defun ring-insert (ring item)
8031
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
87 "Insert onto ring RING the item ITEM, as the newest (last) item.
4b45aa6d5d76 (ring-insert-at-beginning): New function.
Richard M. Stallman <rms@gnu.org>
parents: 4516
diff changeset
88 If the ring is full, dump the oldest item to make room."
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
89 (let* ((vec (cdr (cdr ring)))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
90 (veclen (length vec))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
91 (hd (car ring))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
92 (ln (car (cdr ring))))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
93 (prog1
4516
95b9760d19e3 (ring-mod): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 2582
diff changeset
94 (aset vec (mod (+ hd ln) veclen) item)
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
95 (if (= ln veclen)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
96 (setcar ring (ring-plus1 hd veclen))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
97 (setcar (cdr ring) (1+ ln))))))
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
98
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
99 (defun ring-remove (ring &optional index)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
100 "Remove an item from the RING. Return the removed item.
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
101 If optional INDEX is nil, remove the oldest item. If it's
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
102 numeric, remove the element indexed."
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
103 (if (ring-empty-p ring)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
104 (error "Ring empty")
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
105 (let* ((hd (car ring))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
106 (ln (car (cdr ring)))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
107 (vec (cdr (cdr ring)))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
108 (veclen (length vec))
4516
95b9760d19e3 (ring-mod): Remove, since floor and mod
Paul Eggert <eggert@twinsun.com>
parents: 2582
diff changeset
109 (tl (mod (1- (+ hd ln)) veclen))
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
110 oldelt)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
111 (if (null index)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
112 (setq index (1- ln)))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
113 (setq index (ring-index index hd ln veclen))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
114 (setq oldelt (aref vec index))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
115 (while (/= index tl)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
116 (aset vec index (aref vec (ring-plus1 index veclen)))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
117 (setq index (ring-plus1 index veclen)))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
118 (aset vec tl nil)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
119 (setcar (cdr ring) (1- ln))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
120 oldelt)))
124
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
121
27691d738b4f Initial revision
David Lawrence <tale@gnu.org>
parents:
diff changeset
122 (defun ring-ref (ring index)
2574
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
123 "Returns RING's INDEX element.
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
124 INDEX need not be <= the ring length, the appropriate modulo operation
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
125 will be performed. Element 0 is the most recently inserted; higher indices
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
126 correspond to older elements until they wrap."
2582
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
127 (if (ring-empty-p ring)
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
128 (error "indexed empty ring")
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
129 (let* ((hd (car ring)) (ln (car (cdr ring))) (vec (cdr (cdr ring))))
e01048f32511 Rewritten. A poor choice of representation made the old code excessively
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2574
diff changeset
130 (aref vec (ring-index index hd ln (length vec))))))
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
131
2574
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
132 (provide 'ring)
c782b69b60a4 Added and fixed documentation.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2424
diff changeset
133
658
7cbd4fcd8b0f *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 245
diff changeset
134 ;;; ring.el ends here