From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Josh Newsgroups: gmane.emacs.bugs Subject: bug#13790: Cannot paste with C-y into Homebrew emacs v24.2.1 Date: Wed, 3 Apr 2013 10:07:20 -0700 Message-ID: References: <988801E5-2282-4367-A46E-7A05A63069AD@swipnet.se> <1790161F-1C74-43D3-AFEE-40EAF0B2AFBB@swipnet.se> <83obew1bub.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1365008890 26433 80.91.229.3 (3 Apr 2013 17:08:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Apr 2013 17:08:10 +0000 (UTC) Cc: 13790@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 03 19:08:37 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UNRAn-0006rC-IS for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Apr 2013 19:08:33 +0200 Original-Received: from localhost ([::1]:48404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNRAO-0002xL-NY for geb-bug-gnu-emacs@m.gmane.org; Wed, 03 Apr 2013 13:08:08 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:40807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNRAJ-0002x7-72 for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2013 13:08:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNRAE-0006pf-KR for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2013 13:08:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNRAE-0006pC-Gg for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2013 13:07:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UNRDC-0006i3-DS for bug-gnu-emacs@gnu.org; Wed, 03 Apr 2013 13:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Josh Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 Apr 2013 17:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13790 X-GNU-PR-Package: emacs,ns X-GNU-PR-Keywords: moreinfo unreproducible Original-Received: via spool by 13790-submit@debbugs.gnu.org id=B13790.136500906125783 (code B ref 13790); Wed, 03 Apr 2013 17:11:02 +0000 Original-Received: (at 13790) by debbugs.gnu.org; 3 Apr 2013 17:11:01 +0000 Original-Received: from localhost ([127.0.0.1]:60306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UNRDA-0006ho-Nn for submit@debbugs.gnu.org; Wed, 03 Apr 2013 13:11:01 -0400 Original-Received: from mail-we0-f180.google.com ([74.125.82.180]:64934) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UNRD6-0006hc-KK for 13790@debbugs.gnu.org; Wed, 03 Apr 2013 13:10:58 -0400 Original-Received: by mail-we0-f180.google.com with SMTP id r5so1334274wey.11 for <13790@debbugs.gnu.org>; Wed, 03 Apr 2013 10:07:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :x-gm-message-state; bh=sFVjy8h0wYBjIcNSfCIgym46qkEtC9SKW8LJJw0/gsg=; b=Q66xrVwCD6YZWn5P1JxqfAirHmCQjaz662tYPhhJz8b78AzHk1yUhO6Ru2E5+JwBgV LaDQFc85b06eP/i8m/z69U5LVxu5iE31rPxvEswDZnF9kKg/fGcdaq/K7O7BGsINlCnn DW4ft7AATNOlp4b4958mA+f8AI4QksXrU8iVXVGGJTD3hfzZCG1lB8qkpxGF63ZkLt7z xhME91gE8wOuSF6aLIhLOTv5suk9ku6yMuoV8R1yiymQbI//f0C8wonWPBsKFkad46ET KZnbIT35kxcCV8s8zDZfplJT5a52ysh/JU5f7clQuDyypuvwO8kemM/vdxJlwbn+hHOr awCw== X-Received: by 10.180.98.198 with SMTP id ek6mr4060624wib.7.1365008870502; Wed, 03 Apr 2013 10:07:50 -0700 (PDT) Original-Received: by 10.194.42.137 with HTTP; Wed, 3 Apr 2013 10:07:20 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: WUeURJe-tPoEBZnWpGbPIZgta7A X-Gm-Message-State: ALoCoQkHHZ333F/s5cjg7z1OGAxCQLBTxoNWmc901pEMbBGCjHMCLrhESdapWTkyW+559HCMs2BV X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:73111 Archived-At: On Wed, Mar 13, 2013 at 11:04 AM, Stefan Monnier wrote: >> I'd be happy to contribute it, > > Cool. Could you try and make it into a patch to xclip.el, then? OK, I took a stab at it and it seems to work correctly under OS X in -nw mode. I do not have access to a system running X at the moment so someone should verify that the original functionality remains intact. Please also review the change to the define-minor-mode form, where I replaced the use of terminal-init-xterm-hook with direct calls to turn-{on,off}-xclip. I hadn't heard of this hook before and my impression after a brief investigation is that these terminal-init hooks are selected based on the value of TERM during initialization and then run before user init. If that's so then I don't see how adding (xclip-mode 1) to users' .emacs as the commentary suggests could possibly work, since that would cause turn-on-xclip-mode to be added to a hook that had already run. I assume I'm missing something here, but someone more familiar with the init sequence than I am should review the mode enablement implementation. Also, if my impression that the specific terminal-init hook is selected based on TERM is correct then I don't see how the current implementation could be working for users with TERM set to rxvt, screen, screen-256color, etc. I removed the optional `push' argument to xclip-select-text because it was unused within the function and also because xclip-select-text is a target of interprogram-cut-function, whose docstring specifies that its targets are called with exactly one argument. >> Also, I see that xclip.el resides in the GNU ELPA repository. Since >> it's likely that many people using Emacs in -nw mode would like to >> integrate Emacs kill and yank operations with their operating systems' >> clipboards, I wonder if it would be worthwhile for some or all of >> xclip.el's functionality to move into the core. >I don't think xclip-mode can be enabled by default (at least not at >this stage), so the only thing we can improve is to bundle xclip.el with >Emacs, although installing a package from GNU ELPA is simple enough that >the pressure to do that is not very high. Enabling xclip-mode by default or at least bundling it with Emacs seems worthwhile to me because it represents such an improvement to Emacs' useability for -nw users. In any case, regardless of whether or not Emacs ships with xclip.el, mentioning its existence in the empty kill ring error message encountered by the reporter would spur users to investigate how to enable or install it. Note: `xclip.el.orig' below was retrieved from http://elpa.gnu.org/packages/xclip-1.0.el --- xclip.el.orig 2012-11-29 08:41:30.000000000 -0800 +++ xclip.el 2013-04-03 08:40:39.000000000 -0700 @@ -28,7 +28,13 @@ ;;; Code: (defvar xclip-program "xclip" - "Name of XClip program tool.") + "Path to the xclip program which provides an interface to the X clipboard.") + +(defvar xclip-ns-copy-program "pbcopy" + "Path to the pbcopy program, an interface to the Nextstep/OS X clipboard.") + +(defvar xclip-ns-paste-program "pbpaste" + "Path to the pbpaste program, an interface to the Nextstep/OS X clipboard.") (defvar xclip-select-enable-clipboard t "Non-nil means cutting and pasting uses the clipboard. @@ -51,7 +57,7 @@ (process-send-string proc data) (process-send-eof proc)))) -(defun xclip-select-text (text &optional push) +(defun xclip-select-text (text) "See `x-select-text'." (xclip-set-selection 'primary text) (setq xclip-last-selected-text-primary text) @@ -59,6 +65,20 @@ (xclip-set-selection 'clipboard text) (setq xclip-last-selected-text-clipboard text))) +(defun xclip-ns-paste () + "Return the text on the Nextstep/OS X system pasteboard." + (let ((coding-system-for-read 'utf-8)) + (shell-command-to-string xclip-ns-paste-program))) + +(defun xclip-ns-cut (text) + "Send TEXT to the Nextstep/OS X system pasteboard." + (let ((process-connection-type nil)) + (let ((proc (start-process "pbcopy" "*Messages*" xclip-ns-copy-program))) + (set-process-sentinel proc 'ignore) ;; stifle noise in *Messages* + (process-send-string proc text) + (process-send-eof proc))) + text) + (defun xclip-selection-value () "See `x-cut-buffer-or-selection-value'." (when (and (executable-find xclip-program) (getenv "DISPLAY")) @@ -94,8 +114,13 @@ (or clip-text primary-text)))) (defun turn-on-xclip () - (setq interprogram-cut-function 'xclip-select-text) - (setq interprogram-paste-function 'xclip-selection-value)) + (cond ((eq system-type 'darwin) + (setq interprogram-cut-function 'xclip-ns-cut + interprogram-paste-function 'xclip-ns-paste)) + ((getenv "DISPLAY") + (setq interprogram-cut-function 'xclip-select-text + interprogram-paste-function 'xclip-selection-value)) + (t (error "No interface to operating system clipboard found")))) (defun turn-off-xclip () (setq interprogram-cut-function nil) @@ -103,11 +128,11 @@ ;;;###autoload (define-minor-mode xclip-mode - "Minor mode to use the `xclip' program to copy&paste." + "Minor mode to integrate operating system clipboards with kills and yanks." :global t (if xclip-mode - (add-hook 'terminal-init-xterm-hook 'turn-on-xclip) - (remove-hook 'terminal-init-xterm-hook 'turn-on-xclip))) + (turn-on-xclip) + (turn-off-xclip))) ;;;; ChangeLog: