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 19:40:17 -0700 Message-ID: <005501c8afeb$afe7ab70$0200a8c0@us.oracle.com> References: <000b01c883aa$0177b340$0600a8c0@us.oracle.com><000901c8ae3c$ae309770$0200a8c0@us.oracle.com><000901c8af91$67d4d7e0$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 1210128056 8393 80.91.229.12 (7 May 2008 02:40:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 7 May 2008 02:40:56 +0000 (UTC) Cc: 'Ehud Karni' , 'David De La Harpe Golden' , 'Emacs-Devel' To: "'Stefan Monnier'" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 07 04:41:30 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 1JtZaz-0004gA-UC for ged-emacs-devel@m.gmane.org; Wed, 07 May 2008 04:41:30 +0200 Original-Received: from localhost ([127.0.0.1]:59477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JtZaH-0005cb-UW for ged-emacs-devel@m.gmane.org; Tue, 06 May 2008 22:40:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JtZa2-0005Su-Om for emacs-devel@gnu.org; Tue, 06 May 2008 22:40:30 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JtZa2-0005SU-Aw for emacs-devel@gnu.org; Tue, 06 May 2008 22:40:30 -0400 Original-Received: from [199.232.76.173] (port=37992 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JtZa1-0005SJ-S2 for emacs-devel@gnu.org; Tue, 06 May 2008 22:40:29 -0400 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JtZa1-0001lj-Gt for emacs-devel@gnu.org; Tue, 06 May 2008 22:40:29 -0400 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id m472ePOQ009309; Tue, 6 May 2008 20:40:25 -0600 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id m46Jat9J032583; Tue, 6 May 2008 20:40:24 -0600 Original-Received: from inet-141-146-46-1.oracle.com by acsmt351.oracle.com with ESMTP id 3667108071210128001; Tue, 06 May 2008 19:40:01 -0700 Original-Received: from dradamslap1 (/141.144.72.200) by bhmail.oracle.com (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 May 2008 19:40:01 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: Aciv5isSZMZomN0oRl+Sf81j/B9G2gAAfubQ 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:96640 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 > > Why not just either yank and swap primary<->secondary? > Also it can just be called secondary-dwim. I don't know what you're suggesting. I don't know what you mean here by "either...and" and by "swap primary<->secondary". Here is the code I have, so you can see more clearly what I meant. Let me know more precisely what you have in mind. I have no problem with renaming commands or other changes. Note that `primary-to-secondary' and `secondary-to-primary' are not exact opposites. The first puts the secondary selection (also) on the (current buffer's) region text. The second pops to the buffer that has the secondary selection and selects that text as the active region. The first is more useful than the second. In particular, it indirectly gives you different ways to create the secondary selection using the keyboard. For example, you can use `C-M-@' to mark a sexp and then `C-u C-M-y' to select it as the secondary (assuming that `C-M-y' is bound to `yank-secondary-or-swap-w-region '). Yanking the secondary is the most useful of the three, which is why it needs no prefix arg. It is particularly useful with delete-selection mode, although I just started using it that way recently. (defun yank-secondary-or-swap-w-region (arg) ; I bind it to `C-M-y' "Insert the secondary selection at point. Prefix arg: swap with region. Move point to the end of the inserted text. Leave mark where it was. With a prefix arg, swap the region and secondary selections instead, in this way: Arg >= 0: Make the region into the secondary selection. Arg < 0: Convert the secondary selection into the region." (interactive "P") (cond (arg (setq arg (prefix-numeric-value arg)) (if (wholenump arg) (call-interactively #'primary-to-secondary) (call-interactively #'secondary-to-primary))) (t (setq this-command 'yank-secondary) (when delete-selection-mode (delete-selection-pre-hook)) ; Hack! (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 (current-buffer)) (setq mouse-secondary-overlay (make-overlay beg end (current-buffer))) (overlay-put mouse-secondary-overlay 'face 'secondary-selection)) (x-set-selection 'SECONDARY (buffer-substring beg end))) (defun secondary-to-primary () "Convert the secondary selection into the active region. Select the secondary selection and pop to its buffer." (interactive) (let ((secondary (x-get-selection 'SECONDARY))) (unless (and secondary mouse-secondary-overlay) (error "No secondary selection")) (x-set-selection 'PRIMARY secondary)) (pop-to-buffer (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)) (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))) ;; Tell `delete-selection-mode' to replace active region ;; by yanked secondary selection. (put 'yank-secondary 'delete-selection 'yank) ---------------- FWIW, this is the code I'm using for the Edit menu. As mentioned in thread "x-selection-exists-p vs x-get-selection", I use `x-get-selection' instead of `x-selection-exists-p' for the `SECONDARY' because the latter doesn't seem to work, at least on Windows. I think that is a bug, but I never got a clear confirmation. I use `x-selection-enable-clipboard' also. (when (fboundp 'yank-secondary) (define-key-after menu-bar-edit-menu [yank-secondary] '(menu-item "Paste Secondary" yank-secondary :help "Paste secondary selection." :enable (and (fboundp 'x-get-selection) (x-get-selection 'SECONDARY) (not buffer-read-only)) :keys "\\[yank-secondary-or-swap-w-region]") 'paste) (define-key-after menu-bar-edit-menu [primary-to-secondary] '(menu-item "Region to Secondary" primary-to-secondary :help "Make the region into the secondary selection." :enable mark-active :keys "C-1 \\[yank-secondary-or-swap-w-region]") 'yank-secondary) (define-key-after menu-bar-edit-menu [secondary-to-primary] '(menu-item "Secondary to Region" secondary-to-primary :help "Convert the secondary selection into the active region." :enable (and (fboundp 'x-get-selection) (x-get-selection 'SECONDARY)) :keys "C-- 1 \\[yank-secondary-or-swap-w-region]") 'primary-to-secondary))