all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Duncan Findlay via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 55883@debbugs.gnu.org
Subject: bug#55883: [PATCH] Update X Primary Selection with active regions
Date: Tue, 14 Jun 2022 19:01:58 -0700	[thread overview]
Message-ID: <CAPANw+PyG2OD_Vw0dLO3T7qX1T3EEN8-B2cTSEguo9e_Z880=w@mail.gmail.com> (raw)
In-Reply-To: <837d5jtp9x.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2043 bytes --]

On Tue, Jun 14, 2022 at 5:15 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Duncan Findlay <duncf@google.com>
> > Date: Mon, 13 Jun 2022 23:36:13 -0700
> > Cc: 55883@debbugs.gnu.org
> >
> > > > --- a/lisp/frame.el
> > > > +++ b/lisp/frame.el
> > > > @@ -2164,6 +2164,8 @@ display-selections-p
> > > >         (not (null dos-windows-version))))
> > > >       ((memq frame-type '(x w32 ns pgtk))
> > > >        t)
> > > > +     ((terminal-parameter display 'display-selections-p)
> > > > +      t)
> > >
> > > This should test xterm--set-selection parameter.
> >
> > OK, so the goal is to check the xterm--set-selection terminal
> > parameter and variable xterm-select-active-regions before selecting
> > the active region in deactivate-mark in simple.el.
> >
> > We could do this in display-selections-p, but given that these
> > variables are not obviously related to display-selections-p, it seems
> > to me we probably want to do this check in deactivate-mark instead.
> > Does that seem reasonable to you?
>
> I think I'd prefer to have it in display-selections-p, like your last
> version did, just using xterm--set-selection terminal parameter, not
> the new one you invented.

Updated.

> > > I think the code should instead check the value of
> > > xterm-select-active-regions in keyboard.c, where it decides whether to
> > > set PRIMARY.  (Let me know if you need guidance for how to reference a
> > > Lisp variable from C.)
> >
> > This seems to work -- is there a better way?
> >
> > !NILP (SYMBOL_VAL (XSYMBOL (Qxterm_select_active_regions)))
>
> This is not safe, IMO.  I think this is better:
>
>   if ((!NILP (Fwindow_system (Qnil))
>        || ((symval = find_symbol_value (Qxterm_select_active_regions),
>             (!EQ (symval, Qunbound) && !NILP (symval)))
>             && !NILP (Fterminal_parameter (Qnil, Qxterm__set_selection))))

Thanks, I would never have figured that out myself.

> > I've also addressed Po's comments about long conditionals.
>
> Thanks, the patch LGTM, modulo the above 2 minor nits.

Duncan

[-- Attachment #2: 0001-Support-select-active-regions-with-xterm.patch --]
[-- Type: text/x-patch, Size: 4229 bytes --]

From 99337d15f3e0aecd57dd238c9616df83d1ae82a6 Mon Sep 17 00:00:00 2001
From: Duncan Findlay <duncf@google.com>
Date: Fri, 10 Jun 2022 18:46:49 -0700
Subject: [PATCH] Support `select-active-regions' with xterm

This allows Emacs to save the active region to the user's
primary selection on supported terminals.  The behavior follows
the existing `select-active-regions' variable and requires
`xterm-select-active-regions' to be non-nil.

* src/keyboard.c (command_loop_1):
* lisp/frame.el (display-selections-p): On text terminals, check
terminal parameter `xterm--set-selections' and variable
`xterm-select-active-regions' when deciding whether to update
primary selection. (bug#55883)
* lisp/term/xterm.el (xterm-select-active-regions): New
defcustom.
---
 etc/NEWS           |  6 ++++++
 lisp/frame.el      |  6 ++++++
 lisp/term/xterm.el |  8 ++++++++
 src/keyboard.c     | 10 +++++++++-
 4 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 19ca21f666..ea501b7c69 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -502,6 +502,12 @@ This is in addition to previously-supported ways of discovering 24-bit
 color support: either via the "RGB" or "setf24" capabilities, or if
 the 'COLORTERM' environment variable is set to the value "truecolor".
 
+*** Select active regions with xterm selection support.
+On terminals with xterm setSelection support, the active region may be
+saved to the X primary selection, following the
+'select-active-regions' variable.  This support is enabled with
+'xterm-select-active-regions'.
+
 ** ERT
 
 +++
diff --git a/lisp/frame.el b/lisp/frame.el
index 27f99fb7d2..35863c0135 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -2149,6 +2149,9 @@ 'display-blink-cursor-p
 (defalias 'display-multi-frame-p #'display-graphic-p)
 (defalias 'display-multi-font-p #'display-graphic-p)
 
+;; From term/xterm.el
+(defvar xterm-select-active-regions)
+
 (defun display-selections-p (&optional display)
   "Return non-nil if DISPLAY supports selections.
 A selection is a way to transfer text or other data between programs
@@ -2164,6 +2167,9 @@ display-selections-p
        (not (null dos-windows-version))))
      ((memq frame-type '(x w32 ns pgtk))
       t)
+     ((and xterm-select-active-regions
+           (terminal-parameter nil 'xterm--set-selection))
+      t)
      (t
       nil))))
 
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index a7e257f41c..0791780d40 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -80,6 +80,14 @@ xterm-store-paste-on-kill-ring
   :version "28.1"
   :type 'boolean)
 
+(defcustom xterm-select-active-regions nil
+  "If non-nil, update PRIMARY X selection on text-mode frames.
+On a text-mode terminal that supports setSelection command, if
+this variable is non-nil, Emacs will set the PRIMARY selection
+from the active region, according to `select-active-regions'."
+  :version "29.1"
+  :type 'boolean)
+
 (defconst xterm-paste-ending-sequence "\e[201~"
   "Characters sent by the terminal to end a bracketed paste.")
 
diff --git a/src/keyboard.c b/src/keyboard.c
index 55d710ed62..9b34a47675 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1567,9 +1567,15 @@ command_loop_1 (void)
 	    call0 (Qdeactivate_mark);
 	  else
 	    {
+	      Lisp_Object symval;
 	      /* Even if not deactivating the mark, set PRIMARY if
 		 `select-active-regions' is non-nil.  */
-	      if (!NILP (Fwindow_system (Qnil))
+	      if ((!NILP (Fwindow_system (Qnil))
+		   || ((symval =
+			find_symbol_value (Qxterm_select_active_regions),
+			(!EQ (symval, Qunbound) && !NILP (symval)))
+		       && !NILP (Fterminal_parameter (Qnil,
+						      Qxterm__set_selection))))
 		  /* Even if mark_active is non-nil, the actual buffer
 		     marker may not have been set yet (Bug#7044).  */
 		  && XMARKER (BVAR (current_buffer, mark))->buffer
@@ -12163,6 +12169,8 @@ syms_of_keyboard (void)
   DEFSYM (Qpolling_period, "polling-period");
 
   DEFSYM (Qgui_set_selection, "gui-set-selection");
+  DEFSYM (Qxterm__set_selection, "xterm--set-selection");
+  DEFSYM (Qxterm_select_active_regions, "xterm-select-active-regions");
 
   /* The primary selection.  */
   DEFSYM (QPRIMARY, "PRIMARY");
-- 
2.36.1.476.g0c4daa206d-goog


  reply	other threads:[~2022-06-15  2:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10  6:18 bug#55883: [PATCH] Update X Primary Selection with active regions Duncan Findlay via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-10  6:52 ` Eli Zaretskii
2022-06-11  1:59   ` Duncan Findlay via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-11  7:53     ` Eli Zaretskii
2022-06-14  5:57       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-14  6:36       ` Duncan Findlay via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-14 12:15         ` Eli Zaretskii
2022-06-15  2:01           ` Duncan Findlay via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-06-15 16:51             ` Eli Zaretskii
2022-06-18 11:13               ` Eli Zaretskii
2022-06-18 15:15                 ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-18 16:09                   ` Eli Zaretskii
2022-06-22  1:58                     ` Duncan Findlay via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-22 13:02                       ` Eli Zaretskii
2022-06-22 15:37                       ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPANw+PyG2OD_Vw0dLO3T7qX1T3EEN8-B2cTSEguo9e_Z880=w@mail.gmail.com' \
    --to=bug-gnu-emacs@gnu.org \
    --cc=55883@debbugs.gnu.org \
    --cc=duncf@google.com \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.