Mercurial > emacs
view lisp/emacs-lisp/ring.el @ 51415:762217a72cae
Long overdue merge.
Don't require `compile' since it seems unnecessary.
For all internal variables and functions the docstring comments have
been converted into proper docstrings
(bibtex-maintainer-address, bibtex-maintainer-salutation)
(bibtex-version): Remove support for bug reporting.
(bibtex-field-delimiters, bibtex-entry-delimiters)
(bibtex-sort-ignore-string-entries, bibtex-maintain-sorted-entries)
Replace make-variable-buffer-local by make-local-variable for
(bibtex-entry-format): New tag `required-fields'.
(bibtex-maintain-sorted-entries): New var.
(bibtex-sort-entry-class, bibtex-sort-entry-class-alist): New vars.
(bibtex-predefined-month-strings, bibtex-predefined-strings):
Make into alists with pairs (abbreviation expansion).
(bibtex-autokey-titleword-change-strings)
(bibtex-autokey-transcriptions): Make into alists.
Add new replacement pairs.
(bibtex-autokey-use-crossref): New var.
Replace bibtex-autokey-year-use-crossref-entry because updated code
for autokey generation handles crossrefs independently of
particular fields.
(bibtex-reference-key, bibtex-mode-syntax-table):
Remove = because it can't be part of a string's key.
(bibtex-complete-key-cleanup): New var.
(bibtex-complete): Merge bibtex-complete-string and bibtex-complete-key
into it (and bind to M-tab).
(bibtex-valid-entry-re, bibtex-any-valid-entry-re)
(bibtex-valid-entry-whitespace-re, bibtex-empty-field-re)
(bibtex-quoted-string-re): New vars.
(bibtex-field-name-for-parsing): Don't make-variable-buffer-local.
(zmacs-regions): Declare to quieten the byte-compiler.
(bibtex-comment-start): Don't include the space.
(bibtex-font-lock-syntactic-keywords): New var.
(bibtex-font-lock-keywords): Remove the entry for @Comment.
(bibtex-parse-field-string): Merge the functionality of
bibtex-parse-field-string-braced, bibtex-parse-quoted-string and
bibtex-parse-field-string-quoted.
(bibtex-search-forward-field-string): Remove.
(bibtex-parse-association): Use when.
(bibtex-parse-field-name): Use when.
(bibtex-parse-field-text): Use when and cond.
(bibtex-parse-field): Use let.
(bibtex-search-forward-field, bibtex-search-backward-field):
Make bound optional, use let, setq, and cddr.
(bibtex-start-of-field, bibtex-start-of-name-in-field)
(bibtex-end-of-name-in-field): Use nth.
(bibtex-name-in-field, bibtex-text-in-field-bounds)
(bibtex-text-in-field, bibtex-type-in-head, bibtex-key-in-head)
(bibtex-text-in-string): New functions.
(bibtex-reference-key-in-string): New fun. Merge of
bibtex-start-of-reference-key-in-string and
bibtex-end-of-reference-key-in-string.
(bibtex-parse-string-prefix): Use let and when.
(bibtex-parse-string-postfix): Use when.
(bibtex-search-forward-string, bibtex-search-backward-string):
Use save-excursion and setq.
(bibtex-member-of-regexp): Use let.
(bibtex-assoc-of-regexp): Use caar und let.
(bibtex-skip-to-valid-entry): Return buffer position.
(bibtex-map-entries): Use save-excursion.
(bibtex-progress-message): Simplify.
(bibtex-search-entry): Use skip-chars-forward, when, save-match-data.
(bibtex-move-outside-of-entry): Handle the case that point is before
first entry.
(bibtex-enclosing-field): Use save-excursion, when.
(bibtex-format-field-delimiters): Merge into bibtex-format-entry.
(bibtex-enclosing-entry-maybe-empty-head): Simplify.
(bibtex-format-entry): Simplify. Handle new tag required-fields of
bibtex-entry-format.
(bibtex-autokey-abbrev): Accept negative values of len.
(bibtex-autokey-get-field, bibtex-autokey-demangle-title): New funs.
(bibtex-autokey-get-namefield, bibtex-autokey-get-namelist)
(bibtex-autokey-get-yearfield-digits, bibtex-autokey-get-yearfield)
(bibtex-autokey-get-titlestring): Remove.
(bibtex-autokey-get-names): Simplify.
(bibtex-autokey-get-titles): Rename to bibtex-autokey-get-title.
(bibtex-autokey-demangle-name): Simplify, avoid error messages.
(bibtex-generate-autokey): Simplify.
(bibtex-parse-keys): Simplify, use push.
(bibtex-parse-strings): New fun similar to bibtex-parse-keys.
(bibtex-string-files-init): New fun.
(bibtex-parse-buffers-stealthily): Use bibtex-parse-keys,
bibtex-string-files-init and bibtex-parse-strings.
(bibtex-complete): Rename to bibtex-complete-internal, use push,
bibtex-reference-key-in-string, no sorting.
(bibtex-complete-string-cleanup): New fun, displays expansion of
completed strings.
(bibtex-choose-completion-string): New fun. Required for
choose-completion-string-functions.
(bibtex-do-auto-fill): Remove. Set fill-prefix in bibtex-mode.
(bibtex-pop): Simplify.
(bibtex-mode): Move setting of bibtex-string to bibtex-parse-strings.
Set choose-completion-string-functions.
(bibtex-print-help-message,bibtex-make-field, bibtex-end-of-entry)
(bibtex-count-entries): Simplify.
(bibtex-entry-index, bibtex-lessp): New funs for generalized sorting
scheme of indices, see bibtex-maintain-sorted-entries.
(bibtex-sort-buffer): Use bibtex-lessp for sorting.
(bibtex-find-crossref, bibtex-find-entry): New funs.
(bibtex-find-entry-location): Rename to bibtex-prepare-new-entry, use
bibtex-lessp, Simplify.
(bibtex-validate): Simplify. Fixe bug of internal variable
questionable-month.
(bibtex-remove-OPT-or-ALT): Use when.
(bibtex-remove-delimiters, bibtex-kill-field, bibtex-kill-entry)
(bibtex-clean-entry, bibtex-fill-entry, bibtex-reformat): Simplify.
(bibtex-convert-alien): Use deactivate-mark rather than the
non-existent bibtex-mark-active variable.
(bibtex-complete-string, bibtex-complete-key): Merge into new
`smart' defun bibtex-complete.
(bibtex-String): Update for new sorting scheme, distinguish empty and
non-empty key strings.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 02 Jun 2003 22:30:09 +0000 |
parents | 661c97b907a8 |
children | 000e2717e1a5 d7ddb3e565de |
line wrap: on
line source
;;; ring.el --- handle rings of items ;; Copyright (C) 1992 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: extensions ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; This code defines a ring data structure. A ring is a ;; (hd-index length . vector) ;; list. You can insert to, remove from, and rotate a ring. When the ring ;; fills up, insertions cause the oldest elts to be quietly dropped. ;; ;; In ring-ref, 0 is the index of the newest element. Higher indexes ;; correspond to older elements; when the index equals the ring length, ;; it wraps to the newest element again. ;; ;; hd-index = vector index of the oldest ring item. ;; Newer items follow this item; at the end of the vector, ;; they wrap around to the start of the vector. ;; length = number of items currently in the ring. ;; This never exceeds the length of the vector itself. ;; ;; These functions are used by the input history mechanism, but they can ;; be used for other purposes as well. ;;; Code: ;;; User Functions: ;;;###autoload (defun ring-p (x) "Returns t if X is a ring; nil otherwise." (and (consp x) (integerp (car x)) (consp (cdr x)) (integerp (car (cdr x))) (vectorp (cdr (cdr x))))) ;;;###autoload (defun make-ring (size) "Make a ring that can contain SIZE elements." (cons 0 (cons 0 (make-vector size nil)))) (defun ring-insert-at-beginning (ring item) "Add to RING the item ITEM. Add it at the front, as the oldest item." (let* ((vec (cdr (cdr ring))) (veclen (length vec)) (hd (car ring)) (ln (car (cdr ring)))) (setq ln (min veclen (1+ ln)) hd (ring-minus1 hd veclen)) (aset vec hd item) (setcar ring hd) (setcar (cdr ring) ln))) (defun ring-plus1 (index veclen) "Returns INDEX+1, with wraparound." (let ((new-index (+ index 1))) (if (= new-index veclen) 0 new-index))) (defun ring-minus1 (index veclen) "Returns INDEX-1, with wraparound." (- (if (= 0 index) veclen index) 1)) (defun ring-length (ring) "Returns the number of elements in the RING." (car (cdr ring))) (defun ring-index (index head ringlen veclen) "Converts nominal ring index INDEX to an internal index. The internal index refers to the items ordered from newest to oldest. HEAD is the index of the oldest element in the ring. RINGLEN is the number of elements currently in the ring. VECLEN is the size of the vector in the ring." (setq index (mod index ringlen)) (mod (1- (+ head (- ringlen index))) veclen)) (defun ring-empty-p (ring) "Returns t if RING is empty; nil otherwise." (= 0 (car (cdr ring)))) (defun ring-size (ring) "Returns the size of RING, the maximum number of elements it can contain." (length (cdr (cdr ring)))) (defun ring-copy (ring) "Returns a copy of RING." (let* ((vec (cdr (cdr ring))) (hd (car ring)) (ln (car (cdr ring)))) (cons hd (cons ln (copy-sequence vec))))) (defun ring-insert (ring item) "Insert onto ring RING the item ITEM, as the newest (last) item. If the ring is full, dump the oldest item to make room." (let* ((vec (cdr (cdr ring))) (veclen (length vec)) (hd (car ring)) (ln (car (cdr ring)))) (prog1 (aset vec (mod (+ hd ln) veclen) item) (if (= ln veclen) (setcar ring (ring-plus1 hd veclen)) (setcar (cdr ring) (1+ ln)))))) (defun ring-remove (ring &optional index) "Remove an item from the RING. Return the removed item. If optional INDEX is nil, remove the oldest item. If it's numeric, remove the element indexed." (if (ring-empty-p ring) (error "Ring empty") (let* ((hd (car ring)) (ln (car (cdr ring))) (vec (cdr (cdr ring))) (veclen (length vec)) (tl (mod (1- (+ hd ln)) veclen)) oldelt) (if (null index) (setq index (1- ln))) (setq index (ring-index index hd ln veclen)) (setq oldelt (aref vec index)) (while (/= index tl) (aset vec index (aref vec (ring-plus1 index veclen))) (setq index (ring-plus1 index veclen))) (aset vec tl nil) (setcar (cdr ring) (1- ln)) oldelt))) (defun ring-ref (ring index) "Returns RING's INDEX element. INDEX = 0 is the most recently inserted; higher indices correspond to older elements. INDEX need not be <= the ring length; the appropriate modulo operation will be performed." (if (ring-empty-p ring) (error "Accessing an empty ring") (let* ((hd (car ring)) (ln (car (cdr ring))) (vec (cdr (cdr ring)))) (aref vec (ring-index index hd ln (length vec)))))) (defun ring-elements (ring) "Return a list of the lements of RING." (mapcar #'identity (cddr ring))) ;;; provide ourself: (provide 'ring) ;;; ring.el ends here