1
0
Fork 0

emacs: stop polluting my kill-ring (still needs some adjustments)

This commit is contained in:
Kevin Baensch 2020-06-01 02:28:36 +02:00
parent 3ee8c1eee3
commit f9c4bb6bd7
Signed by: derped
GPG Key ID: C0F1D326C7626543
1 changed files with 59 additions and 0 deletions

View File

@ -100,6 +100,65 @@ in rec {
;; Fix keyboard input of 'dead-keys'
(require 'iso-transl)
;; Some small helper functions
;; These are based on the already existing 'kill' versions of the function
;; It's literally just a M-x r-str kill delete (and getting rid of tabs)
(defun delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument ARG, do this that many times."
(interactive "p")
(delete-region (point) (progn (forward-word arg) (point))))
(define-key global-map [remap kill-word] 'delete-word)
;; (define-key global-map (kbd <>) 'kill-word)
(defun backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument ARG, do this that many times."
(interactive "p")
(delete-word (- arg)))
(define-key global-map [remap backward-kill-word] 'backward-delete-word)
(defun delete-whole-line (&optional arg)
"Delete current line.
With prefix ARG, delete that many lines starting from the current line.
If ARG is negative, delete backward. Also delete the preceding newline.
\(This is meant to make \\[repeat] work well with negative arguments.)
If ARG is zero, delete current line but exclude the trailing newline."
(interactive "p")
(or arg (setq arg 1))
(if (and (> arg 0) (eobp) (save-excursion (forward-visible-line 0) (eobp)))
(signal 'end-of-buffer nil))
(if (and (< arg 0) (bobp) (save-excursion (end-of-visible-line) (bobp)))
(signal 'beginning-of-buffer nil))
(unless (eq last-command 'delete-region)
(delete-new "")
(setq last-command 'delete-region))
(cond ((zerop arg)
;; We need to delete in two steps, because the previous command
;; could have been a delete command, in which case the text
;; before point needs to be prepended to the current delete
;; ring entry and the text after point appended. Also, we
;; need to use save-excursion to avoid copying the same text
;; twice to the delete ring in read-only buffers.
(save-excursion
(delete-region (point) (progn (forward-visible-line 0) (point))))
(delete-region (point) (progn (end-of-visible-line) (point))))
((< arg 0)
(save-excursion
(delete-region (point) (progn (end-of-visible-line) (point))))
(delete-region (point)
(progn (forward-visible-line (1+ arg))
(unless (bobp) (backward-char))
(point))))
(t
(save-excursion
(delete-region (point) (progn (forward-visible-line 0) (point))))
(delete-region (point)
(progn (forward-visible-line arg) (point))))))
(define-key global-map [remap kill-whole-line] 'delete-whole-line)
'';
};