emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 407062c: Allow save-interprogram-paste-before-kill to be a number


From: Lars Ingebrigtsen
Subject: master 407062c: Allow save-interprogram-paste-before-kill to be a number
Date: Sun, 13 Jun 2021 08:04:53 -0400 (EDT)

branch: master
commit 407062c296677f8d370706c8a620d2526a83df97
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Allow save-interprogram-paste-before-kill to be a number
    
    * doc/emacs/killing.texi (Clipboard): Document it.
    * lisp/simple.el (save-interprogram-paste-before-kill): Extend
    range (bug#41168).
    (kill-new): Implement it (bug#41168).
---
 doc/emacs/killing.texi | 13 ++++++++-----
 etc/NEWS               |  5 +++++
 lisp/simple.el         | 29 ++++++++++++++++++++---------
 3 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/doc/emacs/killing.texi b/doc/emacs/killing.texi
index 56763b2..4291afe 100644
--- a/doc/emacs/killing.texi
+++ b/doc/emacs/killing.texi
@@ -522,11 +522,14 @@ clipboard.
 
 @vindex save-interprogram-paste-before-kill
   When an Emacs kill command puts text in the clipboard, the existing
-clipboard contents are normally lost.  Optionally, you can change
-@code{save-interprogram-paste-before-kill} to @code{t}.  Then Emacs
-will first save the clipboard to its kill ring, preventing you from
-losing the old clipboard data---at the risk of high memory consumption
-if that data turns out to be large.
+clipboard contents are normally lost.  Optionally, Emacs can save the
+existing clipboard contents to the kill ring, preventing you from
+losing the old clipboard data.  If
+@code{save-interprogram-paste-before-kill} changed to a number, then
+this data is copied over if it's smaller (in characters) than this
+number.  If this variable is any other non-@code{nil} value, it's
+always copied over---at the risk of high memory consumption if that
+data turns out to be large.
 
   Yank commands, such as @kbd{C-y} (@code{yank}), also use the
 clipboard.  If another application ``owns'' the clipboard---i.e., if
diff --git a/etc/NEWS b/etc/NEWS
index 1693342..d3ee5659a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2087,6 +2087,11 @@ Shift while typing 'C-a', i.e. 'C-S-a', will now 
highlight the text.
 
 ** Miscellaneous
 
++++
+*** 'save-interprogram-paste-before-kill' can now be a number.
+In that case, it's interpreted as a limit to how long the clipboard
+data can be before saving to the kill ring.
+
 ---
 *** New variable 'hl-line-overlay-priority'.
 This can be used to change the priority of the hl-line overlays.
diff --git a/lisp/simple.el b/lisp/simple.el
index 90dd8f1..dfe2549 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5041,8 +5041,14 @@ ring directly.")
 A non-nil value ensures that Emacs kill operations do not
 irrevocably overwrite existing clipboard text by saving it to the
 `kill-ring' prior to the kill.  Such text can subsequently be
-retrieved via \\[yank] \\[yank-pop]."
-  :type 'boolean
+retrieved via \\[yank] \\[yank-pop].
+
+This variable can be either a number (in which case the clipboard
+data is only saved if it's shorter (in characters) than that
+number.  Any other non-nil value will save the clipboard data
+unconditionally."
+  :type '(choice (const :tag "Always" t)
+                 number)
   :group 'killing
   :version "23.2")
 
@@ -5079,13 +5085,18 @@ argument should still be a \"useful\" string for such 
uses."
     (let ((interprogram-paste (and interprogram-paste-function
                                    (funcall interprogram-paste-function))))
       (when interprogram-paste
-        (dolist (s (if (listp interprogram-paste)
-                       ;; Use `reverse' to avoid modifying external data.
-                       (reverse interprogram-paste)
-                    (list interprogram-paste)))
-         (unless (and kill-do-not-save-duplicates
-                      (equal-including-properties s (car kill-ring)))
-           (push s kill-ring))))))
+        (setq interprogram-paste
+              (if (listp interprogram-paste)
+                  ;; Use `reverse' to avoid modifying external data.
+                  (reverse interprogram-paste)
+               (list interprogram-paste)))
+        (when (or (not (numberp save-interprogram-paste-before-kill))
+                  (< (seq-reduce #'+ (mapcar #'length interprogram-paste) 0)
+                     save-interprogram-paste-before-kill))
+          (dolist (s interprogram-paste)
+           (unless (and kill-do-not-save-duplicates
+                         (equal-including-properties s (car kill-ring)))
+             (push s kill-ring)))))))
   (unless (and kill-do-not-save-duplicates
               (equal-including-properties string (car kill-ring)))
     (if (and replace kill-ring)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]