The approach I follow is to just rewrite
kill-line to use
delete-region instead of
kill-region. The functions
delete-region are almost the same. The big different is that the former saves what's deleted in the kill ring. The latter doesn't. Rewriting the function with this replacement retains the exact behavior of
kill-line without any side effects.
(defun my/kill-line (&optional arg)
"Delete the rest of the current line; if no nonblanks there, delete thru newline.
With prefix argument ARG, delete that many lines from point.
Negative arguments delete lines backward.
With zero argument, delete the text before point on the current line.
When calling from a program, nil means \"no arg\",
a number counts as a prefix arg.
If `show-trailing-whitespace' is non-nil, this command will just
delete the rest of the current line, even if there are no nonblanks
If option `kill-whole-line' is non-nil, then this command deletes the whole line
including its terminating newline, when used at the beginning of a line
with no argument.
If the buffer is read-only, Emacs will beep and refrain from deleting
(forward-visible-line (prefix-numeric-value arg))
(signal 'end-of-buffer nil))
(if (or (save-excursion
;; If trailing whitespace is visible,
;; don't treat it as nothing.
(skip-chars-forward " \t" end))
(= (point) end))
(and kill-whole-line (bolp)))
(global-set-key (kbd "C-k") 'my/kill-line)