When I hit "undo" in emacs it undoes the my edit, but I lose the selected region, and I have to go back and reselect it. Is there a way to bind undo so it'll select the last selected region
The best I can come up with was:
(global-set-key (kbd "\C-o")
(lambda()
(interactive)
(progn (undo)
(exchange-point-and-mark)
)))
You do NOT lose the region. The region remains in the yank-ring.
If you want to re-select it, you can simply call exchange-point-and-mark
, which is bound by default to C-xC-x.
You can always use advice to take what you have and wrap it around undo
:
(defadvice undo (around reactivate-mark (&optional arg) activate)
(let ((ma mark-active))
ad-do-it
;; Reactiveate mark if it was active
(when ma
(exchange-point-and-mark))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With