Copyright (C) 2000-2012 |
GNU Info (emacs-lisp-intro.info)kill-rng-yk-ptr last eltPointing to the last element ............................ The final question is, what happens if the `kill-ring-yank-pointer' is set to the _last_ element of the kill ring? Will a call to `rotate-yank-pointer' mean that nothing more can be taken from the kill ring? The answer is no. What happens is different and useful. The `kill-ring-yank-pointer' is set to point to the beginning of the kill ring instead. Let's see how this works by looking at the code, assuming the length of the kill ring is 5 and the argument passed to `rotate-yank-pointer' is 1. When the `kill-ring-yank-pointer' points to the last element of the kill ring, its length is 1. The code looks like this: (% (+ arg (- length (length kill-ring-yank-pointer))) length) When the variables are replaced by their numeric values, the expression looks like this: (% (+ 1 (- 5 1)) 5) This expression can be evaluated by looking at the most embedded inner expression first and working outwards: The value of `(- 5 1)' is 4; the sum of `(+ 1 4)' is 5; and the remainder of dividing 5 by 5 is zero. So what `rotate-yank-pointer' will do is (setq kill-ring-yank-pointer (nthcdr 0 kill-ring)) which will set the `kill-ring-yank-pointer' to point to the beginning of the kill ring. So what happens with successive calls to `rotate-yank-pointer' is that it moves the `kill-ring-yank-pointer' from element to element in the kill ring until it reaches the end; then it jumps back to the beginning. And this is why the kill ring is called a ring, since by jumping back to the beginning, it is as if the list has no end! (And what is a ring, but an entity with no end?) automatically generated by info2www version 1.2.2.9 |