[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to execute code on cursor move
From: |
Suvayu Ali |
Subject: |
Re: How to execute code on cursor move |
Date: |
Sat, 13 Jul 2013 17:32:23 +0200 |
User-agent: |
Mutt/1.5.21 (2012-12-30) |
Hi Drew,
On Sat, Jul 13, 2013 at 06:26:24AM -0700, Drew Adams wrote:
> > > 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))))
>
I actually saw something very similar in Org mode source but didn't
quite follow everything, so I "simplified" it to what you see
above. :-p
Thank you very much for the pointer. Now I understand :).
Cheers,
--
Suvayu
Open source is the future. It sets us free.