[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: How to execute code on cursor move
From: |
Drew Adams |
Subject: |
RE: How to execute code on cursor move |
Date: |
Sat, 13 Jul 2013 06:26:24 -0700 (PDT) |
> > I want to check a text property and display in the minibuffer depending
> > on context (in my case, on an org-link).
> >
> > (add-hook 'post-command-hook
> > (lambda()
> > (if (eq (get-text-property (point) 'face) 'org-link)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Is using the post-command-hook a good idea?
>
> No, because it slows down Emacs's _every_ command.
>
> > Is there something better?
>
> There are the 'point-entered' and 'point-left' text properties. Make
> sure they cover the buffer positions where you want to display the
> message in the echo area, and the rest should be easy.
Remember too that the `face' property can be a cons of faces or face
attributes. So you might not want to test for `org-link' using only `eq'.
IOW, you might want something like this, to check for the presence of
face `org-link':
(let ((face (get-text-property (point) 'face)))
(or (eq 'org-link face)
(and (consp face) (memq 'org-link face))))