From edf46425bb0f78ca5f571de2761e94ad7caf7aab Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sat, 13 Aug 2022 22:39:53 +0800 Subject: [PATCH] org-copy-visible: Prevent Emacs storing primary-selection in kill-ring * lisp/org.el (org-copy-visible): Make sure that the visible text is the first entry in `kill-ring' upon exiting `org-copy-visible'. This was previously not the case when `select-enable-primary' is non-nil. The fix only works in Emacs 29 after https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=0ab572d5c991dee4818d364a65e004d20f1f45a1 See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=57147 Fixes https://orgmode.org/list/25331.25617.528381.574211@gargle.gargle.HOWL --- lisp/org.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index c46e7cbcfa..9e8155391f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16972,7 +16972,10 @@ this numeric value." (let ((next (next-single-char-property-change beg 'invisible nil end))) (setq result (concat result (buffer-substring beg next))) (setq beg next)))) - (setq deactivate-mark t) + ;; Prevent Emacs from adding full selected text to `kill-ring' + ;; when `select-enable-primary' is non-nil. This special value of + ;; `deactivate-mark' only works since Emacs 29. + (setq deactivate-mark 'dont-save) (kill-new result) (message "Visible strings have been copied to the kill ring.")))