unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Josh <josh@foxtail.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 13790@debbugs.gnu.org
Subject: bug#13790: Cannot paste with C-y into Homebrew emacs v24.2.1
Date: Wed, 3 Apr 2013 10:07:20 -0700	[thread overview]
Message-ID: <CANdFEAF9btn5TY3_BzYRoaF_RyAJ1HoHDHe97x4RO6_0cDhp6Q@mail.gmail.com> (raw)
In-Reply-To: <jwvli9r18x6.fsf-monnier+emacs@gnu.org>

On Wed, Mar 13, 2013 at 11:04 AM, Stefan Monnier
<monnier@iro.umontreal.ca> 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:





  reply	other threads:[~2013-04-03 17:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22 22:40 bug#13790: Cannot paste with C-y into Homebrew emacs v24.2.1 Andrew Pennebaker
2013-03-05 20:13 ` Glenn Morris
2013-03-05 21:46   ` Jan Djärv
2013-03-05 23:19     ` Josh
2013-03-06  9:34       ` Jan Djärv
2013-03-06 15:54         ` Josh
2013-03-06 18:54           ` Jan Djärv
2013-03-06 21:02             ` Eli Zaretskii
2013-03-06 21:49               ` Josh
2013-03-09  1:42                 ` Stefan Monnier
2013-03-13 16:18                   ` Josh
2013-03-13 18:04                     ` Stefan Monnier
2013-04-03 17:07                       ` Josh [this message]
2013-04-08 16:24                         ` Stefan Monnier
2013-04-13 16:55                           ` Josh
2024-01-10 11:22 ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANdFEAF9btn5TY3_BzYRoaF_RyAJ1HoHDHe97x4RO6_0cDhp6Q@mail.gmail.com \
    --to=josh@foxtail.org \
    --cc=13790@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).