1
votes

The delete-region command in Emacs doesn't behave as expected. It sends the region to the kill-ring, even though it shouldn't.

While deleting one character at a time with delete-backward-char works as expected, i.e. it doesn't send the character to the kill-ring. delete-region sends the highlighted text to the kill-ring. Note that delete-forward-char also works fine. I have identified the problematic behavior by directly calling the command, using M-x delete-region.

I simply wish to delete a region without sending the content of that region to the kill-ring. This follows a litany of queries of a similar flavor. I have already consulted several posts on this topic, including 136581, 637351, 17914475, and 1257365, but none of the proposed solutions work because they tend to solve the problem by referring to using the delete-region command. I have also checked the relevant entry in the emacswiki, but this is not addressing the issue, either.

Here is the description of the command within Emacs:

delete-region is an interactive built-in function in ‘C source code’.

(delete-region START END)

Delete the text between START and END. If called interactively, delete the region between point and mark. This command deletes buffer text without modifying the kill ring.

My experience is that this description is incorrect. I'm using Emacs 25.2.2 on Ubuntu 18.04.

Any help would be very much appreciated.

1
Is the variable select-enable-primary set to t by any chance? That's the only thing I can think of that would explain this behaviour. It means that whenever you select a region, it gets added to the kill ring, regardless of whether you delete it afterwards. - legoscia
Can you replicate the problem starting from emacs -Q ? - phils
What @phils said. delete-region does not copy text to the kill-ring. Something in your setup is causing it to do that - probably something in your init file, but possibly something in your site-lisp.el file, or even possibly something in your Emacs build (unlikely, as it would have been reported). Start by emacs -Q to question your init file. If that's not the problem, check site-lisp.el. If that's not the problem then use M-x report-emacs-bug to report the problem. - Drew
Thanks a lot. Both @phils and @Drew are entirely right. The problem doesn't arise when I use emacs -Q. - Nicomachus
Regarding @legoscia's suggestion, however, I couldn't identify any mention of select-enable-primary in my .emacs file. I could post it, if you want, but it is pretty long, as I have accumulated lots of commands over the years. - Nicomachus

1 Answers

1
votes

In fact, it was pretty straightforward. I just needed to retain the default values for the following two commands.

x-select-enable-primary

x-select-enable-clipboard

In an effort to obtain a better behavior of the yank command outside of Emacs, I ended up compromising the behavior of the yank command inside Emacs. I would advise newbies not to mess up with these particular commands, and to keep the default values.