all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* set-temporary-overlay-map doesn't work for me
@ 2013-11-27 21:37 Andrey Tykhonov
  2013-11-27 22:00 ` Drew Adams
  2013-11-27 22:26 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Andrey Tykhonov @ 2013-11-27 21:37 UTC (permalink / raw)
  To: help-gnu-emacs



Hi all,

I have two quite simple functions:

(defun my-temp ()
  (interactive)
  (set-temporary-overlay-map
   (let ((map (make-sparse-keymap)))
     (define-key map [mouse-1] 'my-mouse-down)
     map)))

(defun my-mouse-down ()
  (interactive)
  (message "Word is: %s " (thing-at-point 'word)))


I evaluate them, then M-x my-temp RET, then mouse click (left button) on
"interactive" world and I'm expecting to see "Word is "interactive""
message in the minibuffer. But no messages appear! I cannot figure out
why this code behaves in such way...

By the way I have tried (global-set-key [mouse-1] 'my-mouse-down) and
this works and I see the message. Also I've tried:

(define-key map (kbd "C-c C-c") 'my-mouse-down) and this code also works well.

But I need mouse click to be processed and to be processed only once!

What trouble with these two functions?

P.S.: Values of `overriding-terminal-local-map` and `overriding-local-map`
variables are nil.


Best regards,
Andrey



^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: set-temporary-overlay-map doesn't work for me
  2013-11-27 21:37 set-temporary-overlay-map doesn't work for me Andrey Tykhonov
@ 2013-11-27 22:00 ` Drew Adams
  2013-11-27 22:40   ` Andrey Tykhonov
  2013-11-27 22:48   ` Drew Adams
  2013-11-27 22:26 ` Stefan Monnier
  1 sibling, 2 replies; 5+ messages in thread
From: Drew Adams @ 2013-11-27 22:00 UTC (permalink / raw)
  To: Andrey Tykhonov, help-gnu-emacs

> (defun my-temp ()
>   (interactive)
>   (set-temporary-overlay-map
>    (let ((map (make-sparse-keymap)))
>      (define-key map [mouse-1] 'my-mouse-down)
>      map)))
> 
> (defun my-mouse-down ()
>   (interactive)
>   (message "Word is: %s " (thing-at-point 'word)))
> 
> I evaluate them, then M-x my-temp RET, then mouse click (left button) on
> "interactive" world and I'm expecting to see "Word is "interactive""
> message in the minibuffer. But no messages appear!

`my-temp' does not read your mouse click.  It binds the keymap, and
then it exits.  And then you click your mouse, with the binding no
longer in effect.

One approach would be to read an event inside your `my-temp', and
ignore it if not a mouse click.  To do something cleaner than that
we would need to see the overall context - what you really want to do.

But if this is all there is, then it seems you want to invoke a
command (why a command?) that reads an event, and if that event is a
mouse click then invoke `my-mouse-down'.  Or perhaps you want to
read events until you get a mouse click event...

Anyway, that's the problem.  Either describe what you really need
or work it out knowing what this problem is.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: set-temporary-overlay-map doesn't work for me
  2013-11-27 21:37 set-temporary-overlay-map doesn't work for me Andrey Tykhonov
  2013-11-27 22:00 ` Drew Adams
@ 2013-11-27 22:26 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2013-11-27 22:26 UTC (permalink / raw)
  To: help-gnu-emacs

> I have two quite simple functions:

> (defun my-temp ()
>   (interactive)
>   (set-temporary-overlay-map
>    (let ((map (make-sparse-keymap)))
>      (define-key map [mouse-1] 'my-mouse-down)
>      map)))

> (defun my-mouse-down ()
>   (interactive)
>   (message "Word is: %s " (thing-at-point 'word)))


> I evaluate them, then M-x my-temp RET, then mouse click (left button) on
> "interactive" world and I'm expecting to see "Word is "interactive""
> message in the minibuffer. But no messages appear! I cannot figure out
> why this code behaves in such way...

I think the problem is that clicking with your mouse will do two things:
`down-mouse-1' then `mouse-1' and the first will exit the temporary
overlay map.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: set-temporary-overlay-map doesn't work for me
  2013-11-27 22:00 ` Drew Adams
@ 2013-11-27 22:40   ` Andrey Tykhonov
  2013-11-27 22:48   ` Drew Adams
  1 sibling, 0 replies; 5+ messages in thread
From: Andrey Tykhonov @ 2013-11-27 22:40 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs


Drew Adams writes:

>> (defun my-temp ()
>>   (interactive)
>>   (set-temporary-overlay-map
>>    (let ((map (make-sparse-keymap)))
>>      (define-key map [mouse-1] 'my-mouse-down)
>>      map)))
>>
>> (defun my-mouse-down ()
>>   (interactive)
>>   (message "Word is: %s " (thing-at-point 'word)))
>>
>> I evaluate them, then M-x my-temp RET, then mouse click (left button) on
>> "interactive" world and I'm expecting to see "Word is "interactive""
>> message in the minibuffer. But no messages appear!
>
> `my-temp' does not read your mouse click.  It binds the keymap, and
> then it exits.  And then you click your mouse, with the binding no
> longer in effect.

I wonder: why (kbd "C-c C-c") binding (in case if place it instead of
[mouse-1]) still in effect even after `my-temp` exits?

I was expecting that [mouse-1] will be behaved in the same way.

> One approach would be to read an event inside your `my-temp', and
> ignore it if not a mouse click.  To do something cleaner than that
> we would need to see the overall context - what you really want to do.

Well, I'll try read an event!

Thank you a lot!


Best regards,
Andrey

>
> But if this is all there is, then it seems you want to invoke a
> command (why a command?) that reads an event, and if that event is a
> mouse click then invoke `my-mouse-down'.  Or perhaps you want to
> read events until you get a mouse click event...
>
> Anyway, that's the problem.  Either describe what you really need
> or work it out knowing what this problem is.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: set-temporary-overlay-map doesn't work for me
  2013-11-27 22:00 ` Drew Adams
  2013-11-27 22:40   ` Andrey Tykhonov
@ 2013-11-27 22:48   ` Drew Adams
  1 sibling, 0 replies; 5+ messages in thread
From: Drew Adams @ 2013-11-27 22:48 UTC (permalink / raw)
  To: Andrey Tykhonov, help-gnu-emacs

> I wonder: why (kbd "C-c C-c") binding (in case if place it instead of
> [mouse-1]) still in effect even after `my-temp` exits?
> I was expecting that [mouse-1] will be behaved in the same way.

No, please ignore my answer to the question - wrong.  I didn't even
notice the call to `set-temporary-overlay-map'.  Sounds like Stefan
is on the right track.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-11-27 22:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-27 21:37 set-temporary-overlay-map doesn't work for me Andrey Tykhonov
2013-11-27 22:00 ` Drew Adams
2013-11-27 22:40   ` Andrey Tykhonov
2013-11-27 22:48   ` Drew Adams
2013-11-27 22:26 ` Stefan Monnier

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.