Go to the first, previous, next, last section, table of contents.


yank

After learning about rotate-yank-pointer, the code for the yank function is almost easy. It has only one tricky part, which is the computation of the argument to be passed to rotate-yank-pointer.

The code looks like this:

(defun yank (&optional arg)
  "Reinsert the last stretch of killed text.
More precisely, reinsert the stretch of killed text most 
recently killed OR yanked.
With just C-U as argument, same but put point in front 
(and mark at end).  With argument n, reinsert the nth 
most recently killed stretch of killed text.
See also the command \\[yank-pop]."

  (interactive "*P")
  (rotate-yank-pointer (if (listp arg) 0
                         (if (eq arg '-) -1
                           (1- arg))))
  (push-mark (point))
  (insert (car kill-ring-yank-pointer))
  (if (consp arg)
      (exchange-point-and-mark)))

Glancing over this code, we can understand the last few lines readily enough. The mark is pushed, that is, remembered; then the first element (the CAR) of what the kill-ring-yank-pointer points to is inserted; and then, if the argument passed the function is a cons, point and mark are exchanged so the point is put in the front of the inserted text rather than at the end. This option is explained in the documentation. The function itself is interactive with "*P". This means it will not work on a read-only buffer, and that the unprocessed prefix argument is passed to the function.


Go to the first, previous, next, last section, table of contents.