[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xclip 5b55f20 04/18: * xclip.el: Use pbcopy and pbpaste
From: |
Stefan Monnier |
Subject: |
[elpa] externals/xclip 5b55f20 04/18: * xclip.el: Use pbcopy and pbpaste if available |
Date: |
Sat, 28 Nov 2020 14:27:55 -0500 (EST) |
branch: externals/xclip
commit 5b55f208f41ada5fe3e3d1afa27650272193f5af
Author: Leo Liu <sdl.web@gmail.com>
Commit: Leo Liu <sdl.web@gmail.com>
* xclip.el: Use pbcopy and pbpaste if available
(xclip-use-pbcopy&paste): New variable.
(xclip-set-selection, xclip-selection-value, xclip-mode): Use it.
---
xclip.el | 68 +++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 44 insertions(+), 24 deletions(-)
diff --git a/xclip.el b/xclip.el
index d08dcd2..bc9b640 100644
--- a/xclip.el
+++ b/xclip.el
@@ -5,7 +5,7 @@
;; Author: Leo Liu <sdl.web@gmail.com>
;; Keywords: convenience, tools
;; Created: 2007-12-30
-;; Version: 1.1
+;; Version: 1.2
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -41,6 +41,15 @@ This is in addition to, but in preference to, the primary
selection."
:type 'boolean
:group 'killing)
+(defcustom xclip-use-pbcopy&paste (and xclip-select-enable-clipboard
+ (eq system-type 'darwin)
+ (executable-find "pbcopy")
+ t)
+ "Non-nil means using pbcopy and pbpaste instead of xclip.
+If non-nil `xclip-program' is ignored."
+ :type 'boolean
+ :group 'killing)
+
(defvar xclip-last-selected-text-clipboard nil
"The value of the CLIPBOARD X selection from xclip.")
@@ -51,12 +60,17 @@ This is in addition to, but in preference to, the primary
selection."
"TYPE is a symbol: primary, secondary and clipboard.
See also `x-set-selection'."
- (when (getenv "DISPLAY")
- (let* ((process-connection-type nil)
- (proc (start-process "xclip" nil xclip-program
- "-selection" (symbol-name type))))
+ (let* ((process-connection-type nil)
+ (proc (cond
+ (xclip-use-pbcopy&paste
+ (start-file-process "pbcopy" nil "pbcopy"))
+ ((getenv "DISPLAY")
+ (start-file-process "xclip" nil xclip-program
+ "-selection" (symbol-name type))))))
+ (when proc
(process-send-string proc data)
- (process-send-eof proc))))
+ (process-send-eof proc))
+ data))
(defun xclip-select-text (text)
"See `x-select-text'."
@@ -68,24 +82,28 @@ See also `x-set-selection'."
(defun xclip-selection-value ()
"See `x-selection-value'."
- (when (getenv "DISPLAY")
- (let ((clip-text (when xclip-select-enable-clipboard
- (with-output-to-string
+ (let ((clip-text (when xclip-select-enable-clipboard
+ (with-output-to-string
+ (cond
+ (xclip-use-pbcopy&paste
+ (process-file "pbpaste" nil standard-output nil))
+ ((getenv "DISPLAY")
(process-file xclip-program nil standard-output nil
- "-o" "-selection" "clipboard")))))
- (setq clip-text
- (cond ; Check clipboard selection.
- ((or (not clip-text) (string= clip-text ""))
- (setq xclip-last-selected-text-clipboard nil))
- ((eq clip-text xclip-last-selected-text-clipboard)
- nil)
- ((string= clip-text xclip-last-selected-text-clipboard)
- ;; Record the newer string so subsequent calls can use
- ;; the `eq' test.
- (setq xclip-last-selected-text-clipboard clip-text)
- nil)
- (t (setq xclip-last-selected-text-clipboard clip-text))))
- (or clip-text
+ "-o" "-selection" "clipboard")))))))
+ (setq clip-text
+ (cond ; Check clipboard selection.
+ ((or (not clip-text) (string= clip-text ""))
+ (setq xclip-last-selected-text-clipboard nil))
+ ((eq clip-text xclip-last-selected-text-clipboard)
+ nil)
+ ((string= clip-text xclip-last-selected-text-clipboard)
+ ;; Record the newer string so subsequent calls can use the
+ ;; `eq' test.
+ (setq xclip-last-selected-text-clipboard clip-text)
+ nil)
+ (t (setq xclip-last-selected-text-clipboard clip-text))))
+ (or clip-text
+ (when (getenv "DISPLAY")
(let ((primary-text (with-output-to-string
(process-file xclip-program nil
standard-output nil "-o"))))
@@ -113,9 +131,11 @@ See also `x-set-selection'."
:global t
(if xclip-mode
(progn
- (or (executable-find xclip-program)
+ (or xclip-use-pbcopy&paste
+ (executable-find xclip-program)
(signal 'file-error (list "Searching for program"
xclip-program "no such file")))
+ ;; NOTE: See `tty-run-terminal-initialization' and term/README
(add-hook 'terminal-init-xterm-hook 'turn-on-xclip))
(remove-hook 'terminal-init-xterm-hook 'turn-on-xclip)))
- [elpa] branch externals/xclip created (now 0118d7a), Stefan Monnier, 2020/11/28
- [elpa] externals/xclip d778c36 01/18: Add xclip.el., Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 201b390 03/18: * xclip.el: Some cleanups and fix copyright years., Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 5b55f20 04/18: * xclip.el: Use pbcopy and pbpaste if available,
Stefan Monnier <=
- [elpa] externals/xclip 145cdb7 06/18: * xclip/xclip.el: Use gui-backend-*-selection in Emacs≥25, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 1c536bb 05/18: * xclip.el: Fix last change, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 6d62531 10/18: * xclip/xclip.el: Add new `emacs` method, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip ad395be 08/18: * xclip/xclip.el: Fix bug#33399, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 7b7b6d2 13/18: xclip.el: Add support for termux-clipboard-get/set, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 0029bde 16/18: * packages/xclip/xclip.el: Fix it when loaded before term/xterm.el, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 0118d7a 18/18: * .gitignore: New file, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip 89e061e 14/18: * packages/xclip/xclip.el: Tweak last patch, Stefan Monnier, 2020/11/28
- [elpa] externals/xclip a5e0330 02/18: * xclip.el: Better follow conventions., Stefan Monnier, 2020/11/28
- [elpa] externals/xclip ef584a0 11/18: * xclip/xclip.el: Don't use remote processes to get selection, Stefan Monnier, 2020/11/28