GNU bug report logs - #902
select-active-regions only half-working

Previous Next

Package: emacs;

Reported by: David De La Harpe Golden <david <at> harpegolden.net>

Date: Sat, 6 Sep 2008 06:00:02 UTC

Severity: normal

Tags: patch

Found in version 23.0.60

Done: Chong Yidong <cyd <at> stupidchicken.com>

Bug is archived. No further changes may be made.

Full log


Message #50 received at 902 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: David De La Harpe Golden <david <at> harpegolden.net>
Cc: 902 <at> debbugs.gnu.org
Subject: Re: bug#902: select-active-regions only half-working
Date: Tue, 09 Sep 2008 10:50:05 -0400
>> 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.

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.
 
> +	  ((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.
 
> +    (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").
 

        Stefan




This bug report was last modified 15 years and 187 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.