emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 2cb5ed66c0: Support `select-active-regions' with xterm


From: Eli Zaretskii
Subject: master 2cb5ed66c0: Support `select-active-regions' with xterm
Date: Sat, 18 Jun 2022 07:13:15 -0400 (EDT)

branch: master
commit 2cb5ed66c094cc1ea937c72eb7958c2dc674ac7f
Author: Duncan Findlay <duncf@google.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    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 761f236925..f195a721f4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -506,6 +506,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 @@ frame's display)."
 (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 @@ frame's display)."
        (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 @@ capabilities, and only when that terminal understands 
bracketed paste."
   :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 60ff8f5ea6..cd92cf8d4a 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");



reply via email to

[Prev in Thread] Current Thread [Next in Thread]