unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David De La Harpe Golden <david@harpegolden.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: select-active-regions
Date: Sat, 18 Jul 2009 19:45:54 +0100	[thread overview]
Message-ID: <4A621862.3010408@harpegolden.net> (raw)
In-Reply-To: <83skgup04t.fsf@gnu.org>

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

Eli Zaretskii wrote:

>> (x-set-selection 'PRIMARY value)
>> ;should just stash value somewhere
> 
> What would be the purpose of stashing the value ``somewhere''? 

The purpose is to emulate internally to emacs a primary selection 
facility otherwise missing from the platform in question. w32 emacs 
looks to have been treating the primary selection that way for the past 
13 years or so.
http://cvs.savannah.gnu.org/viewvc/emacs/lisp/w32-fns.el?revision=1.14&root=emacs&view=markup

On recent w32 it might now be possible to use an accessibility API (at 
least with sufficient privileges) to record  selections in some other 
applications, which might allow a closer to complete emulation of at 
least incoming primary, though it might be tricksy to actually implement 
and not especially worth it.

> The
> NEWS entry says:
> 
>     *** If `select-active-regions' is t, setting the mark automatically
>     makes the new region into the primary selection (for interaction with
>     other window applications).
>

Uh-huh. Note how it also says "makes the new region into the primary 
selection"  ?

> How can Emacs interact with other applications, if we just stash the
> value in some internal variable?
> 

Not all platforms have a primary selection as an OS-level entity in the 
first place, they only have a clipboard (well, the amiga actually had 
hundreds of distinct clipboards, but I'm not sure amiga support is worth 
worrying about even though AROS now exists), so emacs just has to 
interact with them via means other than a primary selection.  But mixing 
up primary and clipboard within 
x-set-selection/x-get-selection/x-selection-owner-p is wrong not
to mention phenomenally confusing.

Waht's more, I suspect it also Just Won't Work Anyway, because on w32 
AFAIK you set the system clipboard, on x11 you acquire the clipboard 
selection and applications ask you for the clipboard contents.  Perhaps 
just regard select-active-regions as a feature aimed mostly at X11 users...

If you do want select-active-regions to be able to affect the clipboard, 
a relatively sane way to do it would be to introduce customization 
variables:

x-select-active-regions-enable-clipboard 
x-select-active-regions-enable-primary

by analogy with x-select-enable-primary and x-select-enable-clipboard,
that would allow customization of which selections to actually affect 
during select-active-regions.   Note that x-select-enable-primary and 
x-select-enable-clipboard would be completely UNsuitable for reuse 
there, if you don't see why you probably haven't quite understood the issue.

See attached (illstrative) patch.





[-- Attachment #2: select-active-regions_allowclip_r1.diff --]
[-- Type: text/x-patch, Size: 5511 bytes --]

Index: lisp/simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.995
diff -U 8 -r1.995 simple.el
--- lisp/simple.el	18 Jul 2009 04:37:56 -0000	1.995
+++ lisp/simple.el	18 Jul 2009 18:43:58 -0000
@@ -3468,35 +3468,55 @@
 
 If you are using this in an editing command, you are most likely making
 a mistake; see the documentation of `set-mark'."
   (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
       (marker-position (mark-marker))
     (signal 'mark-inactive nil)))
 
 (defcustom select-active-regions nil
-  "If non-nil, an active region automatically becomes the window selection."
+  "If non-nil, an active region automatically becomes the window selection.
+Which selections are actually affected is determined by the
+`x-select-active-regions-enable-primary' and
+`x-select-active-regions-enable-clipboard' variables -
+if unbound or nil, that selection will be unaffected.
+may be poorly supported on windowing systems other than X11
+due to basic windowing system architectural differences."
   :type 'boolean
   :group 'killing
   :version "23.1")
 
+(defsubst select-active-regions--start ()
+  (and (bound-and-true-p x-select-active-regions-enable-primary)
+       (x-set-selection 'PRIMARY (current-buffer)))
+  (and (bound-and-true-p x-select-active-regions-enable-clipboard)
+       (x-set-selection 'CLIPBOARD (current-buffer))))
+
+(defsubst select-active-regions--end ()
+  (and (bound-and-true-p x-select-active-regions-enable-primary)
+       (x-selection-owner-p 'PRIMARY)
+       (x-set-selection 'PRIMARY (buffer-substring-no-properties
+				  (region-beginning) (region-end))))
+  (and (bound-and-true-p x-select-active-regions-enable-clipboard)
+       (x-selection-owner-p 'CLIPBOARD)
+       (x-set-selection 'CLIPBOARD (buffer-substring-no-properties
+				    (region-beginning) (region-end)))))
+
 ;; Many places set mark-active directly, and several of them failed to also
 ;; run deactivate-mark-hook.  This shorthand should simplify.
 (defsubst deactivate-mark (&optional force)
   "Deactivate the mark by setting `mark-active' to nil.
 Unless FORCE is non-nil, this function does nothing if Transient
 Mark mode is disabled.
 This function also runs `deactivate-mark-hook'."
   (when (or transient-mark-mode force)
     ;; Copy the latest region into the primary selection, if desired.
     (and select-active-regions
 	 mark-active
-	 (x-selection-owner-p 'PRIMARY)
-	 (x-set-selection 'PRIMARY (buffer-substring-no-properties
-				    (region-beginning) (region-end))))
+	 (select-active-regions--end))
     (if (and (null force)
 	     (or (eq transient-mark-mode 'lambda)
 		 (and (eq (car-safe transient-mark-mode) 'only)
 		      (null (cdr transient-mark-mode)))))
 	;; When deactivating a temporary region, don't change
 	;; `mark-active' or run `deactivate-mark-hook'.
 	(setq transient-mark-mode nil)
       (if (eq (car-safe transient-mark-mode) 'only)
@@ -3506,17 +3526,17 @@
 
 (defun activate-mark ()
   "Activate the mark."
   (when (mark t)
     (setq mark-active t)
     (unless transient-mark-mode
       (setq transient-mark-mode 'lambda))
     (when select-active-regions
-      (x-set-selection 'PRIMARY (current-buffer)))))
+      (select-active-regions--start))))
 
 (defun set-mark (pos)
   "Set this buffer's mark to POS.  Don't use this function!
 That is to say, don't use this function unless you want
 the user to see that the mark has moved, and you want the previous
 mark position to be lost.
 
 Normally, when a new mark is set, the old one should go on the stack.
@@ -3530,17 +3550,17 @@
 
    (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
 
   (if pos
       (progn
 	(setq mark-active t)
 	(run-hooks 'activate-mark-hook)
 	(when select-active-regions
-	  (x-set-selection 'PRIMARY (current-buffer)))
+	  (select-active-regions--start))
 	(set-marker (mark-marker) pos (current-buffer)))
     ;; Normally we never clear mark-active except in Transient Mark mode.
     ;; But when we actually clear out the mark value too, we must
     ;; clear mark-active in any mode.
     (deactivate-mark t)
     (set-marker (mark-marker) nil)))
 
 (defcustom use-empty-active-region nil
Index: lisp/term/x-win.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/term/x-win.el,v
retrieving revision 1.240
diff -U 8 -r1.240 x-win.el
--- lisp/term/x-win.el	19 Mar 2009 00:56:52 -0000	1.240
+++ lisp/term/x-win.el	18 Jul 2009 18:43:58 -0000
@@ -1243,16 +1243,26 @@
   :type 'boolean
   :group 'killing)
 
 (defcustom x-select-enable-primary t
   "Non-nil means cutting and pasting uses the primary selection."
   :type 'boolean
   :group 'killing)
 
+(defcustom x-select-active-regions-enable-clipboard nil
+  "Non-nil means `select-active-regions' uses the clipboard"
+  :type 'boolean
+  :group 'killing)
+
+(defcustom x-select-active-regions-enable-primary t
+  "Non-nil means `select-active-regions' uses the primary selection."
+  :type 'boolean
+  :group 'killing)
+
 (defun x-select-text (text &optional push)
   "Make TEXT, a string, the primary X selection.
 Also, set the value of X cut buffer 0, for backward compatibility
 with older X applications.
 gildea@stop.mail-abuse.org says it's not desirable to put kills
 in the clipboard."
   ;; With multi-tty, this function may be called from a tty frame.
   (when (eq (framep (selected-frame)) 'x)

  parent reply	other threads:[~2009-07-18 18:45 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-18 11:20 select-active-regions Eli Zaretskii
2009-07-18 13:41 ` select-active-regions David De La Harpe Golden
2009-07-18 13:47   ` select-active-regions David De La Harpe Golden
2009-07-18 13:54   ` select-active-regions Eli Zaretskii
2009-07-18 14:19     ` select-active-regions Chong Yidong
2009-07-18 18:33       ` select-active-regions Eli Zaretskii
2009-07-18 18:48         ` select-active-regions David De La Harpe Golden
2009-07-18 19:23           ` select-active-regions Eli Zaretskii
2009-07-18 19:50             ` select-active-regions David De La Harpe Golden
2009-07-19 14:41             ` select-active-regions Jason Rumney
2009-07-19 17:39               ` select-active-regions Eli Zaretskii
2009-07-19 19:36                 ` select-active-regions David De La Harpe Golden
2009-07-19 20:20                   ` select-active-regions Eli Zaretskii
2009-07-19 21:52                     ` select-active-regions Lennart Borgman
2009-07-20  3:15                       ` select-active-regions Eli Zaretskii
2009-07-20  3:20                         ` select-active-regions Lennart Borgman
2009-07-20 18:40                           ` select-active-regions Eli Zaretskii
2009-07-20  0:22                     ` select-active-regions David De La Harpe Golden
2009-07-20  3:12                       ` select-active-regions Eli Zaretskii
2009-07-18 18:51         ` select-active-regions Chong Yidong
2009-07-18 19:20           ` select-active-regions Eli Zaretskii
2009-07-18 19:37             ` select-active-regions Chong Yidong
2009-07-18 19:45               ` select-active-regions Eli Zaretskii
2009-07-18 20:15                 ` select-active-regions David De La Harpe Golden
2009-07-18 18:45     ` David De La Harpe Golden [this message]
2009-07-18 19:26       ` select-active-regions Eli Zaretskii
2009-07-18 19:10   ` select-active-regions Eli Zaretskii
2009-07-18 19:30     ` select-active-regions David De La Harpe Golden

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=4A621862.3010408@harpegolden.net \
    --to=david@harpegolden.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).