Function: ring-resize
ring-resize is a byte-compiled function defined in ring.el.gz.
Signature
(ring-resize RING SIZE)
Documentation
Set the size of RING to SIZE.
If the new size is smaller, then the oldest items in the ring are discarded.
Probably introduced at or before Emacs version 27.1.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/ring.el.gz
(defun ring-resize (ring size)
"Set the size of RING to SIZE.
If the new size is smaller, then the oldest items in the ring are
discarded."
(when (integerp size)
(let ((length (ring-length ring))
(new-vec (make-vector size nil)))
(if (= length 0)
(setcdr ring (cons 0 new-vec))
(let* ((hd (car ring))
(old-size (ring-size ring))
(old-vec (cddr ring))
(copy-length (min size length))
(copy-hd (mod (+ hd (- length copy-length)) length)))
(setcdr ring (cons copy-length new-vec))
;; If the ring is wrapped, the existing elements must be written
;; out in the right order.
(dotimes (j copy-length)
(aset new-vec j (aref old-vec (mod (+ copy-hd j) old-size))))
(setcar ring 0))))))