A abordagem que eu sigo é apenas reescrever kill-line
para usar delete-region
em vez de kill-region
. As funções kill-region
e delete-region
são quase iguais. O grande diferencial é que o primeiro salva o que é deletado no kill ring. Este último não. Reescrevendo a função com essa substituição mantém o comportamento exato de kill-line
sem nenhum efeito colateral.
(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
there.
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
the line."
(interactive "P")
(delete-region
(point)
(progn
(if arg
(forward-visible-line (prefix-numeric-value arg))
(if (eobp)
(signal 'end-of-buffer nil))
(let ((end
(save-excursion
(end-of-visible-line) (point))))
(if (or (save-excursion
;; If trailing whitespace is visible,
;; don't treat it as nothing.
(unless show-trailing-whitespace
(skip-chars-forward " \t" end))
(= (point) end))
(and kill-whole-line (bolp)))
(forward-visible-line 1)
(goto-char end))))
(point))))
(global-set-key (kbd "C-k") 'my/kill-line)