Node:rotate-yank-pointer, Next:, Previous:Kill Ring, Up:Kill Ring



B.1 The rotate-yank-pointer Function

The rotate-yank-pointer function changes the element in the kill ring to which kill-ring-yank-pointer points. For example, it can change kill-ring-yank-pointer from pointing to the second element to point to the third element.

Here is the code for rotate-yank-pointer:

(defun rotate-yank-pointer (arg)
  "Rotate the yanking point in the kill ring."
  (interactive "p")
  (let ((length (length kill-ring)))
    (if (zerop length)
        ;; then-part
        (error "Kill ring is empty")
      ;; else-part
      (setq kill-ring-yank-pointer
            (nthcdr (% (+ arg
                          (- length
                             (length
                              kill-ring-yank-pointer)))
                       length)
                    kill-ring)))))