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

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

How to handle mouse events


From: Tassilo Horn
Subject: How to handle mouse events
Date: Mon, 24 Apr 2006 12:23:27 +0200
User-agent: Gnus/5.110005 (No Gnus v0.5) Emacs/22.0.50 (gnu/linux)

Hi,

I wrote a simple dictionary with emacs bindings. One feature I want to
implemenet now is to open a tooltip with the translation of the word the
mouse is pointing at.

So far I wrote this code:

,----
| (defvar rdictcc-tooltip-mode nil
|   "Indicates wheather the rdictcc tooltip mode is active.")
| (nconc minor-mode-alist '((rdictcc-tooltip-mode " RDictCc")))
|
| (defun rdictcc-translate-word-under-mouse (event)
|   "Display translations of the word at the cursor in a tooltip."
|   (interactive "e")
|   (let ((word (save-window-excursion
|                 (save-excursion
|                   (mouse-set-point event)
|                   (current-word t t)))))
|     (message "Word is %s" word)
|     (tooltip-show (rdictcc-translate-word-to-string word))))
|
| (defun rdictcc-tooltip-mode (&optional arg)
|   "Display tooltips for the current word."
|   (interactive "P")
|   (require 'tooltip)
|   (let ((val (if arg
|                  (> (prefix-numeric-value arg) 0)
|                (not rdictcc-tooltip-mode))))
|     (make-local-variable 'rdictcc-tooltip-mode)
|     (setq rdictcc-tooltip-mode val)
|     (tooltip-mode 1)
|     (add-hook 'tooltip-hook 'rdictcc-translate-word-under-mouse t t)
|     (make-local-variable 'track-mouse)
|     (setq track-mouse val)))
`----

But there are no tooltips and it seems that I never enter
`rdictcc-translate-word-under-mouse', or at least "Word is <word>" is
never printed in the echo area.

If I enter below code in *scratch* buffer, I get a tooltip with the
translation.

,----[ in *scratch* ]
| (track-mouse
|   (rdictcc-translate-word-under-mouse (read-event)))
`----

Any help?

Bye,
Tassilo


reply via email to

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