From 4935be7cc68822796d2359321b66e9cb2d92ec6e Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Wed, 1 May 2019 19:00:43 -0400 Subject: Add replacement for 'kill-visual-line --- jakob.org | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'jakob.org') diff --git a/jakob.org b/jakob.org index a73abc3..ecb4c7e 100644 --- a/jakob.org +++ b/jakob.org @@ -308,8 +308,8 @@ Unbind and so that I'm not accidentally calling =suspend-frame=. ** Kill-Ring -Replace =kill-word= and =backward-kill-word= with equivalents that do not push the -region to the kill ring. +Replace =kill-word=, =backward-kill-word=, and =kill-visual-line= with equivalents +that do not copy the region into the kill ring. #+BEGIN_SRC elisp (defun delete-word (arg) @@ -324,8 +324,35 @@ With argument ARG, do this that many times." (interactive "p") (delete-word (- arg))) +(defun delete-visual-line (&optional arg) + "Delete the rest of the visual line. +With prefix argument ARG, delete that many visual lines from point. +If ARG is negative, delete visual lines backward. +If ARG is zero, delete the text before point on the current visual +line." + (interactive "P") + ;; Like in `kill-line', it's better to move point to the other end + ;; of the kill before killing. + (let ((opoint (point)) + (delete-whole-line (and kill-whole-line (bolp)))) + (if arg + (vertical-motion (prefix-numeric-value arg)) + (end-of-visual-line 1) + (if (= (point) opoint) + (vertical-motion 1) + ;; Skip any trailing whitespace at the end of the visual line. + ;; We used to do this only if `show-trailing-whitespace' is + ;; nil, but that's wrong; the correct thing would be to check + ;; whether the trailing whitespace is highlighted. But, it's + ;; OK to just do this unconditionally. + (skip-chars-forward " \t"))) + (delete-region opoint (if (and delete-whole-line (= (following-char) ?\n)) + (1+ (point)) + (point))))) + (bind-key "M-d" #'delete-word) (bind-key "M-DEL" #'backward-delete-word) +(bind-key "C-k" #'delete-visual-line) #+END_SRC * Quality-of-Life -- cgit v1.3