From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: Set X primary selection with Emacs in xterm Date: Fri, 03 Jun 2022 13:33:54 +0800 Message-ID: <8735gm71kt.fsf@yahoo.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34000"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) Cc: emacs-devel@gnu.org To: Duncan Findlay Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 03 07:35:08 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nwzxk-0008eF-69 for ged-emacs-devel@m.gmane-mx.org; Fri, 03 Jun 2022 07:35:08 +0200 Original-Received: from localhost ([::1]:54448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwzxi-0002nI-K7 for ged-emacs-devel@m.gmane-mx.org; Fri, 03 Jun 2022 01:35:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwzwo-00025q-LA for emacs-devel@gnu.org; Fri, 03 Jun 2022 01:34:10 -0400 Original-Received: from sonic306-20.consmr.mail.ne1.yahoo.com ([66.163.189.82]:36327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwzwm-0006lz-DW for emacs-devel@gnu.org; Fri, 03 Jun 2022 01:34:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654234445; bh=cnNO2v0qqahfOD/v8olqzvYtSYtVTuyDzoYemu8OSYI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=LiC8UPWJOTGvHKkezyEz3dxff8jjKTvt+4X3Hdq6XTVDH0iS+ygWeD2+GwaB3e+LQbgzAzLjdbz9YYDmV7EF86a+kSYn1f2pwaTbSYrM9VxBLvw9ByPDv2c3US41HVm5kBJQYdUz3UpEpLHoL/Bt+9i1H9CzTfFEcgGAV1pXnHIQTNxAPNPcSiq/5RQQboGQcD6R9c6dgnd21V++eGZ2ppfdr7fSF5AwksslCnTkOxWkkKU8wYnq/3h64YWDXLEmBztqN06bRWY3lOFQKV203hDcAMpIyod6/tXbYXgwAgPXF9Tp2SaG0z03cyQi+BqsavLKsEMNmXcsnHh99KRnfA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654234445; bh=8dnknnMGm1GeLZZELlveixXfaHVdhPK1c+uAPL28L9g=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=B9qnAc/IIe/UXJuw2uhcT6ggj/Ro3LFTYpKsMn9sA3gU6h6C8v1VVK2Z3gg0nCDHQ6EZnZJALHOlRLAuTMTNKqXzOoDtlifncn7iShaLHcK27e0C+39r9Yk9xjESAdsVTpeJSjwuS7I1yJH6KHpgZsPYKn928s5m70YTdWnMJgsGZsem0dShMVxvakKmWky1MJbUt1CMYzUpIQZBC12LDOhWpR8pIDLuyGuqoW9W+3YcTjVj/VZLQg1QiUXoXspcQJg+Z6xVet0dd2zAc2Gt04MCx8JJC3jNKamXfS2+AGeDBqfXueai4F5QdvZVcjBOukpBcsa3svg2VXu7b5LNrw== X-YMail-OSG: FnyXMIUVM1mv2IvINiS9JrJeXpTKgEsBbkwx6urHXZy7Ljjdim_o.ofR_Bug4UR Nc5ej9dXD0v_2gv7Endc14khrn25MqlGB7o5QaljdvbgNWvPeVyCfYce3iwHXpkERCvXwiiLsUXR 95ZgAVLrqqeNuxfE94weFYmEFPL2613In7tXth61irvtj.89GxMSRa6ZF1oB3FPEhp2KG7QhFlRJ 0._Ng4ns5Ptg89tXc9kCD_NO5riSWFtbieNeSrmUEKZCfpYY9TanAOlI_KW5dIIw_fc0n4GiV9DS g6V.MkW3wpzw57sdoGxyM.heX3QAoKckCqO8YAXWEsSzUmOtmGL9pmDwDNXKMrVqdKRkMjwrnSFW uOXoBqqXvgmVc6Xm2QyZ1xweZEd83gcK8tAUbAbOrrNmstXKoToHq1xAmTvsWKMIXsDfyCx2_FJV xTa4UssPzh2GjXD_uXDyvtZOBXWVbK4tBEEP1314z22l_tIS3mB1b_7PedroBiq4kLg7zfeIKQwn 5hKM4lb3KSbNXsvyZ8uhoC4BD4fruksvTFLcFkKX2hll9Rgnb6_m.uztf9qjJBCpmlaCV7pNLzf6 CeL93m4G9buWmp2EY_piCQd4l2BPVQ9_OXENUFBGlJzTHEIk_JuwW59D4vsqHck.aZxkuvtzhv_J Mr_oa.U8mjzgwpoGMP0_JekVkoBAFGWbr22pVtjHLn7k48Vt12ddswr3vtG5DVtBaSClWQ95HizL LUEccHmjovTOKTH9K4f3DXifBCaPHZjMNZOok.l_buRkUZAJqCcTFZr8Z3OXUQgUUINap6o6Fn5w 2_WZ.ojpJX3tEYuLfniWTQoLDDTlCngST5IJXeaRfb X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Fri, 3 Jun 2022 05:34:05 +0000 Original-Received: by hermes--canary-production-sg3-5f7658c994-bv4wk (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 5a4425387ccf804a050a7a4d8e81bbb8; Fri, 03 Jun 2022 05:33:58 +0000 (UTC) In-Reply-To: (Duncan Findlay's message of "Thu, 2 Jun 2022 21:03:49 -0700") X-Mailer: WebService/1.1.20225 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.189.82; envelope-from=luangruo@yahoo.com; helo=sonic306-20.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:290593 Archived-At: (Patches should ideally be sent to bug-gnu-emacs@gnu.org, and not here.) Duncan Findlay writes: > I frequently use Emacs over ssh and I'd really like to get both > primary and clipboard selections to work as close as possible to > running Emacs on X natively. I'd like to kill text in Emacs and have > that show up in my system clipboard so I can paste into other > applications. Similarly, if I select text with mark and keyboard (or > mouse with xterm-mouse-mode), I'd like it to update my local X's > primary selection so I can middle-click to paste it elsewhere. I have > two patches attached that got this working for me. > > Without changes, with `(setq xterm-extra-capabilities > '(setSelection))', when I kill text, Emacs generates OSC 52 terminal > escape codes and xterm updates my clipboard. This works great! Emacs > also has support for updating the primary selection with this same > mechanism, e.g. `(gui-set-selection 'PRIMARY "primary")'. This, too, > works fine with xterm. > > The bit that's missing is that when I select text with keyboard or > mouse (with xterm-mouse-mode), the primary selection is not updated. > It appears that the primary selection is only updated when > `(window-system)' is not nil. > > I've attached a patch below to replace the `window-system' check with > `display-selections-p', as that's documented as the preferred way to > do this type of check. It also moves the check to lisp where we can > advise it. > > The second patch changes `(display-selections-p)' to return true > under xterm with the setSelection feature enabled. Thanks. That mostly looks good to me, some minor comments below: > * src/keyboard.c (command_loop_1): Replace call to `window-system' > with `display-selections-p' when deciding whether to update primary > selection. > * lisp/frame.el (display-selections-p): Return `t' when xterm's > setSelection mode is enabled. We don't indent each line of a ChangeLog entry to line up with the asterisk, so this should be written: * src/keyboard.c (command_loop_1): Replace call to `window-system' with `display-selections-p' when deciding whether to update primary selection. instead. Please also make sure that each line of the commit message takes no more than 64 columns on-screen. > lisp/frame.el | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/lisp/frame.el b/lisp/frame.el > index 27f99fb7d2..eb8ae1c27d 100644 > --- a/lisp/frame.el > +++ b/lisp/frame.el > @@ -2164,6 +2164,9 @@ display-selections-p > (not (null dos-windows-version)))) > ((memq frame-type '(x w32 ns pgtk)) > t) > + ((and (memq frame-type '(t)) This `memq' is redundant: why not (eq frame-type t) instead? > + (eq (terminal-parameter nil 'xterm--set-selection) t)) > + t) This doesn't look very clean... I wonder if there is a cleaner way to check for this support. Also, have you signed copyright papers? And if not, how many lines of code have you previously contributed to Emacs?