emacs-diffs
[Top][All Lists]
Advanced

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

master 16174d796f: Avoid extraneous selection querying if we own the sel


From: Po Lu
Subject: master 16174d796f: Avoid extraneous selection querying if we own the selection
Date: Mon, 31 Jan 2022 21:08:57 -0500 (EST)

branch: master
commit 16174d796f86fe31c4a20ece471bed10f23c229f
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Avoid extraneous selection querying if we own the selection
    
    * lisp/select.el (gui--selection-value-internal): Return nil if
    `gui-backend-selection-owner-p' on window systems where it is
    reliable.
---
 lisp/select.el | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/lisp/select.el b/lisp/select.el
index 7f29f02dab..420967c1b0 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -168,20 +168,26 @@ text/plain\\;charset=utf-8)."
 Call `gui-get-selection' with an appropriate DATA-TYPE argument
 decided by `x-select-request-type'.  The return value is already
 decoded.  If `gui-get-selection' signals an error, return nil."
-  (let ((request-type (if (memq window-system '(x pgtk))
-                          (or x-select-request-type
-                              '(UTF8_STRING COMPOUND_TEXT STRING 
text/plain\;charset=utf-8))
-                        'STRING))
-       text)
-    (with-demoted-errors "gui-get-selection: %S"
-      (if (consp request-type)
-          (while (and request-type (not text))
-            (setq text (gui-get-selection type (car request-type)))
-            (setq request-type (cdr request-type)))
-        (setq text (gui-get-selection type request-type))))
-    (if text
-       (remove-text-properties 0 (length text) '(foreign-selection nil) text))
-    text))
+  ;; The doc string of `interprogram-paste-function' says to return
+  ;; nil if no other program has provided text to paste.
+  (unless (and (memq window-system '(x haiku))
+               ;; gui-backend-selection-p might be unreliable on other
+               ;; window systems.
+               (gui-backend-selection-owner-p type))
+    (let ((request-type (if (memq window-system '(x pgtk))
+                            (or x-select-request-type
+                                '(UTF8_STRING COMPOUND_TEXT STRING 
text/plain\;charset=utf-8))
+                          'STRING))
+         text)
+      (with-demoted-errors "gui-get-selection: %S"
+        (if (consp request-type)
+            (while (and request-type (not text))
+              (setq text (gui-get-selection type (car request-type)))
+              (setq request-type (cdr request-type)))
+          (setq text (gui-get-selection type request-type))))
+      (if text
+         (remove-text-properties 0 (length text) '(foreign-selection nil) 
text))
+      text)))
 
 (defun gui-selection-value ()
   (let ((clip-text



reply via email to

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