From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#902: select-active-regions only half-working Date: Tue, 09 Sep 2008 10:50:05 -0400 Message-ID: References: <48C21AD8.1060505@harpegolden.net> <48C2E68C.6060909@harpegolden.net> <48C43937.7030702@harpegolden.net> <48C5C661.4090201@harpegolden.net> Reply-To: Stefan Monnier , 902@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1220973205 7372 80.91.229.12 (9 Sep 2008 15:13:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Sep 2008 15:13:25 +0000 (UTC) Cc: 902@emacsbugs.donarmstrong.com To: David De La Harpe Golden Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Sep 09 17:14:17 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kd4qK-0007cZ-MW for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Sep 2008 17:09:25 +0200 Original-Received: from localhost ([127.0.0.1]:38758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kd4pK-0007Ft-LT for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Sep 2008 11:08:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kd4od-0006x8-Rz for bug-gnu-emacs@gnu.org; Tue, 09 Sep 2008 11:07:40 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kd4oa-0006va-UU for bug-gnu-emacs@gnu.org; Tue, 09 Sep 2008 11:07:38 -0400 Original-Received: from [199.232.76.173] (port=47632 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kd4oa-0006vA-6R for bug-gnu-emacs@gnu.org; Tue, 09 Sep 2008 11:07:36 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:38432) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kd4oZ-0003sw-SG for bug-gnu-emacs@gnu.org; Tue, 09 Sep 2008 11:07:36 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m89F7WXM026917; Tue, 9 Sep 2008 08:07:33 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m89Et8M4021730; Tue, 9 Sep 2008 07:55:08 -0700 X-Loop: don@donarmstrong.com Resent-From: Stefan Monnier Resent-To: bug-submit-list@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 Original-Received: via spool by 902-submit@emacsbugs.donarmstrong.com id=B902.122097181520410 (code B ref 902); Tue, 09 Sep 2008 14:55:08 +0000 Original-Received: (at 902) by emacsbugs.donarmstrong.com; 9 Sep 2008 14:50:15 +0000 Original-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" Original-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 Original-Received: by pastel.home (Postfix, from userid 20848) id 32EF554279; Tue, 9 Sep 2008 10:50:05 -0400 (EDT) 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) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Tue, 09 Sep 2008 11:07:38 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:20396 Archived-At: >> 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