From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: kill-new discards current X selection Date: Wed, 26 Aug 2009 15:28:04 -0400 Message-ID: References: <4A95606A.6050606@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1251316574 18620 80.91.229.12 (26 Aug 2009 19:56:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Aug 2009 19:56:14 +0000 (UTC) Cc: emacs-devel@gnu.org To: Sam Steingold Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 26 21:56:07 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MgObC-0003AD-5J for ged-emacs-devel@m.gmane.org; Wed, 26 Aug 2009 21:56:02 +0200 Original-Received: from localhost ([127.0.0.1]:45805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgObB-0002Yc-Oa for ged-emacs-devel@m.gmane.org; Wed, 26 Aug 2009 15:56:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MgOAI-0003D7-Pw for emacs-devel@gnu.org; Wed, 26 Aug 2009 15:28:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MgOAD-00034y-NM for emacs-devel@gnu.org; Wed, 26 Aug 2009 15:28:14 -0400 Original-Received: from [199.232.76.173] (port=49926 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgOAD-00034d-IG for emacs-devel@gnu.org; Wed, 26 Aug 2009 15:28:09 -0400 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:20044 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MgOA9-000051-Gg; Wed, 26 Aug 2009 15:28:05 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Au4EAG0plUpFpYuS/2dsb2JhbACBU9ddhBoFh2M X-IronPort-AV: E=Sophos;i="4.44,281,1249272000"; d="scan'208";a="44250021" Original-Received: from 69-165-139-146.dsl.teksavvy.com (HELO ceviche.home) ([69.165.139.146]) by ironport2-out.teksavvy.com with ESMTP; 26 Aug 2009 15:27:11 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 62666B40F3; Wed, 26 Aug 2009 15:28:04 -0400 (EDT) In-Reply-To: <4A95606A.6050606@gnu.org> (Sam Steingold's message of "Wed, 26 Aug 2009 12:18:50 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114631 Archived-At: > 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)