Deleting a chunk of text from the cursor causes the deleted contents to be copied into the kill ring, overwriting whatever I had stored there. How do I stop this from happening?
If you look at what M-backspace
calls using C-h <M-backspace>
you see that it calls backward-kill-word
that function simply calls kill-word
with a negative argument. The kill-word
function is coded as:
(defun kill-word (arg)
"Kill characters forward until encountering the end of a word.
With argument ARG, do this that many times."
(interactive "p")
(kill-region (point) (progn (forward-word arg) (point))))
If we write a function that does the same thing using delete-region
instead of kill-region
we'll get the desired result. Here is our new delete-word
function:
(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))))
We can now write our own backward-delete-word
using backward-kill-work
as an example like this:
(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)))
afterwards all we need to do is bind this new function to <M-backspace>
!
If you have any questions just let me know!
kill-ring-max
kills. Use C-y and repeated M-y to yank older content. doc – JeanPierre Mar 3 '16 at 19:45