unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Sam Steingold <sds@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: kill-new discards current X selection
Date: Wed, 26 Aug 2009 15:28:04 -0400	[thread overview]
Message-ID: <jwv8wh67548.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <4A95606A.6050606@gnu.org> (Sam Steingold's message of "Wed, 26 Aug 2009 12:18:50 -0400")

> When I select a word in an xterm and then kill in emacs, then X selection is
> gone forever, replaced with the emacs kill.
> The appended patch prepends the current X selection to kill-ring before
> replacing the X selection with the current Emacs kill.
> Is it OK to install it unconditionally, or is it better to guard it
> with a user option, e.g., save-interprogram-paste-before-kill?

It needs to be guarded, because it can cause a delay in C-k (when the
previous selection owner is non-responsive) and some people find it
unacceptable.  At least that's my recollection of the consensus last
time I suggested it.

BTW, here's the version I use in my own local collection of hacks.


        Stefan


=== modified file 'lisp/simple.el'
--- lisp/simple.el	2009-08-19 08:31:59 +0000
+++ lisp/simple.el	2009-08-21 14:24:38 +0000
@@ -2799,6 +2851,21 @@
 argument is not used by `insert-for-yank'.  However, since Lisp code
 may access and use elements from the kill ring directly, the STRING
 argument should still be a \"useful\" string for such uses."
+  ;; To better pretend that X-selection = head-of-kill-ring, we copy other
+  ;; application's X-selection to the kill-ring.  This comes in handy when
+  ;; you do something like:
+  ;; - copy a piece of text in your web-browser.
+  ;; - have to do some editing (including killing) before you can yank
+  ;;   that text.
+  ;; Note: this piece of code inspired from current-kill.
+  (let ((paste (and interprogram-paste-function
+                    (funcall interprogram-paste-function))))
+    (when paste
+      (let ((interprogram-cut-function nil)
+            (interprogram-paste-function nil))
+        (kill-new paste))))
+  ;; The actual kill-new functionality.
+  (when (equal string (car kill-ring)) (setq replace t))
   (if (> (length string) 0)
       (if yank-handler
 	  (put-text-property 0 (length string)




  parent reply	other threads:[~2009-08-26 19:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26 16:18 kill-new discards current X selection Sam Steingold
2009-08-26 18:41 ` Jan D.
2009-08-26 19:28 ` Stefan Monnier [this message]
2009-08-26 20:39   ` Sam Steingold
2009-08-27  3:03     ` Stefan Monnier
2009-08-26 19:36 ` David De La Harpe Golden

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=jwv8wh67548.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=sds@gnu.org \
    /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).