Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delete only one character when region is highlighted

Tags:

emacs

elisp

I cannot find the setting that prevents deletion of an entire region when you have it highlighted and you hit backspace... (I just want it to delete one character even if a region is highlighted.) I already have

(delete-selection-mode 0)

and in custom-set-variables (I have cua-mode enabled for its rectangle functions),

'(cua-delete-selection nil)

but that is the behavior I get. Am I missing something?

like image 227
hatmatrix Avatar asked Aug 30 '10 12:08

hatmatrix


2 Answers

Found it:

(setq delete-active-region nil)

is the answer. Thanks to all for toughing it out with me!

like image 145
hatmatrix Avatar answered Oct 08 '22 19:10

hatmatrix


Emacs has different behavior depending on whether the highlighting was done with mouse or the keyboard.

Even in transient-mark-mode, if you set the mark and move the point, using backspace will not delete the region. delete-selection-mode is a minor mode that changes this behavior.

When using the mouse to highlight a region, regardless of delete-selection-mode, using backspace will delete the region that was highlighted with the mouse. From Section 25.1.1 of the manual:

"While the region remains active, typing or deletes the text in that region and deactivates the mark; this behavior follows a convention established by other graphical programs, and it does not apply when you set the region any other way, including shift-selection (*note Shift Selection::)."

Based on this, it sounds like you're selecting the region using the mouse. Is that correct? Does the same behavior arise when using shift-select-mode or simply using mark and point?

like image 34
R. P. Dillon Avatar answered Oct 08 '22 20:10

R. P. Dillon