Next: , Previous: current-kill, Up: current-kill

The code for current-kill

The current-kill function is used by yank and by yank-pop. Here is the code for current-kill:

     (defun current-kill (n &optional do-not-move)
       "Rotate the yanking point by N places, and then return that kill.
     If N is zero, `interprogram-paste-function' is set, and calling it
     returns a string, then that string is added to the front of the
     kill ring and returned as the latest kill.
     If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
     yanking point; just return the Nth kill forward."
       (let ((interprogram-paste (and (= n 0)
                                      (funcall interprogram-paste-function))))
         (if interprogram-paste
               ;; Disable the interprogram cut function when we add the new
               ;; text to the kill ring, so Emacs doesn't try to own the
               ;; selection, with identical text.
               (let ((interprogram-cut-function nil))
                 (kill-new interprogram-paste))
           (or kill-ring (error "Kill ring is empty"))
           (let ((ARGth-kill-element
                  (nthcdr (mod (- n (length kill-ring-yank-pointer))
                               (length kill-ring))
             (or do-not-move
                 (setq kill-ring-yank-pointer ARGth-kill-element))
             (car ARGth-kill-element)))))

Remember also that the kill-new function sets kill-ring-yank-pointer to the latest element of the kill ring, which means that all the functions that call it set the value indirectly: kill-append, copy-region-as-kill, kill-ring-save, kill-line, and kill-region.

Here is the line in kill-new, which is explained in The kill-new function.

     (setq kill-ring-yank-pointer kill-ring)