all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: David De La Harpe Golden <david@harpegolden.net>
Cc: 902@emacsbugs.donarmstrong.com
Subject: bug#902: select-active-regions only half-working
Date: Tue, 09 Sep 2008 10:50:05 -0400	[thread overview]
Message-ID: <jwv63p5gz5f.fsf-monnier+emacsbugreports@gnu.org> (raw)
In-Reply-To: <48C5C661.4090201@harpegolden.net> (David De La Harpe Golden's message of "Tue, 09 Sep 2008 01:42:09 +0100")

>> 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






  reply	other threads:[~2008-09-09 14:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <878wiqivfr.fsf@stupidchicken.com>
2008-09-06  5:53 ` bug#902: select-active-regions only half-working David De La Harpe Golden
     [not found]   ` <handler.902.B.122068042025981.ack@emacsbugs.donarmstrong.com>
2008-09-06 19:35     ` bug#902: Acknowledgement (select-active-regions only half-working) David De La Harpe Golden
2008-09-06 19:50   ` bug#902: select-active-regions only half-working Stefan Monnier
2008-09-06 20:22     ` David De La Harpe Golden
2008-09-07  3:53       ` Stefan Monnier
2008-09-07 20:27         ` David De La Harpe Golden
2008-09-07 21:20           ` Stefan Monnier
2008-09-09  0:42             ` David De La Harpe Golden
2008-09-09 14:50               ` Stefan Monnier [this message]
2008-09-09 19:20                 ` David De La Harpe Golden
2008-09-10 16:37                   ` Stefan Monnier
2008-09-10 21:45                     ` David De La Harpe Golden
2008-09-11  2:01                       ` Stefan Monnier
2008-09-11  2:40                         ` David De La Harpe Golden
2009-01-25 23:44                         ` David De La Harpe Golden
2009-07-15  1:40   ` bug#902: marked as done (select-active-regions only half-working) Emacs bug Tracking System

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=jwv63p5gz5f.fsf-monnier+emacsbugreports@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=902@emacsbugs.donarmstrong.com \
    --cc=david@harpegolden.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.