From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: yank-secondary Date: Tue, 6 May 2008 08:54:01 -0700 Message-ID: <000901c8af91$67d4d7e0$0200a8c0@us.oracle.com> References: <000b01c883aa$0177b340$0600a8c0@us.oracle.com> <000901c8ae3c$ae309770$0200a8c0@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1210089302 19665 80.91.229.12 (6 May 2008 15:55:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 6 May 2008 15:55:02 +0000 (UTC) Cc: 'Ehud Karni' , 'David De La Harpe Golden' To: "'Emacs-Devel'" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 06 17:55:35 2008 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 1JtPVt-0005sQ-BD for ged-emacs-devel@m.gmane.org; Tue, 06 May 2008 17:55:34 +0200 Original-Received: from localhost ([127.0.0.1]:36459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JtPVA-0000Ie-9W for ged-emacs-devel@m.gmane.org; Tue, 06 May 2008 11:54:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JtPV1-0000Fr-IB for emacs-devel@gnu.org; Tue, 06 May 2008 11:54:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JtPUx-0000DB-MN for emacs-devel@gnu.org; Tue, 06 May 2008 11:54:38 -0400 Original-Received: from [199.232.76.173] (port=52266 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JtPUx-0000Cv-4u for emacs-devel@gnu.org; Tue, 06 May 2008 11:54:35 -0400 Original-Received: from agminet01.oracle.com ([141.146.126.228]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JtPUw-0003TR-8t for emacs-devel@gnu.org; Tue, 06 May 2008 11:54:34 -0400 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by agminet01.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id m46FsFBG011934; Tue, 6 May 2008 10:54:16 -0500 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id m4679XtE026013; Tue, 6 May 2008 09:54:15 -0600 Original-Received: from inet-141-146-46-1.oracle.com by acsmt351.oracle.com with ESMTP id 3666935641210089234; Tue, 06 May 2008 08:53:54 -0700 Original-Received: from dradamslap1 (/141.144.72.200) by bhmail.oracle.com (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 May 2008 08:53:53 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <000901c8ae3c$ae309770$0200a8c0@us.oracle.com> Thread-Index: AchjiN79QbAYQ+j/ROKKRXQlsKbyaAH6E8ugBg4v7iAKmcQIgABfxqlQ X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:96591 Archived-At: Dunno if anyone tried the code I sent, but I've since combined the three commands in one, `yank-secondary-or-swap-w-region': * no prefix arg: yank-secondary * prefix arg >= 0: primary-to-secondary * prefix arg < 0: secondary-to-primary I also fixed a minor bug in `primary-to-secondary'. The code is here, for those who are interested: http://www.emacswiki.org/cgi-bin/wiki/misc-cmds.el -------- > From: Drew Adams Sent: Sunday, May 04, 2008 4:15 PM > Resending (see below). There was some interest, but not a > deluge of response. This is an update, with some new commands. > > David D.L.H.G mentioned that there is no way to create the > secondary selection by keyboard, and that he typically is > already using the mouse when he wants to yank the secondary > selection. > > That's not my experience. I often yank the secondary > selection long after I've created it. In fact, I typically > use the same secondary selection over a period > of editing, whereas I change the primary (region) selection > often. That's the beauty of the secondary selection, to me: > it persists even when the region changes. You can use > registers in a similar way, but I find the secondary > selection handy for this. > > But what about having a way to create the secondary > selection by keyboard? Good idea. I don't think it's > helpful or necessary to duplicate the many ways that > one can define the region, just to do the same for the > secondary selection. You don't need 36 ways to define that. > > But it would be useful to be able to create the secondary > selection from the region. That then gives you all of the > many region creation methods for free. > > I now bind not `yank-secondary' (which I sent previously) > but a command that does the same thing but also lets you > use `C-u' to instead create the secondary selection from > the region. I bind it to `C-M-y'. > > (defun yank-secondary-or-convert-primary (arg) > "Insert the secondary selection at point. > Move point to the end of the inserted text. Does not change mark. > With a prefix arg, make the region into the secondary selection, > instead." > (interactive "P") > (if arg > (call-interactively #'primary-to-secondary) > (setq this-command 'yank-secondary) > (when delete-selection-mode ; Hack! > (delete-selection-pre-hook)) > (call-interactively #'yank-secondary))) > > (defun primary-to-secondary (beg end) > "Make the region in the current buffer into the secondary > selection." > (interactive "r") > (setq mouse-secondary-start (make-marker)) > (set-marker mouse-secondary-start beg) > (if mouse-secondary-overlay > (move-overlay mouse-secondary-overlay beg end) > (setq mouse-secondary-overlay (make-overlay beg end)) > (overlay-put mouse-secondary-overlay > 'face 'secondary-selection)) > (x-set-selection 'SECONDARY (buffer-substring beg end))) > > IOW, I use `C-M-y' to yank the secondary and `C-u C-M-y' to > copy the region text to the secondary (it still leaves the > region active). That's the right way to > create the secondary from the keyboard, I think. > > There was also some question of how yanking should interact with > delete-selection mode. I now let it delete the region text, > and I find that that is quite useful. IOW, `C-M-y' with an > active region replaces the region text > with the secondary selection. > > Among other things, that provides a handy way to replace text > here and there, without monkeying with the kill-ring order > (`M-y'). I also use it sometimes with isearch the same way, > as a way to replace particular search hits on the fly. > (`C-SPC' in my version of isearch-map is a toggle that sets > the region around the search hit when you exit isearch, which > is handy here.) > > The hack in the `yank-secondary-or-convert-primary' code > shows how I make delete-selection mode DTRT. I didn't find a > better way, since delete-selection mode looks only at the > current key's command. Suggestions welcome. > > FWIW, I also have a command, `secondary-to-primary', to pop > to the buffer of the secondary selection and select it as > the region. It's sort of the opposite of > `primary-to-secondary'. I have not bound it to a key. > > (defun secondary-to-primary () > "Converts the secondary selection into the active region. > Selects the secondary selection and its buffer in another window." > (interactive) > (let ((secondary (x-get-selection 'SECONDARY))) > (unless (and secondary mouse-secondary-overlay) > (error "No secondary selection")) > (x-set-selection 'PRIMARY secondary)) > (switch-to-buffer-other-window > (overlay-buffer mouse-secondary-overlay)) > (push-mark (overlay-start mouse-secondary-overlay) t t) > (goto-char (overlay-end mouse-secondary-overlay)) > (setq deactivate-mark nil)) > > You might give `yank-secondary-or-convert-primary' a try, to > see if it's something that Emacs might benefit from. > > Here again is `yank-secondary' (used by > `yank-secondary-or-convert-primary'): > > (defun yank-secondary () > "Insert the secondary selection at point. > Moves point to the end of the inserted text. Does not change mark." > (interactive) > (let ((secondary (x-get-selection 'SECONDARY))) > (unless secondary (error "No secondary selection")) > (insert secondary))) > > -------------8<-------------------- > > From: Drew Adams Sent: Tuesday, March 11, 2008 11:59 AM > > Resending. Questions: > > > > 1) Any interest? > > 2) Do you yank the secondary selection (without the mouse)? > > If so, how? > > > > ------------- > > Sent: Wednesday, January 30, 2008 1:41 PM > > Any interest in adding something like this? I've used it for > > years. Hard to > > believe it isn't already in Emacs (or is it?). (What do those > > of you who are sans souris use?) > > > > (defun yank-secondary () > > "Insert the secondary selection at point. > > Moves point to the end of the inserted text. Does not change mark." > > (interactive) > > (let ((secondary (x-get-selection 'SECONDARY))) > > (unless secondary (error "No secondary selection")) > > (insert secondary))) > > > > I bind it to `C-M-y', so I can access two different > > selections from the keyboard. > > > > (FWIW, I also bind the meta mouse stuff to `C-M-', so > > mouse-yank-secondary and yank-secondary use the same > > modifiers. I've done that since I had an SGI workstation > > that wouldn't pass ALT-mouse stuff to Emacs. So, e.g., I > > have `C-M-y' = yank-secondary, `C-M-mouse2' = > > mouse-yank-secondary, `C-M-mouse-1' > > = mouse-start-secondary, `C-M-mouse-3' = > > mouse-secondary-save-then-kill, > > `C-M-drag-mouse-1' = mouse-set-secondary, and > > `C-M-down-mouse-1' = mouse-drag-secondary.)