14

When I copy some selected text (kill-ring-save with M-w), I automatically lose my selection. I have tried with Transient Mark Mode with no luck. (Note that I'm not using CUA Mode.)

1
  • I initially thought it was about the X selection (in which case the variable select-active-regions would be relevant), but it seems to be about highlighting the region.
    – YoungFrog
    Feb 1, 2016 at 10:46

1 Answer 1

11

The best solution is using C-x C-x to reactivate the mark. But if you want to really keep the selection you can use:

(defun copy-keep-highlight (beg end)
  (interactive "r")
  (prog1 (kill-ring-save beg end)
    (setq deactivate-mark nil)))
6
  • 1
    I'd suggest using a piece of advice like this : (defun yf/no-deactivate-mark (&rest _) (setq deactivate-mark nil)) (advice-addadvice-add 'kill-ring-save :after #'yf/no-deactivate-mark)
    – YoungFrog
    Feb 1, 2016 at 10:48
  • @djangoliv, thanks. What is this prog1?
    – NVaughan
    Feb 2, 2016 at 1:18
  • @YoungFrog, thanks, but your code doesn't work as its got a syntax error somewhere.
    – NVaughan
    Feb 2, 2016 at 1:19
  • 2
    Ah, copy paste error : advice-add should be there only once. I can't edit the comment.
    – YoungFrog
    Feb 2, 2016 at 9:20
  • 1
    @NVaughan here a good explanation: emacs.stackexchange.com/questions/5829/…
    – djangoliv
    Feb 2, 2016 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.