emacs-devel
[Top][All Lists]
Advanced

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

RE: supporting mouse-entered, mouse-left


From: Drew Adams
Subject: RE: supporting mouse-entered, mouse-left
Date: Sat, 1 Aug 2009 00:26:46 -0700

>> 2. A way to know when the mouse is over any such text.
>> ...
>> A function on `post-command-hook' could perhaps check whether
>> the last event was a mouse event, and if so get the mouse position
>> and then the value of the property at that position.
>
> My question is #2, and your solution does not work.  Emacs does
> not send any notifications when the mouse moves unless track-mouse
> is on.

Right, for a mouseover you would need to use tracking (or write some C code, as
you mentioned). You seemed to say you could not use tracking (or perhaps did not
want to use it).

Using `post-command-hook' as I suggested is quite sufficient if you are willing
to click the spot to check instead of just mousing over it. This simple code
highlights all occurrences of the property when any such occurrence is clicked,
and unhighlights them all when you click anywhere else:

(defun foo (prop value &optional start end face type)
  (unless face (setq face  'highlight))
  (unless type (setq type  'overlay))
  (when (string-match
          "mouse"
          (format "%S" (event-basic-type last-command-event)))
    (let* ((estart  (event-start last-command-event))
           (pos     (posn-point estart)))
      (when (integer-or-marker-p pos)
        (save-excursion
          (with-current-buffer (window-buffer (posn-window estart))
            (if (eq (get-char-property pos prop) value)
                (hlt-highlight-property-with-value
                  prop (list value) start end face type)
              (hlt-unhighlight-region-for-face face start end))))))))

(defun foobar () (foo 'mouse-face 'highlight))
(add-hook 'post-command-hook 'foobar)

Try it in *Help* or Dired, for instance, to show/hide all links at once.

But if, as you now added, you do not really want to, as you said before, "light
up" all such occurrences, then just substitute your code to "squeak audibly,
like mice" for the hook function. Or tomorrow, if you want to send up balloons
instead, put your balloon machine on the hook. Or not.






reply via email to

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