From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 06 Sep 2008 06:00:02 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by submit@emacsbugs.donarmstrong.com id=B.122068042025981 (code B ref -1); Sat, 06 Sep 2008 06:00:02 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.8 required=4.0 tests=AWL,BAYES_00,FVGT_m_MULTI_ODD, HAS_PACKAGE,MIXEDBDN,MURPHY_DRUGS_REL8,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 6 Sep 2008 05:53:40 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m865rbGu025975 for ; Fri, 5 Sep 2008 22:53:38 -0700 Received: from golden1.harpegolden.net (unknown [86.45.10.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 1A01F81DE for ; Sat, 6 Sep 2008 06:53:35 +0100 (IST) Message-ID: <48C21AD8.1060505@harpegolden.net> Date: Sat, 06 Sep 2008 06:53:28 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: submit@debbugs.gnu.org X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------060103000303040901090207" This is a multi-part message in MIME format. --------------060103000303040901090207 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Package: emacs Version: 23.0.60 Severity: normal Tags: patch The select-active-regions in-tree does not work in all cases - it works when the region is changed by moving the mark but not when it is changed by certain other means e.g. moving the point with the keyboard. (Workaround: C-x C-x C-x C-x ...). There were a couple of approaches tried a while back (see emacs-devel "Improved X Selections" thread). The idle timer seemed to work best in practice, despite (or because of) "coarse graining" i.e. a bunch of small region changes in a row don't reupdate the selection for each change, only kicks in when emacs has idled. Attached patch is a simple idle-timer based implementation. Concerns here may also apply to the activate-mark-hook (which states in its documentation that it is rerun when region changes). Having that work similarly with the same method would probably mean that active region timer would have to be enabled whenever the mark is active, not just when select-active-regions is on. --------------060103000303040901090207 Content-Type: text/x-patch; name="select-active-regions-by-idle-timer.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions-by-idle-timer.diff" Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 6 Sep 2008 05:41:14 -0000 @@ -3439,18 +3439,46 @@ (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode (setq transient-mark-mode 'lambda)))) +(defvar select-active-regions-timer nil) + +(defvar select-active-regions-last-region-hash nil) + +(defun select-active-regions-maybe-set-selection () + "Implements `select-active-regions', called from idle timer +`select-active-regions-timer'" + (and select-active-regions + (region-active-p) + (> (region-end) (region-beginning)) + (if (or (not select-active-regions-last-region-hash) + (x-selection-owner-p nil)) + (let ((region-hash + (md5 (current-buffer) (region-beginning) + (region-end) nil t))) + (unless (string-equal region-hash + select-active-regions-last-region-hash) + (x-set-selection + nil (buffer-substring (region-beginning) (region-end))) + (setq select-active-regions-last-region-hash + region-hash))) + (setq select-active-regions-last-region-hash 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. + +In conjunction with this, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil, set `mouse-drag-copy-region' +to nil, and turn on `transient-mark-mode'." :type 'boolean :group 'killing :version "23.1") (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 @@ -3466,19 +3494,26 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) + (if select-active-regions + (progn + (unless select-active-regions-timer + (setq select-active-regions-timer + (run-with-idle-timer + 0.1 t 'select-active-regions-maybe-set-selection))) + (select-active-regions-maybe-set-selection)) + (when select-active-regions-timer + (cancel-timer select-active-regions-timer) + (setq select-active-regions-timer nil))) (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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) --------------060103000303040901090207 Content-Type: text/plain; name="ChangeLog.select-active-regions-by-idle-timer" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.select-active-regions-by-idle-timer" 2008-09-06 David De La Harpe Golden * simple.el: idle-timer implementation of select-active-regions --------------060103000303040901090207-- From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: Acknowledgement (select-active-regions only half-working) Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 06 Sep 2008 19:45:05 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122072973720106 (code B ref 902); Sat, 06 Sep 2008 19:45:05 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-4.6 required=4.0 tests=AWL,BAYES_00,FVGT_m_MULTI_ODD, HAS_BUG_NUMBER,MIXEDBDN,MURPHY_DRUGS_REL8,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 6 Sep 2008 19:35:37 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m86JZXnc020100 for <902@emacsbugs.donarmstrong.com>; Sat, 6 Sep 2008 12:35:34 -0700 Received: from golden1.harpegolden.net (86-43-162-117.b-ras2.prp.dublin.eircom.net [86.43.162.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 7B86081DE for <902@emacsbugs.donarmstrong.com>; Sat, 6 Sep 2008 20:35:32 +0100 (IST) Message-ID: <48C2DB81.2080007@harpegolden.net> Date: Sat, 06 Sep 2008 20:35:29 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------080507030205070504020707" This is a multi-part message in MIME format. --------------080507030205070504020707 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Uh. Hashing is probably silly/pointless in this case (wrote that far too early in the morning...). Revised patch attached, just saves last region and uses string-equal. --------------080507030205070504020707 Content-Type: text/x-patch; name="select-active-regions-by-idle-timer_rev2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions-by-idle-timer_rev2.diff" Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 6 Sep 2008 19:33:00 -0000 @@ -3439,18 +3439,45 @@ (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode (setq transient-mark-mode 'lambda)))) +(defvar select-active-regions-timer nil) + +(defvar select-active-regions-last-region nil) + +(defun select-active-regions-maybe-set-selection () + "Implements `select-active-regions', called from idle timer +`select-active-regions-timer'" + (and select-active-regions + (region-active-p) + (> (region-end) (region-beginning)) + (if (or (not select-active-regions-last-region) + (x-selection-owner-p nil)) + (let ((latest-region + (buffer-substring (region-beginning) (region-end)))) + (unless (string-equal latest-region + select-active-regions-last-region) + (x-set-selection + nil latest-region) + (setq select-active-regions-last-region + latest-region))) + (setq select-active-regions-last-region 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. + +In conjunction with this, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil, set `mouse-drag-copy-region' +to nil, and turn on `transient-mark-mode'." :type 'boolean :group 'killing :version "23.1") (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 @@ -3466,19 +3493,26 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) + (if select-active-regions + (progn + (unless select-active-regions-timer + (setq select-active-regions-timer + (run-with-idle-timer + 0.1 t 'select-active-regions-maybe-set-selection))) + (select-active-regions-maybe-set-selection)) + (when select-active-regions-timer + (cancel-timer select-active-regions-timer) + (setq select-active-regions-timer nil))) (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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) --------------080507030205070504020707-- From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: Stefan Monnier , 902@debbugs.gnu.org Resent-From: Stefan Monnier Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 06 Sep 2008 19:55:05 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by submit@emacsbugs.donarmstrong.com id=B.122073062124931 (code B ref -1); Sat, 06 Sep 2008 19:55:05 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.7 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 6 Sep 2008 19:50:21 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.teksavvy.com [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m86JoAcC024209; Sat, 6 Sep 2008 12:50:11 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqYEAJl7wkhFxJRU/2dsb2JhbACBZbEAgWaBBw X-IronPort-AV: E=Sophos;i="4.32,346,1217822400"; d="scan'208";a="26458624" Received: from 69-196-148-84.dsl.teksavvy.com (HELO ceviche.home) ([69.196.148.84]) by ironport2-out.teksavvy.com with ESMTP; 06 Sep 2008 15:50:05 -0400 Received: by ceviche.home (Postfix, from userid 20848) id ECCA4B405D; Sat, 6 Sep 2008 15:50:04 -0400 (EDT) From: Stefan Monnier To: David De La Harpe Golden Cc: 902@debbugs.gnu.org, submit@debbugs.gnu.org Message-ID: References: <48C21AD8.1060505@harpegolden.net> Date: Sat, 06 Sep 2008 15:50:04 -0400 In-Reply-To: <48C21AD8.1060505@harpegolden.net> (David De La Harpe Golden's message of "Sat, 06 Sep 2008 06:53:28 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-CrossAssassin-Score: 2 > The select-active-regions in-tree does not work in all cases - it works > when the region is changed by moving the mark but not when it is changed > by certain other means e.g. moving the point with the keyboard. > (Workaround: C-x C-x C-x C-x ...). Could you be more precise and give an actual recipe? Stefan From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 06 Sep 2008 20:30:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.12207325623925 (code B ref 902); Sat, 06 Sep 2008 20:30:04 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.5 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 6 Sep 2008 20:22:42 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m86KMd8D003919 for <902@emacsbugs.donarmstrong.com>; Sat, 6 Sep 2008 13:22:40 -0700 Received: from golden1.harpegolden.net (86-43-162-117.b-ras2.prp.dublin.eircom.net [86.43.162.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 9C19A81DE; Sat, 6 Sep 2008 21:22:38 +0100 (IST) Message-ID: <48C2E68C.6060909@harpegolden.net> Date: Sat, 06 Sep 2008 21:22:36 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Stefan Monnier CC: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Stefan Monnier wrote: >> The select-active-regions in-tree does not work in all cases - it works >> when the region is changed by moving the mark but not when it is changed >> by certain other means e.g. moving the point with the keyboard. >> (Workaround: C-x C-x C-x C-x ...). > > Could you be more precise and give an actual recipe? > With transient-mark-mode and select-active-regions on: Set mark. (C-SPC) Move point with keyboard, defining an active region. Try to middle-click-paste into another application (that accepts middle clicks to paste in primary, of course) Note that what is pasted in doesn't correspond to the active region. It should. Sorry, this was a known issue pre-bug-tracker, should really have been filed a long time ago: http://lists.gnu.org/archive/html/emacs-devel/2008-02/msg00327.html (includes very similar patches that no longer apply cleanly) There might still be a related ordering issue in mouse-drag-track too, that caused annoying off-by-a-little-bit glitches when mouse-selecting: http://lists.gnu.org/archive/html/emacs-devel/2008-02/msg00316.html From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: Stefan Monnier , 902@debbugs.gnu.org Resent-From: Stefan Monnier Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sun, 07 Sep 2008 04:00:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122075963931635 (code B ref 902); Sun, 07 Sep 2008 04:00:03 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.7 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 7 Sep 2008 03:53:59 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.teksavvy.com [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m873ruRw031629 for <902@emacsbugs.donarmstrong.com>; Sat, 6 Sep 2008 20:53:57 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwFAHPtwkhFxJRU/2dsb2JhbACBZbEHgWaBBw X-IronPort-AV: E=Sophos;i="4.32,349,1217822400"; d="scan'208";a="26466796" Received: from 69-196-148-84.dsl.teksavvy.com (HELO ceviche.home) ([69.196.148.84]) by ironport2-out.teksavvy.com with ESMTP; 06 Sep 2008 23:53:50 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 7CA92B405D; Sat, 6 Sep 2008 23:53:50 -0400 (EDT) From: Stefan Monnier To: David De La Harpe Golden Cc: 902@debbugs.gnu.org Message-ID: References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> Date: Sat, 06 Sep 2008 23:53:50 -0400 In-Reply-To: <48C2E68C.6060909@harpegolden.net> (David De La Harpe Golden's message of "Sat, 06 Sep 2008 21:22:36 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii >> Could you be more precise and give an actual recipe? > With transient-mark-mode and select-active-regions on: > Set mark. (C-SPC) > Move point with keyboard, defining an active region. > Try to middle-click-paste into another application (that > accepts middle clicks to paste in primary, of course) > Note that what is pasted in doesn't correspond to the > active region. It should. Whether it should or not is very debatable. Historically, Emacs has always reuqested the user to select with the mouse or use M-w for that, and I have seen no evidence that people usually expect Emacs to copy the region to the X11-selection more eagerly. Your suggestion might please some people, but I do not think it should be used by default. So I suggest you turn your code into a global minor mode. > There might still be a related ordering issue in mouse-drag-track too, > that caused annoying off-by-a-little-bit glitches when mouse-selecting: > http://lists.gnu.org/archive/html/emacs-devel/2008-02/msg00316.html I'm not sure I understand. If it relates to the current code (as opposed to yours), then please post a separate bug report for it (and include a recipe, of course). Stefan From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sun, 07 Sep 2008 20:35:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122081926829928 (code B ref 902); Sun, 07 Sep 2008 20:35:04 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.8 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 7 Sep 2008 20:27:48 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m87KRjxN029922 for <902@emacsbugs.donarmstrong.com>; Sun, 7 Sep 2008 13:27:46 -0700 Received: from golden1.harpegolden.net (86-43-162-117.b-ras2.prp.dublin.eircom.net [86.43.162.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id A2D2A81AD; Sun, 7 Sep 2008 21:27:44 +0100 (IST) Message-ID: <48C43937.7030702@harpegolden.net> Date: Sun, 07 Sep 2008 21:27:35 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Stefan Monnier CC: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Stefan Monnier wrote: > Whether it should or not is very debatable. Shrug. That would be why it is optional, then. > Historically, Emacs has always reuqested the user to select with the > mouse or use M-w for that, Indeed. That is pretty much what select-active-regions was introduced to address though? - so one can e.g. use M-w for CLIPBOARD yet have PRIMARY set by user-selection (i.e. establishment of a nonzer-sized active region) like other apps. > I do not think it should be used by default. Who's talking about using it by default at this point? If a user actually turns select-active-regions on though, it should work. It could easily enough be recast as a global minor mode I guess. But it's just a boolean setting in-tree at the moment. From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: Stefan Monnier , 902@debbugs.gnu.org Resent-From: Stefan Monnier Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sun, 07 Sep 2008 21:25:13 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122082242016505 (code B ref 902); Sun, 07 Sep 2008 21:25:13 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.7 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 7 Sep 2008 21:20:20 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m87LKGfP016278 for <902@emacsbugs.donarmstrong.com>; Sun, 7 Sep 2008 14:20:18 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiQFACPiw0hFxIqP/2dsb2JhbACBZbAUgWaBBw X-IronPort-AV: E=Sophos;i="4.32,353,1217822400"; d="scan'208";a="26488247" Received: from 69-196-138-143.dsl.teksavvy.com (HELO ceviche.home) ([69.196.138.143]) by ironport2-out.teksavvy.com with ESMTP; 07 Sep 2008 17:20:11 -0400 Received: by ceviche.home (Postfix, from userid 20848) id B24C8B4062; Sun, 7 Sep 2008 17:20:10 -0400 (EDT) From: Stefan Monnier To: David De La Harpe Golden Cc: 902@debbugs.gnu.org Message-ID: References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> Date: Sun, 07 Sep 2008 17:20:10 -0400 In-Reply-To: <48C43937.7030702@harpegolden.net> (David De La Harpe Golden's message of "Sun, 07 Sep 2008 21:27:35 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sorry, don't mind me, I was completely confused. Stefan From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Tue, 09 Sep 2008 00:50:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122092094813963 (code B ref 902); Tue, 09 Sep 2008 00:50:03 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.4 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MIXEDBDN,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 9 Sep 2008 00:42:28 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m890gN3r013957 for <902@emacsbugs.donarmstrong.com>; Mon, 8 Sep 2008 17:42:24 -0700 Received: from golden1.harpegolden.net (86-43-162-175.b-ras2.prp.dublin.eircom.net [86.43.162.175]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id D1AD581AD; Tue, 9 Sep 2008 01:42:21 +0100 (IST) Message-ID: <48C5C661.4090201@harpegolden.net> Date: Tue, 09 Sep 2008 01:42:09 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Stefan Monnier CC: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------040401000202010308040608" This is a multi-part message in MIME format. --------------040401000202010308040608 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Stefan Monnier wrote: > Sorry, don't mind me, I was completely confused. > > No worries. Anyway, there's probably a much more elegant way: (Background: I «gasp» read the docstring for x-set-selection, and _thought_ I'd found a better way - it can take a cons of markers to _lazily_ find the selection data as whatever's between the markers when something requests the selection. However, it turns out that the emacs point is _not_ in fact a marker, so you can't use mark-marker and point-marker to find the region on-demand (point-marker just returns a marker to the instantaneous position of the point)) *** Sooo - Here's a solution that seems generally saner, though does wander deeper into the emacs core - allow x-set-selection to take a function that will be funcalled on demand to return a string to use as the selection data, not just a cons of markers. Avoids performance issues that the moronic string-equal or hash in the timer would introduce, and the (theoretical, for inhumanly fast users) potential flakiness of an idle timer. --------------040401000202010308040608 Content-Type: text/x-patch; name="select-active-regions_lazy_r1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions_lazy_r1.diff" Index: lisp/select.el =================================================================== RCS file: /sources/emacs/emacs/lisp/select.el,v retrieving revision 1.44 diff -U 8 -r1.44 select.el --- lisp/select.el 12 Jun 2008 03:56:16 -0000 1.44 +++ lisp/select.el 9 Sep 2008 00:35:08 -0000 @@ -123,16 +123,20 @@ integer (or a cons of two integers or list of two integers). The selection may also be a cons of two markers pointing to the same buffer, or an overlay. In these cases, the selection is considered to be the text between the markers *at whatever time the selection is examined*. Thus, editing done in the buffer after you specify the selection can alter the effective value of the selection. +The selection may also be a function of one argument that returns a string. +In that case, the selection is considered to be the string +returned by the function *at whatever time the selection is examined*. + The data may also be a vector of valid non-vector selection values. The return value is DATA. Interactively, this command sets the primary selection. Without prefix argument, it reads the selection in the minibuffer. With prefix argument, it uses the text of the region as the selection value ." (interactive (if (not current-prefix-arg) @@ -170,17 +174,22 @@ (and (consp data) (markerp (car data)) (markerp (cdr data)) (marker-buffer (car data)) (marker-buffer (cdr data)) (eq (marker-buffer (car data)) (marker-buffer (cdr data))) (buffer-name (marker-buffer (car data))) - (buffer-name (marker-buffer (cdr data)))))) + (buffer-name (marker-buffer (cdr data)))) + ;; no real guarantee that an impure function that returns + ;; a string now will always do so, but might as well + ;; try it out, for early failure. + (and (functionp data) + (stringp (funcall data))))) ;;; Cut Buffer support (declare-function x-get-cut-buffer-internal "xselect.c") (defun x-get-cut-buffer (&optional which-one) "Returns the value of one of the 8 X server cut-buffers. Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0. @@ -229,17 +238,25 @@ (markerp (cdr value))) (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) (signal 'error (list "markers must be in the same buffer" (car value) (cdr value)))) (save-excursion (set-buffer (or (marker-buffer (car value)) (error "selection is in a killed buffer"))) - (setq str (buffer-substring (car value) (cdr value)))))) + (setq str (buffer-substring (car value) (cdr value))))) + + ((functionp value) + (let ((ret (funcall value))) + (if (stringp ret) + (setq str ret) + (signal 'error + (list "selection function must return string" + value ret)))))) (when str ;; If TYPE is nil, this is a local request, thus return STR as ;; is. Otherwise, encode STR. (if (not type) str (setq coding (or next-selection-coding-system selection-coding-system)) (if coding @@ -304,17 +321,24 @@ ((and (consp value) (markerp (car value)) (markerp (cdr value))) (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) (signal 'error (list "markers must be in the same buffer" (car value) (cdr value)))) - (abs (- (car value) (cdr value))))))) + (abs (- (car value) (cdr value)))) + ((functionp value) + (let ((ret (funcall value))) + (if (stringp ret) + (length ret) + (signal 'error + (list "no selection length found" + value ret)))))))) (if value ; force it to be in 32-bit format. (cons (ash value -16) (logand value 65535)) nil))) (defun xselect-convert-to-targets (selection type value) ;; return a vector of atoms, but remove duplicates first. (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist))) (rest all)) Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 9 Sep 2008 00:35:12 -0000 @@ -3416,44 +3416,60 @@ is active, and returns an integer or nil in the usual way. 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. + +In conjunction with this, to ape some other X11 apps, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil, set `mouse-drag-copy-region' +to nil, and turn on `transient-mark-mode'." + :type 'boolean + :group 'killing + :version "23.1") + ;; Many places set mark-active directly, and several of them failed to also ;; run deactivate-mark-hook. This shorthand should simplify. (defsubst deactivate-mark () "Deactivate the mark by setting `mark-active' to nil. \(That makes a difference only in Transient Mark mode.) Also runs the hook `deactivate-mark-hook'." (when transient-mark-mode (if (or (eq transient-mark-mode 'lambda) (and (eq (car-safe transient-mark-mode) 'only) (null (cdr transient-mark-mode)))) (setq transient-mark-mode nil) (if (eq (car-safe transient-mark-mode) 'only) (setq transient-mark-mode (cdr transient-mark-mode))) (setq mark-active nil) - (run-hooks 'deactivate-mark-hook)))) + (run-hooks 'deactivate-mark-hook)) + (and select-active-regions + (x-selection-owner-p nil) + (< (region-beginning) (region-end)) + (x-set-selection + nil (buffer-substring (region-beginning) (region-end)))))) (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode - (setq transient-mark-mode 'lambda)))) - -(defcustom select-active-regions nil - "If non-nil, an active region automatically becomes the window selection." - :type 'boolean - :group 'killing - :version "23.1") + (setq transient-mark-mode 'lambda)) + (and select-active-regions + (x-set-selection + nil (lambda () + (if (< (region-beginning) (region-end)) + (buffer-substring (region-beginning) (region-end)) + "")))))) (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. @@ -3466,20 +3482,28 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) + (set-marker (mark-marker) pos (current-buffer)) (and select-active-regions (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) - (set-marker (mark-marker) pos (current-buffer))) + nil (lambda () + (if (< (region-beginning) (region-end)) + (buffer-substring (region-beginning) (region-end)) + ""))))) + (and mark-active select-active-regions + (< (region-beginning) (region-end)) + (x-selection-owner-p nil) + (x-set-selection + nil (buffer-substring (region-beginning) (region-end)))) ;; 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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) (defcustom use-empty-active-region nil Index: lisp/mouse.el =================================================================== RCS file: /sources/emacs/emacs/lisp/mouse.el,v retrieving revision 1.347 diff -U 8 -r1.347 mouse.el --- lisp/mouse.el 11 Aug 2008 01:23:05 -0000 1.347 +++ lisp/mouse.el 9 Sep 2008 00:35:13 -0000 @@ -906,16 +906,17 @@ (defun mouse-drag-track (start-event &optional do-mouse-drag-region-post-process) "Track mouse drags by highlighting area between point and cursor. The region will be defined with mark and point, and the overlay will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by mouse-drag-region." (mouse-minibuffer-check start-event) (setq mouse-selection-click-count-buffer (current-buffer)) + (deactivate-mark) (let* ((original-window (selected-window)) ;; We've recorded what we needed from the current buffer and ;; window, now let's jump to the place of the event, where things ;; are happening. (_ (mouse-set-point start-event)) (echo-keystrokes 0) (start-posn (event-start start-event)) (start-point (posn-point start-posn)) @@ -950,17 +951,16 @@ (if (< (point) start-point) (goto-char start-point)) (setq start-point (point)) (if remap-double-click ;; Don't expand mouse overlay in links (setq click-count 0)) (mouse-move-drag-overlay mouse-drag-overlay start-point start-point click-count) (overlay-put mouse-drag-overlay 'window start-window) - (deactivate-mark) (let (event end end-point last-end-point) (track-mouse (while (progn (setq event (read-event)) (or (mouse-movement-p event) (memq (car-safe event) '(switch-frame select-window)))) (if (memq (car-safe event) '(switch-frame select-window)) nil --------------040401000202010308040608 Content-Type: text/plain; name="ChangeLog.select-active-regions_lazy_r1" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.select-active-regions_lazy_r1" 2008-09-06 David De La Harpe Golden * select.el: allow x-set-selection to take a function that is called on-demand to obtain selection data. * simple.el: lazy implementation of select-active-regions. * mouse.el: fix time-ordering of deactivate-mark operations in mouse drag tracking. --------------040401000202010308040608-- From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: Stefan Monnier , 902@debbugs.gnu.org Resent-From: Stefan Monnier Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Tue, 09 Sep 2008 14:55:08 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122097181520410 (code B ref 902); Tue, 09 Sep 2008 14:55:08 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.8 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 9 Sep 2008 14:50:15 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m89EoAX6019809 for <902@emacsbugs.donarmstrong.com>; Tue, 9 Sep 2008 07:50:11 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsAEADMqxkhFxIqP/2dsb2JhbACBZbRYgWSBBw X-IronPort-AV: E=Sophos;i="4.32,365,1217822400"; d="scan'208";a="26560074" Received: from 69-196-138-143.dsl.teksavvy.com (HELO pastel.home) ([69.196.138.143]) by ironport2-out.teksavvy.com with ESMTP; 09 Sep 2008 10:50:05 -0400 Received: by pastel.home (Postfix, from userid 20848) id 32EF554279; Tue, 9 Sep 2008 10:50:05 -0400 (EDT) From: Stefan Monnier To: David De La Harpe Golden Cc: 902@debbugs.gnu.org Message-ID: References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> Date: Tue, 09 Sep 2008 10:50:05 -0400 In-Reply-To: <48C5C661.4090201@harpegolden.net> (David De La Harpe Golden's message of "Tue, 09 Sep 2008 01:42:09 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable >> Sorry, don't mind me, I was completely confused. > No worries. Anyway, there's probably a much more elegant way: > (Background: I =ABgasp=BB read the docstring for x-set-selection, and > _thought_ I'd found a better way - it can take a cons of markers > to _lazily_ find the selection data as whatever's between > the markers when something requests the selection. However, it turns out > that the emacs point is _not_ in fact a marker, so you can't use > mark-marker and point-marker to find the region on-demand (point-marker > just returns a marker to the instantaneous position of the point)) > *** Sooo - Here's a solution that seems generally saner, though does > wander deeper into the emacs core - allow x-set-selection to take a > function that will be funcalled on demand to return a string to use as > the selection data, not just a cons of markers. > Avoids performance issues that the moronic string-equal or hash in the > timer would introduce, and the (theoretical, for inhumanly fast users) > potential flakiness of an idle timer. Sounds good on the surface [ I don't know the insides] > + ;; no real guarantee that an impure function that returns > + ;; a string now will always do so, but might as well > + ;; try it out, for early failure. > + (and (functionp data) > + (stringp (funcall data))))) I wouldn't worry/care about checking the return value here. =20 > + ((functionp value) > + (let ((ret (funcall value))) > + (if (stringp ret) > + (setq str ret) > + (signal 'error > + (list "selection function must return string" > + value ret)))))) Please move this code to an auxiliary function, since it's repeated twice. =20 > + (and select-active-regions > + (x-set-selection > + nil (lambda () > + (if (< (region-beginning) (region-end)) > + (buffer-substring (region-beginning) (region-end)) > + "")))))) You should probably save the current buffer in some variable (current at the time of the x-set-selection) and restore it when the lambda is called. Also, give a name to this function, since it's used at least twice. An alternative is to use not a function but a buffer (which would mean "use the region's content, if active"). =20 Stefan From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Tue, 09 Sep 2008 19:30:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122098802618786 (code B ref 902); Tue, 09 Sep 2008 19:30:03 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.5 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MIXEDBDN,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 9 Sep 2008 19:20:26 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m89JKLVj018482 for <902@emacsbugs.donarmstrong.com>; Tue, 9 Sep 2008 12:20:22 -0700 Received: from golden1.harpegolden.net (unknown [86.45.15.116]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 86F0D81AD; Tue, 9 Sep 2008 20:20:19 +0100 (IST) Message-ID: <48C6CC6F.5090100@harpegolden.net> Date: Tue, 09 Sep 2008 20:20:15 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Stefan Monnier CC: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------030902010909000102070409" This is a multi-part message in MIME format. --------------030902010909000102070409 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Stefan Monnier wrote: > An alternative is to use not a function but a buffer (which would mean > "use the region's content, if active"). Yeah, allowing a function might be a giant bit too open-ended. Attached please find buffer-passing implementation. --------------030902010909000102070409 Content-Type: text/x-patch; name="select-active-regions_lazybuf_r1.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions_lazybuf_r1.diff" Index: lisp/select.el =================================================================== RCS file: /sources/emacs/emacs/lisp/select.el,v retrieving revision 1.44 diff -U 8 -r1.44 select.el --- lisp/select.el 12 Jun 2008 03:56:16 -0000 1.44 +++ lisp/select.el 9 Sep 2008 19:02:15 -0000 @@ -123,16 +123,20 @@ integer (or a cons of two integers or list of two integers). The selection may also be a cons of two markers pointing to the same buffer, or an overlay. In these cases, the selection is considered to be the text between the markers *at whatever time the selection is examined*. Thus, editing done in the buffer after you specify the selection can alter the effective value of the selection. +The selection may also be a buffer object. In that case, the selection is +considered to be the region between the mark and point, if any, in that +buffer, *at whatever time the selection is examined*. + The data may also be a vector of valid non-vector selection values. The return value is DATA. Interactively, this command sets the primary selection. Without prefix argument, it reads the selection in the minibuffer. With prefix argument, it uses the text of the region as the selection value ." (interactive (if (not current-prefix-arg) @@ -170,17 +174,18 @@ (and (consp data) (markerp (car data)) (markerp (cdr data)) (marker-buffer (car data)) (marker-buffer (cdr data)) (eq (marker-buffer (car data)) (marker-buffer (cdr data))) (buffer-name (marker-buffer (car data))) - (buffer-name (marker-buffer (cdr data)))))) + (buffer-name (marker-buffer (cdr data)))) + (bufferp data))) ;;; Cut Buffer support (declare-function x-get-cut-buffer-internal "xselect.c") (defun x-get-cut-buffer (&optional which-one) "Returns the value of one of the 8 X server cut-buffers. Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0. @@ -229,17 +234,24 @@ (markerp (cdr value))) (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) (signal 'error (list "markers must be in the same buffer" (car value) (cdr value)))) (save-excursion (set-buffer (or (marker-buffer (car value)) (error "selection is in a killed buffer"))) - (setq str (buffer-substring (car value) (cdr value)))))) + (setq str (buffer-substring (car value) (cdr value))))) + + ((bufferp value) + (save-excursion + (set-buffer value) + (if (and (mark t) (point)) + (setq str (buffer-substring (mark t) (point))) + (setq str ""))))) (when str ;; If TYPE is nil, this is a local request, thus return STR as ;; is. Otherwise, encode STR. (if (not type) str (setq coding (or next-selection-coding-system selection-coding-system)) (if coding @@ -304,17 +316,23 @@ ((and (consp value) (markerp (car value)) (markerp (cdr value))) (or (eq (marker-buffer (car value)) (marker-buffer (cdr value))) (signal 'error (list "markers must be in the same buffer" (car value) (cdr value)))) - (abs (- (car value) (cdr value))))))) + (abs (- (car value) (cdr value)))) + ((bufferp value) + (save-excursion + (set-buffer value) + (if (and (mark t) (point)) + (abs (- (point) (mark t))) + 0)))))) (if value ; force it to be in 32-bit format. (cons (ash value -16) (logand value 65535)) nil))) (defun xselect-convert-to-targets (selection type value) ;; return a vector of atoms, but remove duplicates first. (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist))) (rest all)) @@ -338,28 +356,36 @@ (cond ((overlayp value) (buffer-file-name (or (overlay-buffer value) (error "selection is in a killed buffer")))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) (buffer-file-name (or (marker-buffer (car value)) (error "selection is in a killed buffer")))) + ((bufferp value) + (buffer-file-name value)) (t nil))) (defun xselect-convert-to-charpos (selection type value) (let (a b tmp) (cond ((cond ((overlayp value) (setq a (overlay-start value) b (overlay-end value))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (car value) - b (cdr value)))) + b (cdr value))) + ((bufferp value) + (save-excursion + (set-buffer value) + (and (mark t) (point) + (setq a (mark t) + b (point)))))) (setq a (1- a) b (1- b)) ; zero-based (if (< b a) (setq tmp a a b b tmp)) (cons 'SPAN (vector (cons (ash a -16) (logand a 65535)) (cons (ash b -16) (logand b 65535)))))))) (defun xselect-convert-to-lineno (selection type value) (let (a b buf tmp) @@ -368,16 +394,23 @@ (markerp (cdr value))) (setq a (marker-position (car value)) b (marker-position (cdr value)) buf (marker-buffer (car value)))) ((overlayp value) (setq buf (overlay-buffer value) a (overlay-start value) b (overlay-end value))) + ((bufferp value) + (save-excursion + (set-buffer value) + (and (mark t) (point) + (setq buf value + a (mark t) + b (point))))) ) (save-excursion (set-buffer buf) (setq a (count-lines 1 a) b (count-lines 1 b))) (if (< b a) (setq tmp a a b b tmp)) (cons 'SPAN (vector (cons (ash a -16) (logand a 65535)) @@ -390,16 +423,23 @@ (markerp (cdr value))) (setq a (car value) b (cdr value) buf (marker-buffer a))) ((overlayp value) (setq buf (overlay-buffer value) a (overlay-start value) b (overlay-end value))) + ((bufferp value) + (save-excursion + (set-buffer value) + (and (mark t) (point) + (setq buf value + a (mark t) + b (point))))) ) (save-excursion (set-buffer buf) (goto-char a) (setq a (current-column)) (goto-char b) (setq b (current-column))) (if (< b a) (setq tmp a a b b tmp)) Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 9 Sep 2008 19:02:18 -0000 @@ -3416,44 +3416,55 @@ is active, and returns an integer or nil in the usual way. 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. + +In conjunction with this, to ape some other X11 apps, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil, set `mouse-drag-copy-region' +to nil, and turn on `transient-mark-mode'." + :type 'boolean + :group 'killing + :version "23.1") + ;; Many places set mark-active directly, and several of them failed to also ;; run deactivate-mark-hook. This shorthand should simplify. (defsubst deactivate-mark () "Deactivate the mark by setting `mark-active' to nil. \(That makes a difference only in Transient Mark mode.) Also runs the hook `deactivate-mark-hook'." (when transient-mark-mode + (and mark-active select-active-regions + (x-selection-owner-p nil) + (x-set-selection nil (x-get-selection nil))) (if (or (eq transient-mark-mode 'lambda) (and (eq (car-safe transient-mark-mode) 'only) (null (cdr transient-mark-mode)))) (setq transient-mark-mode nil) (if (eq (car-safe transient-mark-mode) 'only) (setq transient-mark-mode (cdr transient-mark-mode))) (setq mark-active nil) (run-hooks 'deactivate-mark-hook)))) (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode - (setq transient-mark-mode 'lambda)))) + (setq transient-mark-mode 'lambda)) + (when select-active-regions + (x-set-selection nil (current-buffer))))) -(defcustom select-active-regions nil - "If non-nil, an active region automatically becomes the window selection." - :type 'boolean - :group 'killing - :version "23.1") (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. @@ -3466,20 +3477,22 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) - (set-marker (mark-marker) pos (current-buffer))) + (set-marker (mark-marker) pos (current-buffer)) + (when select-active-regions + (x-set-selection nil (current-buffer)))) + (and mark-active select-active-regions + (x-selection-owner-p nil) + (x-set-selection nil (x-get-selection nil))) ;; 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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) (defcustom use-empty-active-region nil Index: lisp/mouse.el =================================================================== RCS file: /sources/emacs/emacs/lisp/mouse.el,v retrieving revision 1.347 diff -U 8 -r1.347 mouse.el --- lisp/mouse.el 11 Aug 2008 01:23:05 -0000 1.347 +++ lisp/mouse.el 9 Sep 2008 19:02:20 -0000 @@ -906,16 +906,17 @@ (defun mouse-drag-track (start-event &optional do-mouse-drag-region-post-process) "Track mouse drags by highlighting area between point and cursor. The region will be defined with mark and point, and the overlay will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by mouse-drag-region." (mouse-minibuffer-check start-event) (setq mouse-selection-click-count-buffer (current-buffer)) + (deactivate-mark) (let* ((original-window (selected-window)) ;; We've recorded what we needed from the current buffer and ;; window, now let's jump to the place of the event, where things ;; are happening. (_ (mouse-set-point start-event)) (echo-keystrokes 0) (start-posn (event-start start-event)) (start-point (posn-point start-posn)) @@ -950,17 +951,16 @@ (if (< (point) start-point) (goto-char start-point)) (setq start-point (point)) (if remap-double-click ;; Don't expand mouse overlay in links (setq click-count 0)) (mouse-move-drag-overlay mouse-drag-overlay start-point start-point click-count) (overlay-put mouse-drag-overlay 'window start-window) - (deactivate-mark) (let (event end end-point last-end-point) (track-mouse (while (progn (setq event (read-event)) (or (mouse-movement-p event) (memq (car-safe event) '(switch-frame select-window)))) (if (memq (car-safe event) '(switch-frame select-window)) nil @@ -1352,16 +1352,19 @@ (defun mouse-yank-primary (click) "Insert the primary selection at the position clicked on. Move point to the end of the inserted text. If `mouse-yank-at-point' is non-nil, insert at point regardless of where you click." (interactive "e") ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) + ;; if region is active and _is_ primary (due to select-active-regions) + ;; avoid doubling upon repeated consecutive clicks. + (and select-active-regions (deactivate-mark)) (or mouse-yank-at-point (mouse-set-point click)) (let ((primary (x-get-selection 'PRIMARY))) (if primary (insert (x-get-selection 'PRIMARY)) (error "No primary selection")))) (defun mouse-kill-ring-save (click) "Copy the region between point and the mouse click in the kill ring. --------------030902010909000102070409 Content-Type: text/plain; name="ChangeLog.select-active-regions_lazybuf_r1" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.select-active-regions_lazybuf_r1" 2008-09-09 David De La Harpe Golden * select.el: allow x-set-selection to take a buffer object that is inspected on-demand to obtain selection data from its region. * simple.el: lazy implementation of select-active-regions. * mouse.el: fix time-ordering of deactivate-mark operations in mouse drag tracking. Avoid double insertion in mouse-yank-primary when select-active-regions is on. --------------030902010909000102070409-- From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: Stefan Monnier , 902@debbugs.gnu.org Resent-From: Stefan Monnier Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 10 Sep 2008 16:45:02 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122106467816351 (code B ref 902); Wed, 10 Sep 2008 16:45:02 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.9 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 10 Sep 2008 16:37:58 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8AGbpm6016345 for <902@emacsbugs.donarmstrong.com>; Wed, 10 Sep 2008 09:37:52 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwGAFmUx0hFxIqP/2dsb2JhbACBZbcXgWSBBg X-IronPort-AV: E=Sophos;i="4.32,373,1217822400"; d="scan'208";a="26616629" Received: from 69-196-138-143.dsl.teksavvy.com (HELO pastel.home) ([69.196.138.143]) by ironport2-out.teksavvy.com with ESMTP; 10 Sep 2008 12:37:45 -0400 Received: by pastel.home (Postfix, from userid 20848) id A61A185E5; Wed, 10 Sep 2008 12:37:45 -0400 (EDT) From: Stefan Monnier To: David De La Harpe Golden Cc: 902@debbugs.gnu.org Message-ID: References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> <48C6CC6F.5090100@harpegolden.net> Date: Wed, 10 Sep 2008 12:37:45 -0400 In-Reply-To: <48C6CC6F.5090100@harpegolden.net> (David De La Harpe Golden's message of "Tue, 09 Sep 2008 20:20:15 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii > + (save-excursion > + (set-buffer value) Aka "(with-current-buffer value". Again, since this code is present at several places, move it into its own function. Basically this function could turn the buffer value into a "cons of markers" value, so you can use it everywhere and reuse the code that handles a cons of markers. Also the select-active-regions docstring shouldn't recommend to turn on transient-mark-mode since it's already ON by default. Stefan From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 10 Sep 2008 21:55:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122108313931658 (code B ref 902); Wed, 10 Sep 2008 21:55:04 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.5 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MIXEDBDN,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 10 Sep 2008 21:45:39 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8ALjUrc031652 for <902@emacsbugs.donarmstrong.com>; Wed, 10 Sep 2008 14:45:31 -0700 Received: from golden1.harpegolden.net (unknown [86.45.15.116]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id C38D781DE; Wed, 10 Sep 2008 22:45:28 +0100 (IST) Message-ID: <48C83FF3.1060507@harpegolden.net> Date: Wed, 10 Sep 2008 22:45:23 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Stefan Monnier CC: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> <48C6CC6F.5090100@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------040201010906030400020408" This is a multi-part message in MIME format. --------------040201010906030400020408 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Stefan Monnier wrote: > Again, since this code is present at several places, move it into its > own function. Basically this function could turn the buffer value into > a "cons of markers" value, so you can use it everywhere and reuse the > code that handles a cons of markers. > Okay, sorry, I seem to have an irrational fear of introducing named functions in elisp (possibly due to lack of CL packages I'm used to for hiding). Attached. --------------040201010906030400020408 Content-Type: text/x-patch; name="select-active-regions_lazybuf_r2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions_lazybuf_r2.diff" Index: lisp/select.el =================================================================== RCS file: /sources/emacs/emacs/lisp/select.el,v retrieving revision 1.44 diff -U 8 -r1.44 select.el --- lisp/select.el 12 Jun 2008 03:56:16 -0000 1.44 +++ lisp/select.el 10 Sep 2008 20:37:34 -0000 @@ -123,16 +123,20 @@ integer (or a cons of two integers or list of two integers). The selection may also be a cons of two markers pointing to the same buffer, or an overlay. In these cases, the selection is considered to be the text between the markers *at whatever time the selection is examined*. Thus, editing done in the buffer after you specify the selection can alter the effective value of the selection. +The selection may also be a buffer object. In that case, the selection is +considered to be the region between the mark and point, if any, in that +buffer, *at whatever time the selection is examined*. + The data may also be a vector of valid non-vector selection values. The return value is DATA. Interactively, this command sets the primary selection. Without prefix argument, it reads the selection in the minibuffer. With prefix argument, it uses the text of the region as the selection value ." (interactive (if (not current-prefix-arg) @@ -170,17 +174,18 @@ (and (consp data) (markerp (car data)) (markerp (cdr data)) (marker-buffer (car data)) (marker-buffer (cdr data)) (eq (marker-buffer (car data)) (marker-buffer (cdr data))) (buffer-name (marker-buffer (car data))) - (buffer-name (marker-buffer (cdr data)))))) + (buffer-name (marker-buffer (cdr data)))) + (bufferp data))) ;;; Cut Buffer support (declare-function x-get-cut-buffer-internal "xselect.c") (defun x-get-cut-buffer (&optional which-one) "Returns the value of one of the 8 X server cut-buffers. Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0. @@ -206,18 +211,25 @@ (x-rotate-cut-buffers-internal 1)) (x-store-cut-buffer-internal 'CUT_BUFFER0 string)) ;;; Functions to convert the selection into various other selection types. ;;; Every selection type that Emacs handles is implemented this way, except ;;; for TIMESTAMP, which is a special case. +(defun xselect-buffer-region-markers-cons (buffer) + "Helper function for xselect-convert functions given buffers. (Internal)" + (with-current-buffer buffer + (cons (mark-marker) (point-marker)))) + (defun xselect-convert-to-string (selection type value) (let (str coding) + (when (bufferp value) + (setq value (xselect-buffer-region-markers-cons value))) ;; Get the actual string from VALUE. (cond ((stringp value) (setq str value)) ((overlayp value) (save-excursion (or (buffer-name (overlay-buffer value)) (error "selection is in a killed buffer")) @@ -291,16 +303,18 @@ (error "Unknow selection type: %S" type)) ))) (setq next-selection-coding-system nil) (cons type str)))) (defun xselect-convert-to-length (selection type value) + (when (bufferp value) + (setq value (xselect-buffer-region-markers-cons value))) (let ((value (cond ((stringp value) (length value)) ((overlayp value) (abs (- (overlay-end value) (overlay-start value)))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) @@ -338,35 +352,41 @@ (cond ((overlayp value) (buffer-file-name (or (overlay-buffer value) (error "selection is in a killed buffer")))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) (buffer-file-name (or (marker-buffer (car value)) (error "selection is in a killed buffer")))) + ((bufferp value) + (buffer-file-name value)) (t nil))) (defun xselect-convert-to-charpos (selection type value) + (when (bufferp value) + (setq value (xselect-buffer-region-markers-cons value))) (let (a b tmp) (cond ((cond ((overlayp value) (setq a (overlay-start value) b (overlay-end value))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (car value) b (cdr value)))) (setq a (1- a) b (1- b)) ; zero-based (if (< b a) (setq tmp a a b b tmp)) (cons 'SPAN (vector (cons (ash a -16) (logand a 65535)) (cons (ash b -16) (logand b 65535)))))))) (defun xselect-convert-to-lineno (selection type value) + (when (bufferp value) + (setq value (xselect-buffer-region-markers-cons value))) (let (a b buf tmp) (cond ((cond ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (marker-position (car value)) b (marker-position (cdr value)) buf (marker-buffer (car value)))) ((overlayp value) @@ -379,16 +399,18 @@ (setq a (count-lines 1 a) b (count-lines 1 b))) (if (< b a) (setq tmp a a b b tmp)) (cons 'SPAN (vector (cons (ash a -16) (logand a 65535)) (cons (ash b -16) (logand b 65535)))))))) (defun xselect-convert-to-colno (selection type value) + (when (bufferp value) + (setq value (xselect-buffer-region-markers-cons value))) (let (a b buf tmp) (cond ((cond ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (car value) b (cdr value) buf (marker-buffer a))) ((overlayp value) Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 10 Sep 2008 20:37:38 -0000 @@ -3416,44 +3416,55 @@ is active, and returns an integer or nil in the usual way. 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. + +In conjunction with this, to ape some other X11 apps, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil and set `mouse-drag-copy-region' +to nil." + :type 'boolean + :group 'killing + :version "23.1") + ;; Many places set mark-active directly, and several of them failed to also ;; run deactivate-mark-hook. This shorthand should simplify. (defsubst deactivate-mark () "Deactivate the mark by setting `mark-active' to nil. \(That makes a difference only in Transient Mark mode.) Also runs the hook `deactivate-mark-hook'." (when transient-mark-mode + (and mark-active select-active-regions + (x-selection-owner-p nil) + (x-set-selection nil (x-get-selection nil))) (if (or (eq transient-mark-mode 'lambda) (and (eq (car-safe transient-mark-mode) 'only) (null (cdr transient-mark-mode)))) (setq transient-mark-mode nil) (if (eq (car-safe transient-mark-mode) 'only) (setq transient-mark-mode (cdr transient-mark-mode))) (setq mark-active nil) (run-hooks 'deactivate-mark-hook)))) (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode - (setq transient-mark-mode 'lambda)))) + (setq transient-mark-mode 'lambda)) + (when select-active-regions + (x-set-selection nil (current-buffer))))) -(defcustom select-active-regions nil - "If non-nil, an active region automatically becomes the window selection." - :type 'boolean - :group 'killing - :version "23.1") (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. @@ -3466,20 +3477,22 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) - (set-marker (mark-marker) pos (current-buffer))) + (set-marker (mark-marker) pos (current-buffer)) + (when select-active-regions + (x-set-selection nil (current-buffer)))) + (and mark-active select-active-regions + (x-selection-owner-p nil) + (x-set-selection nil (x-get-selection nil))) ;; 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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) (defcustom use-empty-active-region nil Index: lisp/mouse.el =================================================================== RCS file: /sources/emacs/emacs/lisp/mouse.el,v retrieving revision 1.347 diff -U 8 -r1.347 mouse.el --- lisp/mouse.el 11 Aug 2008 01:23:05 -0000 1.347 +++ lisp/mouse.el 10 Sep 2008 20:37:39 -0000 @@ -906,16 +906,17 @@ (defun mouse-drag-track (start-event &optional do-mouse-drag-region-post-process) "Track mouse drags by highlighting area between point and cursor. The region will be defined with mark and point, and the overlay will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by mouse-drag-region." (mouse-minibuffer-check start-event) (setq mouse-selection-click-count-buffer (current-buffer)) + (deactivate-mark) (let* ((original-window (selected-window)) ;; We've recorded what we needed from the current buffer and ;; window, now let's jump to the place of the event, where things ;; are happening. (_ (mouse-set-point start-event)) (echo-keystrokes 0) (start-posn (event-start start-event)) (start-point (posn-point start-posn)) @@ -950,17 +951,16 @@ (if (< (point) start-point) (goto-char start-point)) (setq start-point (point)) (if remap-double-click ;; Don't expand mouse overlay in links (setq click-count 0)) (mouse-move-drag-overlay mouse-drag-overlay start-point start-point click-count) (overlay-put mouse-drag-overlay 'window start-window) - (deactivate-mark) (let (event end end-point last-end-point) (track-mouse (while (progn (setq event (read-event)) (or (mouse-movement-p event) (memq (car-safe event) '(switch-frame select-window)))) (if (memq (car-safe event) '(switch-frame select-window)) nil @@ -1352,16 +1352,19 @@ (defun mouse-yank-primary (click) "Insert the primary selection at the position clicked on. Move point to the end of the inserted text. If `mouse-yank-at-point' is non-nil, insert at point regardless of where you click." (interactive "e") ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) + ;; if region is active and _is_ primary (due to select-active-regions) + ;; avoid doubling upon repeated consecutive clicks. + (and select-active-regions (deactivate-mark)) (or mouse-yank-at-point (mouse-set-point click)) (let ((primary (x-get-selection 'PRIMARY))) (if primary (insert (x-get-selection 'PRIMARY)) (error "No primary selection")))) (defun mouse-kill-ring-save (click) "Copy the region between point and the mouse click in the kill ring. --------------040201010906030400020408 Content-Type: text/plain; name="ChangeLog.select-active-regions_lazybuf_r2" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.select-active-regions_lazybuf_r2" 2008-09-10 David De La Harpe Golden * select.el: allow x-set-selection to take a buffer object that is inspected on-demand to obtain selection data from its region. * simple.el: lazy implementation of select-active-regions. * mouse.el: fix time-ordering of deactivate-mark operations in mouse drag tracking. Avoid doubling of selection in mouse-yank-primary when select-active-regions is on. --------------040201010906030400020408-- From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: Stefan Monnier , 902@debbugs.gnu.org Resent-From: Stefan Monnier Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Thu, 11 Sep 2008 02:10:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122109847827684 (code B ref 902); Thu, 11 Sep 2008 02:10:04 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.8 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 11 Sep 2008 02:01:18 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.teksavvy.com [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8B21Dhm027588 for <902@emacsbugs.donarmstrong.com>; Wed, 10 Sep 2008 19:01:14 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjkFAH8YyEhFxIqP/2dsb2JhbACBZbcEgWSBBg X-IronPort-AV: E=Sophos;i="4.32,375,1217822400"; d="scan'208";a="26643757" Received: from 69-196-138-143.dsl.teksavvy.com (HELO ceviche.home) ([69.196.138.143]) by ironport2-out.teksavvy.com with ESMTP; 10 Sep 2008 22:01:07 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 9DC33B4062; Wed, 10 Sep 2008 22:01:07 -0400 (EDT) From: Stefan Monnier To: David De La Harpe Golden Cc: 902@debbugs.gnu.org Message-ID: References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> <48C6CC6F.5090100@harpegolden.net> <48C83FF3.1060507@harpegolden.net> Date: Wed, 10 Sep 2008 22:01:07 -0400 In-Reply-To: <48C83FF3.1060507@harpegolden.net> (David De La Harpe Golden's message of "Wed, 10 Sep 2008 22:45:23 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii >> Again, since this code is present at several places, move it into its >> own function. Basically this function could turn the buffer value into >> a "cons of markers" value, so you can use it everywhere and reuse the >> code that handles a cons of markers. > Okay, sorry, I seem to have an irrational fear of introducing named > functions in elisp (possibly due to lack of CL packages I'm used to for > hiding). Attached. You can use the double dash convention (i.e. "--") to indicate that this function is "for internal use". Stefan > Index: lisp/select.el > =================================================================== > RCS file: /sources/emacs/emacs/lisp/select.el,v > retrieving revision 1.44 > diff -U 8 -r1.44 select.el > --- lisp/select.el 12 Jun 2008 03:56:16 -0000 1.44 > +++ lisp/select.el 10 Sep 2008 20:37:34 -0000 > @@ -123,16 +123,20 @@ > integer (or a cons of two integers or list of two integers). > The selection may also be a cons of two markers pointing to the same buffer, > or an overlay. In these cases, the selection is considered to be the text > between the markers *at whatever time the selection is examined*. > Thus, editing done in the buffer after you specify the selection > can alter the effective value of the selection. > +The selection may also be a buffer object. In that case, the selection is > +considered to be the region between the mark and point, if any, in that > +buffer, *at whatever time the selection is examined*. > + > The data may also be a vector of valid non-vector selection values. > The return value is DATA. > Interactively, this command sets the primary selection. Without > prefix argument, it reads the selection in the minibuffer. With > prefix argument, it uses the text of the region as the selection value ." > (interactive (if (not current-prefix-arg) > @@ -170,17 +174,18 @@ > (and (consp data) > (markerp (car data)) > (markerp (cdr data)) > (marker-buffer (car data)) > (marker-buffer (cdr data)) > (eq (marker-buffer (car data)) > (marker-buffer (cdr data))) > (buffer-name (marker-buffer (car data))) > - (buffer-name (marker-buffer (cdr data)))))) > + (buffer-name (marker-buffer (cdr data)))) > + (bufferp data))) > > ;;; Cut Buffer support > (declare-function x-get-cut-buffer-internal "xselect.c") > (defun x-get-cut-buffer (&optional which-one) > "Returns the value of one of the 8 X server cut-buffers. > Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0. > @@ -206,18 +211,25 @@ > (x-rotate-cut-buffers-internal 1)) > (x-store-cut-buffer-internal 'CUT_BUFFER0 string)) > > ;;; Functions to convert the selection into various other selection types. > ;;; Every selection type that Emacs handles is implemented this way, except > ;;; for TIMESTAMP, which is a special case. > +(defun xselect-buffer-region-markers-cons (buffer) > + "Helper function for xselect-convert functions given buffers. (Internal)" > + (with-current-buffer buffer > + (cons (mark-marker) (point-marker)))) > + > (defun xselect-convert-to-string (selection type value) > (let (str coding) > + (when (bufferp value) > + (setq value (xselect-buffer-region-markers-cons value))) > ;; Get the actual string from VALUE. > (cond ((stringp value) > (setq str value)) > ((overlayp value) > (save-excursion > (or (buffer-name (overlay-buffer value)) > (error "selection is in a killed buffer")) > @@ -291,16 +303,18 @@ > (error "Unknow selection type: %S" type)) > ))) > (setq next-selection-coding-system nil) > (cons type str)))) > (defun xselect-convert-to-length (selection type value) > + (when (bufferp value) > + (setq value (xselect-buffer-region-markers-cons value))) > (let ((value > (cond ((stringp value) > (length value)) > ((overlayp value) > (abs (- (overlay-end value) (overlay-start value)))) > ((and (consp value) > (markerp (car value)) > (markerp (cdr value))) > @@ -338,35 +352,41 @@ > (cond ((overlayp value) > (buffer-file-name (or (overlay-buffer value) > (error "selection is in a killed buffer")))) > ((and (consp value) > (markerp (car value)) > (markerp (cdr value))) > (buffer-file-name (or (marker-buffer (car value)) > (error "selection is in a killed buffer")))) > + ((bufferp value) > + (buffer-file-name value)) > (t nil))) > (defun xselect-convert-to-charpos (selection type value) > + (when (bufferp value) > + (setq value (xselect-buffer-region-markers-cons value))) > (let (a b tmp) > (cond ((cond ((overlayp value) > (setq a (overlay-start value) > b (overlay-end value))) > ((and (consp value) > (markerp (car value)) > (markerp (cdr value))) > (setq a (car value) > b (cdr value)))) > (setq a (1- a) b (1- b)) ; zero-based > (if (< b a) (setq tmp a a b b tmp)) > (cons 'SPAN > (vector (cons (ash a -16) (logand a 65535)) > (cons (ash b -16) (logand b 65535)))))))) > (defun xselect-convert-to-lineno (selection type value) > + (when (bufferp value) > + (setq value (xselect-buffer-region-markers-cons value))) > (let (a b buf tmp) > (cond ((cond ((and (consp value) > (markerp (car value)) > (markerp (cdr value))) > (setq a (marker-position (car value)) > b (marker-position (cdr value)) > buf (marker-buffer (car value)))) > ((overlayp value) > @@ -379,16 +399,18 @@ > (setq a (count-lines 1 a) > b (count-lines 1 b))) > (if (< b a) (setq tmp a a b b tmp)) > (cons 'SPAN > (vector (cons (ash a -16) (logand a 65535)) > (cons (ash b -16) (logand b 65535)))))))) > (defun xselect-convert-to-colno (selection type value) > + (when (bufferp value) > + (setq value (xselect-buffer-region-markers-cons value))) > (let (a b buf tmp) > (cond ((cond ((and (consp value) > (markerp (car value)) > (markerp (cdr value))) > (setq a (car value) > b (cdr value) > buf (marker-buffer a))) > ((overlayp value) > Index: lisp/simple.el > =================================================================== > RCS file: /sources/emacs/emacs/lisp/simple.el,v > retrieving revision 1.945 > diff -U 8 -r1.945 simple.el > --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 > +++ lisp/simple.el 10 Sep 2008 20:37:38 -0000 > @@ -3416,44 +3416,55 @@ > is active, and returns an integer or nil in the usual way. > 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. > + > +In conjunction with this, to ape some other X11 apps, you might want to: > +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, > +set `x-select-enable-clipboard' to non-nil and set `mouse-drag-copy-region' > +to nil." > + :type 'boolean > + :group 'killing > + :version "23.1") > + > ;; Many places set mark-active directly, and several of them failed to also > ;; run deactivate-mark-hook. This shorthand should simplify. > (defsubst deactivate-mark () > "Deactivate the mark by setting `mark-active' to nil. > \(That makes a difference only in Transient Mark mode.) > Also runs the hook `deactivate-mark-hook'." > (when transient-mark-mode > + (and mark-active select-active-regions > + (x-selection-owner-p nil) > + (x-set-selection nil (x-get-selection nil))) > (if (or (eq transient-mark-mode 'lambda) > (and (eq (car-safe transient-mark-mode) 'only) > (null (cdr transient-mark-mode)))) > (setq transient-mark-mode nil) > (if (eq (car-safe transient-mark-mode) 'only) > (setq transient-mark-mode (cdr transient-mark-mode))) > (setq mark-active nil) > (run-hooks 'deactivate-mark-hook)))) > (defun activate-mark () > "Activate the mark." > (when (mark t) > (setq mark-active t) > (unless transient-mark-mode > - (setq transient-mark-mode 'lambda)))) > + (setq transient-mark-mode 'lambda)) > + (when select-active-regions > + (x-set-selection nil (current-buffer))))) > -(defcustom select-active-regions nil > - "If non-nil, an active region automatically becomes the window selection." > - :type 'boolean > - :group 'killing > - :version "23.1") > (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. > @@ -3466,20 +3477,22 @@ > store it in a Lisp variable. Example: > (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." > (if pos > (progn > (setq mark-active t) > (run-hooks 'activate-mark-hook) > - (and select-active-regions > - (x-set-selection > - nil (buffer-substring (region-beginning) (region-end)))) > - (set-marker (mark-marker) pos (current-buffer))) > + (set-marker (mark-marker) pos (current-buffer)) > + (when select-active-regions > + (x-set-selection nil (current-buffer)))) > + (and mark-active select-active-regions > + (x-selection-owner-p nil) > + (x-set-selection nil (x-get-selection nil))) > ;; 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. > (setq mark-active nil) > (run-hooks 'deactivate-mark-hook) > (set-marker (mark-marker) nil))) > (defcustom use-empty-active-region nil > Index: lisp/mouse.el > =================================================================== > RCS file: /sources/emacs/emacs/lisp/mouse.el,v > retrieving revision 1.347 > diff -U 8 -r1.347 mouse.el > --- lisp/mouse.el 11 Aug 2008 01:23:05 -0000 1.347 > +++ lisp/mouse.el 10 Sep 2008 20:37:39 -0000 > @@ -906,16 +906,17 @@ > (defun mouse-drag-track (start-event &optional > do-mouse-drag-region-post-process) > "Track mouse drags by highlighting area between point and cursor. > The region will be defined with mark and point, and the overlay > will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS > should only be used by mouse-drag-region." > (mouse-minibuffer-check start-event) > (setq mouse-selection-click-count-buffer (current-buffer)) > + (deactivate-mark) > (let* ((original-window (selected-window)) > ;; We've recorded what we needed from the current buffer and > ;; window, now let's jump to the place of the event, where things > ;; are happening. > (_ (mouse-set-point start-event)) > (echo-keystrokes 0) > (start-posn (event-start start-event)) > (start-point (posn-point start-posn)) > @@ -950,17 +951,16 @@ > (if (< (point) start-point) > (goto-char start-point)) > (setq start-point (point)) > (if remap-double-click ;; Don't expand mouse overlay in links > (setq click-count 0)) > (mouse-move-drag-overlay mouse-drag-overlay start-point start-point > click-count) > (overlay-put mouse-drag-overlay 'window start-window) > - (deactivate-mark) > (let (event end end-point last-end-point) > (track-mouse > (while (progn > (setq event (read-event)) > (or (mouse-movement-p event) > (memq (car-safe event) '(switch-frame select-window)))) > (if (memq (car-safe event) '(switch-frame select-window)) > nil > @@ -1352,16 +1352,19 @@ > (defun mouse-yank-primary (click) > "Insert the primary selection at the position clicked on. > Move point to the end of the inserted text. > If `mouse-yank-at-point' is non-nil, insert at point > regardless of where you click." > (interactive "e") > ;; Give temporary modes such as isearch a chance to turn off. > (run-hooks 'mouse-leave-buffer-hook) > + ;; if region is active and _is_ primary (due to select-active-regions) > + ;; avoid doubling upon repeated consecutive clicks. > + (and select-active-regions (deactivate-mark)) > (or mouse-yank-at-point (mouse-set-point click)) > (let ((primary (x-get-selection 'PRIMARY))) > (if primary > (insert (x-get-selection 'PRIMARY)) > (error "No primary selection")))) > (defun mouse-kill-ring-save (click) > "Copy the region between point and the mouse click in the kill ring. > 2008-09-10 David De La Harpe Golden > * select.el: allow x-set-selection to take a buffer object that is > inspected on-demand to obtain selection data from its region. > * simple.el: lazy implementation of select-active-regions. > * mouse.el: fix time-ordering of deactivate-mark operations in > mouse drag tracking. Avoid doubling of selection in > mouse-yank-primary when select-active-regions is on. From unknown Sat Jun 21 03:21:52 2025 X-Loop: don@donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Thu, 11 Sep 2008 02:50:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.12211008329612 (code B ref 902); Thu, 11 Sep 2008 02:50:04 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.5 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MIXEDBDN,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 902) by emacsbugs.donarmstrong.com; 11 Sep 2008 02:40:32 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8B2eRZ0009351 for <902@emacsbugs.donarmstrong.com>; Wed, 10 Sep 2008 19:40:28 -0700 Received: from golden1.harpegolden.net (unknown [86.45.15.116]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id E2E0981DE; Thu, 11 Sep 2008 03:40:25 +0100 (IST) Message-ID: <48C88516.9070203@harpegolden.net> Date: Thu, 11 Sep 2008 03:40:22 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: Stefan Monnier CC: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> <48C6CC6F.5090100@harpegolden.net> <48C83FF3.1060507@harpegolden.net> In-Reply-To: X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------020203020301050301020207" This is a multi-part message in MIME format. --------------020203020301050301020207 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit > > You can use the double dash convention (i.e. "--") to indicate > that this function is "for internal use". > Sorry, my bad, wasn't aware of that convention. Though maybe it should be added to Appendix D of the manual (doc/lispref/tips.texi)? [revision using -- attached] --------------020203020301050301020207 Content-Type: text/x-patch; name="select-active-regions_lazybuf_r3.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions_lazybuf_r3.diff" Index: lisp/select.el =================================================================== RCS file: /sources/emacs/emacs/lisp/select.el,v retrieving revision 1.44 diff -U 8 -r1.44 select.el --- lisp/select.el 12 Jun 2008 03:56:16 -0000 1.44 +++ lisp/select.el 11 Sep 2008 02:19:45 -0000 @@ -123,16 +123,20 @@ integer (or a cons of two integers or list of two integers). The selection may also be a cons of two markers pointing to the same buffer, or an overlay. In these cases, the selection is considered to be the text between the markers *at whatever time the selection is examined*. Thus, editing done in the buffer after you specify the selection can alter the effective value of the selection. +The selection may also be a buffer object. In that case, the selection is +considered to be the region between the mark and point, if any, in that +buffer, *at whatever time the selection is examined*. + The data may also be a vector of valid non-vector selection values. The return value is DATA. Interactively, this command sets the primary selection. Without prefix argument, it reads the selection in the minibuffer. With prefix argument, it uses the text of the region as the selection value ." (interactive (if (not current-prefix-arg) @@ -170,17 +174,18 @@ (and (consp data) (markerp (car data)) (markerp (cdr data)) (marker-buffer (car data)) (marker-buffer (cdr data)) (eq (marker-buffer (car data)) (marker-buffer (cdr data))) (buffer-name (marker-buffer (car data))) - (buffer-name (marker-buffer (cdr data)))))) + (buffer-name (marker-buffer (cdr data)))) + (bufferp data))) ;;; Cut Buffer support (declare-function x-get-cut-buffer-internal "xselect.c") (defun x-get-cut-buffer (&optional which-one) "Returns the value of one of the 8 X server cut-buffers. Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0. @@ -206,18 +211,24 @@ (x-rotate-cut-buffers-internal 1)) (x-store-cut-buffer-internal 'CUT_BUFFER0 string)) ;;; Functions to convert the selection into various other selection types. ;;; Every selection type that Emacs handles is implemented this way, except ;;; for TIMESTAMP, which is a special case. +(defun xselect--buffer-region-markers-cons (buffer) + (with-current-buffer buffer + (cons (mark-marker) (point-marker)))) + (defun xselect-convert-to-string (selection type value) (let (str coding) + (when (bufferp value) + (setq value (xselect--buffer-region-markers-cons value))) ;; Get the actual string from VALUE. (cond ((stringp value) (setq str value)) ((overlayp value) (save-excursion (or (buffer-name (overlay-buffer value)) (error "selection is in a killed buffer")) @@ -291,16 +302,18 @@ (error "Unknow selection type: %S" type)) ))) (setq next-selection-coding-system nil) (cons type str)))) (defun xselect-convert-to-length (selection type value) + (when (bufferp value) + (setq value (xselect--buffer-region-markers-cons value))) (let ((value (cond ((stringp value) (length value)) ((overlayp value) (abs (- (overlay-end value) (overlay-start value)))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) @@ -338,35 +351,41 @@ (cond ((overlayp value) (buffer-file-name (or (overlay-buffer value) (error "selection is in a killed buffer")))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) (buffer-file-name (or (marker-buffer (car value)) (error "selection is in a killed buffer")))) + ((bufferp value) + (buffer-file-name value)) (t nil))) (defun xselect-convert-to-charpos (selection type value) + (when (bufferp value) + (setq value (xselect--buffer-region-markers-cons value))) (let (a b tmp) (cond ((cond ((overlayp value) (setq a (overlay-start value) b (overlay-end value))) ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (car value) b (cdr value)))) (setq a (1- a) b (1- b)) ; zero-based (if (< b a) (setq tmp a a b b tmp)) (cons 'SPAN (vector (cons (ash a -16) (logand a 65535)) (cons (ash b -16) (logand b 65535)))))))) (defun xselect-convert-to-lineno (selection type value) + (when (bufferp value) + (setq value (xselect--buffer-region-markers-cons value))) (let (a b buf tmp) (cond ((cond ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (marker-position (car value)) b (marker-position (cdr value)) buf (marker-buffer (car value)))) ((overlayp value) @@ -379,16 +398,18 @@ (setq a (count-lines 1 a) b (count-lines 1 b))) (if (< b a) (setq tmp a a b b tmp)) (cons 'SPAN (vector (cons (ash a -16) (logand a 65535)) (cons (ash b -16) (logand b 65535)))))))) (defun xselect-convert-to-colno (selection type value) + (when (bufferp value) + (setq value (xselect--buffer-region-markers-cons value))) (let (a b buf tmp) (cond ((cond ((and (consp value) (markerp (car value)) (markerp (cdr value))) (setq a (car value) b (cdr value) buf (marker-buffer a))) ((overlayp value) Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 11 Sep 2008 02:19:49 -0000 @@ -3416,44 +3416,55 @@ is active, and returns an integer or nil in the usual way. 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. + +In conjunction with this, to ape some other X11 apps, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil and set `mouse-drag-copy-region' +to nil." + :type 'boolean + :group 'killing + :version "23.1") + ;; Many places set mark-active directly, and several of them failed to also ;; run deactivate-mark-hook. This shorthand should simplify. (defsubst deactivate-mark () "Deactivate the mark by setting `mark-active' to nil. \(That makes a difference only in Transient Mark mode.) Also runs the hook `deactivate-mark-hook'." (when transient-mark-mode + (and mark-active select-active-regions + (x-selection-owner-p nil) + (x-set-selection nil (x-get-selection nil))) (if (or (eq transient-mark-mode 'lambda) (and (eq (car-safe transient-mark-mode) 'only) (null (cdr transient-mark-mode)))) (setq transient-mark-mode nil) (if (eq (car-safe transient-mark-mode) 'only) (setq transient-mark-mode (cdr transient-mark-mode))) (setq mark-active nil) (run-hooks 'deactivate-mark-hook)))) (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode - (setq transient-mark-mode 'lambda)))) + (setq transient-mark-mode 'lambda)) + (when select-active-regions + (x-set-selection nil (current-buffer))))) -(defcustom select-active-regions nil - "If non-nil, an active region automatically becomes the window selection." - :type 'boolean - :group 'killing - :version "23.1") (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. @@ -3466,20 +3477,22 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) - (set-marker (mark-marker) pos (current-buffer))) + (set-marker (mark-marker) pos (current-buffer)) + (when select-active-regions + (x-set-selection nil (current-buffer)))) + (and mark-active select-active-regions + (x-selection-owner-p nil) + (x-set-selection nil (x-get-selection nil))) ;; 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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) (defcustom use-empty-active-region nil Index: lisp/mouse.el =================================================================== RCS file: /sources/emacs/emacs/lisp/mouse.el,v retrieving revision 1.347 diff -U 8 -r1.347 mouse.el --- lisp/mouse.el 11 Aug 2008 01:23:05 -0000 1.347 +++ lisp/mouse.el 11 Sep 2008 02:19:50 -0000 @@ -906,16 +906,17 @@ (defun mouse-drag-track (start-event &optional do-mouse-drag-region-post-process) "Track mouse drags by highlighting area between point and cursor. The region will be defined with mark and point, and the overlay will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by mouse-drag-region." (mouse-minibuffer-check start-event) (setq mouse-selection-click-count-buffer (current-buffer)) + (deactivate-mark) (let* ((original-window (selected-window)) ;; We've recorded what we needed from the current buffer and ;; window, now let's jump to the place of the event, where things ;; are happening. (_ (mouse-set-point start-event)) (echo-keystrokes 0) (start-posn (event-start start-event)) (start-point (posn-point start-posn)) @@ -950,17 +951,16 @@ (if (< (point) start-point) (goto-char start-point)) (setq start-point (point)) (if remap-double-click ;; Don't expand mouse overlay in links (setq click-count 0)) (mouse-move-drag-overlay mouse-drag-overlay start-point start-point click-count) (overlay-put mouse-drag-overlay 'window start-window) - (deactivate-mark) (let (event end end-point last-end-point) (track-mouse (while (progn (setq event (read-event)) (or (mouse-movement-p event) (memq (car-safe event) '(switch-frame select-window)))) (if (memq (car-safe event) '(switch-frame select-window)) nil @@ -1352,16 +1352,19 @@ (defun mouse-yank-primary (click) "Insert the primary selection at the position clicked on. Move point to the end of the inserted text. If `mouse-yank-at-point' is non-nil, insert at point regardless of where you click." (interactive "e") ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) + ;; if region is active and _is_ primary (due to select-active-regions) + ;; avoid doubling upon repeated consecutive clicks. + (and select-active-regions (deactivate-mark)) (or mouse-yank-at-point (mouse-set-point click)) (let ((primary (x-get-selection 'PRIMARY))) (if primary (insert (x-get-selection 'PRIMARY)) (error "No primary selection")))) (defun mouse-kill-ring-save (click) "Copy the region between point and the mouse click in the kill ring. --------------020203020301050301020207 Content-Type: text/plain; name="ChangeLog.select-active-regions_lazybuf_r3" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.select-active-regions_lazybuf_r3" 2008-09-11 David De La Harpe Golden * select.el: allow x-set-selection to take a buffer object that is inspected on-demand to obtain selection data from its region. * simple.el: lazy implementation of select-active-regions. * mouse.el: fix time-ordering of deactivate-mark operations in mouse drag tracking. Avoid doubling of selection in mouse-yank-primary when select-active-regions is on. --------------020203020301050301020207-- From unknown Sat Jun 21 03:21:52 2025 X-Loop: owner@emacsbugs.donarmstrong.com Subject: bug#902: select-active-regions only half-working Reply-To: David De La Harpe Golden , 902@debbugs.gnu.org Resent-From: David De La Harpe Golden Resent-To: bug-submit-list@lists.donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sun, 25 Jan 2009 23:50:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-Emacs-PR-Message: followup 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.123292705424944 (code B ref 902); Sun, 25 Jan 2009 23:50:03 +0000 Received: (at 902) by emacsbugs.donarmstrong.com; 25 Jan 2009 23:44:14 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-1.9 required=4.0 tests=FOURLA,HAS_BUG_NUMBER, MIXEDBDN autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id n0PNiCml024938 for <902@emacsbugs.donarmstrong.com>; Sun, 25 Jan 2009 15:44:13 -0800 Received: from [87.198.47.25] (87-198-47-25.ptr.magnet.ie [87.198.47.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 353748279 for <902@emacsbugs.donarmstrong.com>; Sun, 25 Jan 2009 23:44:11 +0000 (GMT) Message-ID: <497CF945.5090203@harpegolden.net> Date: Sun, 25 Jan 2009 23:44:05 +0000 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: 902@debbugs.gnu.org References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> <48C6CC6F.5090100@harpegolden.net> <48C83FF3.1060507@harpegolden.net> In-Reply-To: Content-Type: multipart/mixed; boundary="------------080203030001060706090308" This is a multi-part message in MIME format. --------------080203030001060706090308 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Tiny update to apply to current cvs head without large fuzz, functionally unchanged. Not sure it's handling 100% of cases - maybe it should be copying and "holding" as a string the selection before a command runs, and resetting it to the buffer object only if the mark hasn't been deactivated during the run of the command. Otherwise there may be some odd situations where the primary selection doesn't reflect the last _user visible_ highlight on screen, which is surprising. OTOH, that sounds more complex, and such cases don't seem to arise much (or at all) in practice - at least I haven't noticed them. --------------080203030001060706090308 Content-Type: application/x-gzip; name="select-active-regions_lazybuf_r4.diff.gz" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="select-active-regions_lazybuf_r4.diff.gz" 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 R54ipZj2b2VgmHPVLQAA --------------080203030001060706090308-- From unknown Sat Jun 21 03:21:52 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: owner@emacsbugs.donarmstrong.com From: help-debbugs@gnu.org (Emacs bug Tracking System) To: David De La Harpe Golden Subject: bug#902 closed by Chong Yidong (Re: select-active-regions only half-working) Message-ID: References: <878wiqivfr.fsf@stupidchicken.com> <48C21AD8.1060505@harpegolden.net> X-Emacs-PR-Message: they-closed 902 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: patch Reply-To: 902@debbugs.gnu.org Date: Wed, 15 Jul 2009 01:40:05 +0000 Content-Type: multipart/mixed; boundary="----------=_1247622005-26855-1" This is a multi-part message in MIME format... ------------=_1247622005-26855-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is an automatic notification regarding your bug report which was filed against the emacs package: #902: select-active-regions only half-working It has been closed by Chong Yidong . Their explanation is attached below along with your original report. If this explanation is unsatisfactory and you have not received a better one in a separate message then please contact Chong Yidong by replying to this email. --=20 902: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D902 Emacs Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1247622005-26855-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 902-done) by emacsbugs.donarmstrong.com; 15 Jul 2009 01:31:33 +0000 X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02 (2008-06-10) on rzlab.ucr.edu X-Spam-Level: X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. X-Spam-Status: No, score=-0.4 required=4.0 tests=AWL,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02 Received: from pantheon-po30.its.yale.edu (pantheon-po30.its.yale.edu [130.132.50.4]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n6F1VR7T025994 for <902-done@emacsbugs.donarmstrong.com>; Tue, 14 Jul 2009 18:31:28 -0700 Received: from furry (dhcp128036014244.central.yale.edu [128.36.14.244]) (authenticated bits=0) by pantheon-po30.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id n6F1V59U020189 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 14 Jul 2009 21:31:05 -0400 Received: by furry (Postfix, from userid 1000) id 94D53C09B; Tue, 14 Jul 2009 21:31:04 -0400 (EDT) From: Chong Yidong To: David De La Harpe Golden Cc: 902-done@debbugs.gnu.org Subject: Re: select-active-regions only half-working Date: Tue, 14 Jul 2009 21:31:04 -0400 Message-ID: <878wiqivfr.fsf@stupidchicken.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) Hi David, I've checked a revamped version of your patch into the trunk. Thanks very much for figuring out the details for making this work. ------------=_1247622005-26855-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit >From david@harpegolden.net Fri Sep 5 22:53:40 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.8 required=4.0 tests=AWL,BAYES_00,FVGT_m_MULTI_ODD, HAS_PACKAGE,MIXEDBDN,MURPHY_DRUGS_REL8,SPF_HELO_PASS autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 6 Sep 2008 05:53:40 +0000 Received: from harpegolden.net (harpegolden.net [65.99.215.13]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m865rbGu025975 for ; Fri, 5 Sep 2008 22:53:38 -0700 Received: from golden1.harpegolden.net (unknown [86.45.10.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id 1A01F81DE for ; Sat, 6 Sep 2008 06:53:35 +0100 (IST) Message-ID: <48C21AD8.1060505@harpegolden.net> Date: Sat, 06 Sep 2008 06:53:28 +0100 From: David De La Harpe Golden User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: submit@debbugs.gnu.org Subject: select-active-regions only half-working X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------060103000303040901090207" This is a multi-part message in MIME format. --------------060103000303040901090207 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Package: emacs Version: 23.0.60 Severity: normal Tags: patch The select-active-regions in-tree does not work in all cases - it works when the region is changed by moving the mark but not when it is changed by certain other means e.g. moving the point with the keyboard. (Workaround: C-x C-x C-x C-x ...). There were a couple of approaches tried a while back (see emacs-devel "Improved X Selections" thread). The idle timer seemed to work best in practice, despite (or because of) "coarse graining" i.e. a bunch of small region changes in a row don't reupdate the selection for each change, only kicks in when emacs has idled. Attached patch is a simple idle-timer based implementation. Concerns here may also apply to the activate-mark-hook (which states in its documentation that it is rerun when region changes). Having that work similarly with the same method would probably mean that active region timer would have to be enabled whenever the mark is active, not just when select-active-regions is on. --------------060103000303040901090207 Content-Type: text/x-patch; name="select-active-regions-by-idle-timer.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="select-active-regions-by-idle-timer.diff" Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.945 diff -U 8 -r1.945 simple.el --- lisp/simple.el 15 Aug 2008 00:30:44 -0000 1.945 +++ lisp/simple.el 6 Sep 2008 05:41:14 -0000 @@ -3439,18 +3439,46 @@ (defun activate-mark () "Activate the mark." (when (mark t) (setq mark-active t) (unless transient-mark-mode (setq transient-mark-mode 'lambda)))) +(defvar select-active-regions-timer nil) + +(defvar select-active-regions-last-region-hash nil) + +(defun select-active-regions-maybe-set-selection () + "Implements `select-active-regions', called from idle timer +`select-active-regions-timer'" + (and select-active-regions + (region-active-p) + (> (region-end) (region-beginning)) + (if (or (not select-active-regions-last-region-hash) + (x-selection-owner-p nil)) + (let ((region-hash + (md5 (current-buffer) (region-beginning) + (region-end) nil t))) + (unless (string-equal region-hash + select-active-regions-last-region-hash) + (x-set-selection + nil (buffer-substring (region-beginning) (region-end))) + (setq select-active-regions-last-region-hash + region-hash))) + (setq select-active-regions-last-region-hash 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. + +In conjunction with this, you might want to: +rebind mouse-2 to `mouse-yank-primary', set `x-select-enable-primary' to nil, +set `x-select-enable-clipboard' to non-nil, set `mouse-drag-copy-region' +to nil, and turn on `transient-mark-mode'." :type 'boolean :group 'killing :version "23.1") (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 @@ -3466,19 +3494,26 @@ store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (if pos (progn (setq mark-active t) (run-hooks 'activate-mark-hook) - (and select-active-regions - (x-set-selection - nil (buffer-substring (region-beginning) (region-end)))) + (if select-active-regions + (progn + (unless select-active-regions-timer + (setq select-active-regions-timer + (run-with-idle-timer + 0.1 t 'select-active-regions-maybe-set-selection))) + (select-active-regions-maybe-set-selection)) + (when select-active-regions-timer + (cancel-timer select-active-regions-timer) + (setq select-active-regions-timer nil))) (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. (setq mark-active nil) (run-hooks 'deactivate-mark-hook) (set-marker (mark-marker) nil))) --------------060103000303040901090207 Content-Type: text/plain; name="ChangeLog.select-active-regions-by-idle-timer" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ChangeLog.select-active-regions-by-idle-timer" 2008-09-06 David De La Harpe Golden * simple.el: idle-timer implementation of select-active-regions --------------060103000303040901090207-- ------------=_1247622005-26855-1--