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: Saving the selection before killing (was: Selection not to be copied into kill-ring) Date: Thu, 12 Jul 2007 16:31:26 -0400 Message-ID: References: <5fmk5pF3bo3fbU1@mid.individual.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1184272295 2497 80.91.229.12 (12 Jul 2007 20:31:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 12 Jul 2007 20:31:35 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 12 22:31:34 2007 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 1I95K0-0001RP-S7 for ged-emacs-devel@m.gmane.org; Thu, 12 Jul 2007 22:31:33 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I95K0-0003HD-Dy for ged-emacs-devel@m.gmane.org; Thu, 12 Jul 2007 16:31:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I95Jx-0003Gy-9g for emacs-devel@gnu.org; Thu, 12 Jul 2007 16:31:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I95Jw-0003Gl-N5 for emacs-devel@gnu.org; Thu, 12 Jul 2007 16:31:29 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I95Jw-0003GV-J5 for emacs-devel@gnu.org; Thu, 12 Jul 2007 16:31:28 -0400 Original-Received: from tomts16.bellnexxia.net ([209.226.175.4] helo=tomts16-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I95Jw-00025B-3v for emacs-devel@gnu.org; Thu, 12 Jul 2007 16:31:28 -0400 Original-Received: from pastel.home ([74.12.207.21]) by tomts16-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20070712203126.YARF1673.tomts16-srv.bellnexxia.net@pastel.home> for ; Thu, 12 Jul 2007 16:31:26 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 85DB37FF9; Thu, 12 Jul 2007 16:31:26 -0400 (EDT) Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:6ChQXZQ9WDUkIivStFSDSdRghOI= In-Reply-To: (Eli Zaretskii's message of "Thu\, 12 Jul 2007 08\:53\:02 -0400") Posted-To: gnu.emacs.help X-detected-kernel: Solaris 8 (1) 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:74694 Archived-At: The following message is a courtesy copy of an article that has been posted to gnu.emacs.help as well. >>>>> "Eli" == Eli Zaretskii writes: >> From: Will >> Newsgroups: gnu.emacs.help >> Date: Thu, 12 Jul 2007 14:14:01 +0200 >> >> I'd like to copy text from external applications (e.g. web browser) to >> an Emacs buffer. Often before I paste the text into an Emacs buffer I'd >> like to delete text in the this buffer _without_ it being copied to the >> kill-ring, because then the text from the external application gets lost. >> >> => How do I switch off that hightlighted text is copied automatially >> into the kill-ring? >> => How do I delete a region without it getting copied into the >> kill-ring, e.g. by highlighting the text and pressing ? > Try "M-x delete-selection-mode RET". Is this what you want? I bump into the OP's problem every once in a while, but I don't like delete-selection-mode for some reason, so I use the patch below instead. What it does is that when you kill text, before doing the kill (which will replace the current X-selection with the killed text), we save the current selection on the kill-ring (only if it doesn't come from us, of course since otherwise it's already in the kill-ring). So I can simply do my kill and then C-y (which re-inserts what I just killed) and M-y (which replaces the text with the previous X-selection). This feature is pretty unnoticeable, so I'm tempted to install it just like that, but maybe people want yet-another-config-var to control it? Stefan --- orig/lisp/simple.el +++ mod/lisp/simple.el @@ -2479,6 +2536,20 @@ 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. (if (> (length string) 0) (if yank-handler (put-text-property 0 (length string)