[PATCH] emacs: Fix bug in clipboard management

Niall Dooley dooleyn at gmail.com
Mon Nov 27 17:57:17 UTC 2023

Prior to this the password/secret was cleared from the kill ring but
remained in the system clipboard after the timeout expired.  This
ensures the system clipboard is cleared as well.
 contrib/emacs/password-store.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/contrib/emacs/password-store.el b/contrib/emacs/password-store.el
index 280aee5..c28bc7d 100644
--- a/contrib/emacs/password-store.el
+++ b/contrib/emacs/password-store.el
@@ -262,7 +262,7 @@ the stored secret to clear; if nil, then set it to 'secret.
 Note, FIELD does not affect the function logic; it is only used
 to display the message:
-\(message \"Field %s cleared.\" field)."
+\(message \"Field %s cleared from kill ring and system clipboard.\" field)."
   (interactive "i")
   (unless field (setq field 'secret))
   (when password-store-timeout-timer
@@ -270,14 +270,15 @@ to display the message:
     (setq password-store-timeout-timer nil))
   (when password-store-kill-ring-pointer
     (setcar password-store-kill-ring-pointer "")
+    (kill-new "")
     (setq password-store-kill-ring-pointer nil)
-    (message "Field %s cleared." field)))
+    (message "Field %s cleared from kill ring and system clipboard." field)))
 (defun password-store--save-field-in-kill-ring (entry secret field)
   (password-store-clear field)
   (kill-new secret)
   (setq password-store-kill-ring-pointer kill-ring-yank-pointer)
-  (message "Copied %s for %s to the kill ring. Will clear in %s seconds."
+  (message "Copied %s for %s to the kill ring and system clipboard. Will clear in %s seconds."
            field entry password-store-time-before-clipboard-restore)
   (setq password-store-timeout-timer
         (run-at-time password-store-time-before-clipboard-restore nil

More information about the Password-Store mailing list