From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Duncan Findlay Newsgroups: gmane.emacs.devel Subject: Re: Set X primary selection with Emacs in xterm Date: Thu, 9 Jun 2022 23:36:50 -0700 Message-ID: References: <8735gm71kt.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34412"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 10 08:55:46 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 1nzYYb-0008gZ-ES for ged-emacs-devel@m.gmane-mx.org; Fri, 10 Jun 2022 08:55:45 +0200 Original-Received: from localhost ([::1]:43298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzYYX-0004os-P9 for ged-emacs-devel@m.gmane-mx.org; Fri, 10 Jun 2022 02:55:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzYH2-0003sG-JB for emacs-devel@gnu.org; Fri, 10 Jun 2022 02:37:36 -0400 Original-Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:37826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzYH0-0002UB-Lt for emacs-devel@gnu.org; Fri, 10 Jun 2022 02:37:36 -0400 Original-Received: by mail-wr1-x430.google.com with SMTP id o16so1449964wra.4 for ; Thu, 09 Jun 2022 23:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WYuSDcQfPX+pM+U//WfRhcQc422w/L1gOvZSjiUopa4=; b=F+F0gCscMl2t+QEo23smcAloxoH+BraXfTH0NHTfpwEe/MRr7mX2uq8YASlPnsA1k2 8vwYNEZvoa7rH0I7SRGpld2Av++VJZtEQ69YOo34KY/zy9xkaYbRyNedOn7yQ7YM0khU ZToMwD9+dVrKUpYmXSi5c2uFrpGefZCn7tLJ6il4Pw9MObsht8FmMBHAkFaZM3Oralyj cPE3eaD9GJsyuvj5Q00KLiW1H8smpkBHsWggaA+VKztYBo1XZvPRnVPwxqO3Uy6tDwGS bV07ja2z2Rk1PqXalZ0lu83FBw4Sg1yPhNfmLIZpdk00dXkyOaARARO3VKh2SjMKNHgs HXtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WYuSDcQfPX+pM+U//WfRhcQc422w/L1gOvZSjiUopa4=; b=KlCEdY5bSdZEjKr+hvvS80EEtGi0aBcde6HPpDdPSVNdC/anRF9pbpMpfVahLxCHat YJBQn6rFjDWi3Iz6uDDKNG+Gv+k+Ll6Bamid0SRRoBzmjXdyvs/3f0eEEj5vUkI9fgAL 8eTSi6bukVczHoMVP3tNIeChA4v/nZZEhUvLmA1L1eOeLIaDIefvER3xSFtYreN9f86U UkXywTlabBup/gmArSgydx68UG1Beyqfbsf9Tey+06klIlVS7avz5ttpLKp0+PxSYwfH U65uLr6RoRWrtrxz4cq+72FqMhqoot8/X06XfXTolcQpeSyzDAVZfJOMfokUze0K1hdZ 9SsA== X-Gm-Message-State: AOAM531OREyWDZG9qIOTd+332hCnacuGXoDUGilXw5ZXBaQDiiNop0Hc hlWgb/1BmVKSMurZDFstMkJZG9DdJp7kEsMqsmX0ug== X-Google-Smtp-Source: ABdhPJyM9Q8gX4AU9DxwjhW8BdwGERhcdOnwQ/yGUHgKCkiIZmnQ+RrCQdm0YHTA2kMqwg0FZ2vS2kVkEEJPFENlSWY= X-Received: by 2002:a05:6000:91:b0:217:8efc:f572 with SMTP id m17-20020a056000009100b002178efcf572mr28171529wrx.186.1654843051554; Thu, 09 Jun 2022 23:37:31 -0700 (PDT) In-Reply-To: <8735gm71kt.fsf@yahoo.com> Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=duncf@google.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -175 X-Spam_score: -17.6 X-Spam_bar: ----------------- X-Spam_report: (-17.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 10 Jun 2022 02:42:05 -0400 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:290990 Archived-At: Thanks for the feedback! On Thu, Jun 2, 2022 at 10:34 PM Po Lu wrote: > > (Patches should ideally be sent to bug-gnu-emacs@gnu.org, and not > here.) I've sent a new version to the bug tracker: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55883 > 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. I'd missed reading CONTRIBUTE, where this is all documented. Thank you. > > > 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? Oops, thank you. (I'm very new to lisp and mostly pattern matching.) > > > + (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. I figured folks would probably object to that. Based on the responses here, and given that this is only needed for text-based terminals, I think using a generically-named terminal parameter that can be set by any other library makes the most sense. > Also, have you signed copyright papers? And if not, how many lines of > code have you previously contributed to Emacs? This should be covered by my employer's copyright paperwork on file. Thanks Duncan