bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#10022: 24.0.91; `isearch-mouse-2' relies on `x-get-selection' - NG f


From: Stefan Monnier
Subject: bug#10022: 24.0.91; `isearch-mouse-2' relies on `x-get-selection' - NG for Windows etc.
Date: Fri, 18 Nov 2011 12:30:18 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux)

> Because of this global binding, I need to change the `isearch-mode-map'
> binding of `down-mouse-2' to `ignore'.  Dunno whether a binding of
> `ignore' makes better sense for vanilla Emacs here too (e.g., in case
> someone binds `down-mouse-2' globally).

To the extent that isearch only binds mouse-2 in the minibuffer (yes,
it technically also binds it in the main buffer, but to a command that
just delegates to the normal binding), I don't think down-mouse-2 should
default to `ignore', except maybe in the minibuffer.

> That means that `isearch-mouse-2' barfs when it calls
> `isearch-yank-selection'.  That function tries to yank the string
> returned by `x-get-selection', but that function returns nil, not a
> string.  The PRIMARY selection is not set, at least in my context.
> This function apparently depend ons it being set.  Seems like a
> bug, to me.

AFAIK it's called "isearch-yank-x-selection", so it really doesn't seem
like a bug for it to fail when there is no GUI selection (yes, the
choice of "x" to mean "GUI" is unfortunate, but as you know it's
a widespread problem in Emacs).

> (when (and transient-mark-mode (/= (region-beginning) (region-end)))
>   (x-set-selection 'PRIMARY (buffer-substring-no-properties
>                              (region-beginning) (region-end)))
>   (deactivate-mark)
>   (isearch-yank-x-selection))

That presumes the region was meant as a "selection".  I don't see why
isearch should make such an assumption.

> Consider this only an FYI.  I suspect there is a problem, and that the
> `isearch-mouse-2' code should not depend on the PRIMARY selection being
> set, but you decide.

IIUC the intention is for it to perform a task similar to `yank', so it
needs to take the string from some kind of GUI selection, or from the
kill-ring, but taking it straight from the region seems a bit much.

> In case it helps, digging into this more shows that setting the X selection
> explicitly is necessary for the code to work also with older Emacs versions.
> That is not necessary for Emacs 24.

Aha!

> (defun isearch-mouse-2 (click)
>   "..."
>   (interactive "e")
>   (if (not isearchp-mouse-2-flag)
>       (let ((win  (posn-window (event-start click)))
>             (overriding-terminal-local-map  nil)
>             (binding
>              (key-binding (this-command-keys-vector) t)))
>         (if (and (window-minibuffer-p win)
>                  (not (minibuffer-window-active-p win))) ; In echo area
>             (isearch-yank-x-selection)
>           (when (functionp binding) (call-interactively binding))))
>     (when (/= (region-beginning) (region-end))
>       (let ((select-active-regions  t))
>         (deactivate-mark)
>         (isearch-yank-x-selection)))))

> The binding of `select-active-region' is needed, however.
> Without that (and with a customized setting of nil), `get-x-selection'
> returns nil - the problem I mentioned earlier.

But that overrides an explicit request from the user (in her .emacs) to
not automatically consider the region as a selection.
So, while it might make sense when coupled with a new option such as
isearchp-mouse-2-flag, I don't see what Emacs-24.1 could do to help.


        Stefan





reply via email to

[Prev in Thread] Current Thread [Next in Thread]