Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
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.)
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)
(prog1 (kill-ring-save beg end)
(setq deactivate-mark nil)))
(defun yf/no-deactivate-mark (&rest _) (setq deactivate-mark nil)) (advice-addadvice-add 'kill-ring-save :after #'yf/no-deactivate-mark)
Required, but never shown