last-command and this-command

Normally, whenever a function is executed, Emacs sets the value of this-command to the function being executed (which in this case would be copy-region-as-kill). At the same time, Emacs sets the value of last-command to the previous value of this-command.

In the first part of the body of the copy-region-as-kill function, an if expression determines whether the value of last-command is kill-region. If so, the then-part of the if expression is evaluated; it uses the kill-append function to concatenate the text copied at this call to the function with the text already in the first element (the CAR) of the kill ring. On the other hand, if the value of last-command is not kill-region, then the copy-region-as-kill function attaches a new element to the kill ring using the kill-new function.

The if expression reads as follows; it uses eq:

  (if (eq last-command 'kill-region)
      ;; then-part
      (kill-append  (filter-buffer-substring beg end) (< end beg))
    ;; else-part
    (kill-new  (filter-buffer-substring beg end)))

(The filter-buffer-substring function returns a filtered substring of the buffer, if any. Optionally—the arguments are not here, so neither is done—the function may delete the initial text or return the text without its properties; this function is a replacement for the older buffer-substring function, which came before text properties were implemented.)

The eq function tests whether its first argument is the same Lisp object as its second argument. The eq function is similar to the equal function in that it is used to test for equality, but differs in that it determines whether two representations are actually the same object inside the computer, but with different names. equal determines whether the structure and contents of two expressions are the same.

If the previous command was kill-region, then the Emacs Lisp interpreter calls the kill-append function