Among other actions, the else-part of the
if expression sets
the value of
ARGth-kill-element when the kill ring has something in it and
the value of
The code looks like this:
(nthcdr (mod (- n (length kill-ring-yank-pointer)) (length kill-ring)) kill-ring)))
This needs some examination. Unless it is not supposed to move the
current-kill function changes where
That is what the
(setq kill-ring-yank-pointer ARGth-kill-element))
expression does. Also, clearly,
ARGth-kill-element is being
set to be equal to some cdr of the kill ring, using the
nthcdr function that is described in an earlier section.
(See copy-region-as-kill.) How does it do this?
As we have seen before (see nthcdr), the
works by repeatedly taking the cdr of a list—it takes the
cdr of the cdr of the cdr ...
The two following expressions produce the same result:
(setq kill-ring-yank-pointer (cdr kill-ring)) (setq kill-ring-yank-pointer (nthcdr 1 kill-ring))
nthcdr expression is more complicated. It uses
mod function to determine which cdr to select.
(You will remember to look at inner functions first; indeed, we will
have to go inside the
mod function returns the value of its first argument modulo
the second; that is to say, it returns the remainder after dividing
the first argument by the second. The value returned has the same
sign as the second argument.
(mod 12 4) ⇒ 0 ;; because there is no remainder (mod 13 4) ⇒ 1
In this case, the first argument is often smaller than the second. That is fine.
(mod 0 4) ⇒ 0 (mod 1 4) ⇒ 1
We can guess what the
- function does. It is like
subtracts instead of adds; the
- function subtracts its second
argument from its first. Also, we already know what the
function does (see length). It returns the length of a list.
n is the name of the required argument to the
So when the first argument to
nthcdr is zero, the
expression returns the whole list, as you can see by evaluating the
;; kill-ring-yank-pointer and kill-ring have a length of four ;; and (mod (- 0 4) 4) ⇒ 0 (nthcdr (mod (- 0 4) 4) '("fourth line of text" "third line" "second piece of text" "first some text"))
When the first argument to the
current-kill function is one,
nthcdr expression returns the list without its first
(nthcdr (mod (- 1 4) 4) '("fourth line of text" "third line" "second piece of text" "first some text"))
are global variables. That means that any expression in Emacs
Lisp can access them. They are not like the local variables set by
let or like the symbols in an argument list.
Local variables can only be accessed
let that defines them or the function that specifies
them in an argument list (and within expressions called by them).