From 28e7363314061e2a98ba29919146bf51e8f06770 Mon Sep 17 00:00:00 2001 From: Madhu Date: Thu, 10 Mar 2016 14:37:20 +0530 Subject: [PATCH] initial fixes ;; madhu 120322 1. avoid deadlock ;; when calling C-y (call-process("xclip-o")) in a terminal when an ;; emacs X frame owns the selection. 1a. (current-kill 0) when emacs ;; owns the primary. 2. a sit-for in xclip-select-text avoids deadlock ;; when calling C-y in a frame when xclip owns the selection. this ;; happens when M-w'ing a text which has text-properties and C-y'ing sitfor workaround. (selection-value--internal): new dispatch to (xclip-selection-value-synchrnous):new or gui-selection-value internal. --- xclip.el | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/xclip.el b/xclip.el index 4fe07d3..c76e130 100644 --- a/xclip.el +++ b/xclip.el @@ -50,6 +50,15 @@ ;; copy/pasting from an external application to Emacs and not from Emacs to ;; another application (for which it relies on the default code). +;; madhu 120322 1. avoid deadlock +;; when calling C-y (call-process("xclip-o")) in a terminal when an +;; emacs X frame owns the selection. 1a. (current-kill 0) when emacs +;; owns the primary. 2. a sit-for in xclip-select-text avoids deadlock +;; when calling C-y in a frame when xclip owns the selection. this +;; happens when M-w'ing a text which has text-properties and C-y'ing +;; it. +;; + ;;; Code: (defgroup xclip () @@ -156,7 +165,8 @@ (defun xclip-set-selection (type data) (method (error "Unknown `xclip-method': %S" method))))) (when proc (process-send-string proc data) - (process-send-eof proc)) + (process-send-eof proc) + (sit-for .2)) data))) (defun xclip-get-selection (type) @@ -268,7 +278,13 @@ (defun xclip--hidden-frame () &context (window-system nil)) (if (not xclip-mode) (cl-call-next-method) - (xclip-get-selection selection-symbol))) + (cond ((fboundp 'x-selection-exists-p) ; X build + (cond ((x-selection-exists-p selection-symbol) + (cond ((x-selection-owner-p selection-symbol) + (cl-call-next-method)) + (t (xclip-get-selection selection-symbol)))) + (t (xclip-get-selection selection-symbol)))) + (t (xclip-get-selection selection-symbol))))) (cl-defmethod gui-backend-set-selection (selection-symbol value &context (window-system nil)) @@ -311,10 +327,29 @@ (defun xclip--hidden-frame () (xclip-set-selection 'clipboard text) (setq xclip-last-selected-text-clipboard text))) + (defun xclip-selection-value--synchronous (type) + (with-output-to-string + (process-file xclip-program nil standard-output nil + "-o" "-selection" (symbol-name type)))) + + (defun xclip-selection-value--internal (type) + (cond ((and (fboundp 'x-selection-exists-p) ; X build + ;(eq window-system 'x) + ) + (cond ((x-selection-exists-p type) + (cond ((x-selection-owner-p type) + ;;thanks stefan monnier for spit cl-generic + (let ((window-system 'x)) + (gui--selection-value-internal type))) + (t (xclip-selection-value--synchronous type)))) + (t + (xclip-selection-value--synchronous type)))) + (t (xclip-selection-value--synchronous type)))) + (defun xclip-selection-value () "See `x-selection-value'." (let ((clip-text (when xclip-select-enable-clipboard - (xclip-get-selection 'CLIPBOARD)))) + (xclip-selection-value--internal 'CLIPBOARD)))) (setq clip-text (cond ; Check clipboard selection. ((or (not clip-text) (string= clip-text "")) @@ -329,9 +364,7 @@ (defun xclip--hidden-frame () (t (setq xclip-last-selected-text-clipboard clip-text)))) (or clip-text (when (and (memq xclip-method '(xsel xclip)) (getenv "DISPLAY")) - (let ((primary-text (with-output-to-string - (call-process xclip-program nil - standard-output nil "-o")))) + (let ((primary-text (xclip-selection-value--internal 'PRIMARY))) (setq primary-text (cond ; Check primary selection. ((or (not primary-text) (string= primary-text "")) -- 2.46.0.27.gfa3b914457