* How to execute code on cursor move
@ 2013-07-13 10:39 Suvayu Ali
2013-07-13 11:03 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Suvayu Ali @ 2013-07-13 10:39 UTC (permalink / raw)
To: Emacs help
Hi,
I want to check a text property and display in the minibuffer depending
on context (in my case, on an org-link).
This is what I have so far (working):
(add-hook 'post-command-hook
(lambda()
(if (eq (get-text-property (point) 'face) 'org-link)
(display-message-or-buffer
(get-text-property (point) 'help-echo)))))
Is using the post-command-hook a good idea? Is there something better?
As you can see, I'm trying to get the link target; are there better ways
to do this?
Thanks for any ideas.
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to execute code on cursor move
2013-07-13 10:39 Suvayu Ali
@ 2013-07-13 11:03 ` Eli Zaretskii
2013-07-13 13:28 ` Suvayu Ali
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2013-07-13 11:03 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sat, 13 Jul 2013 12:39:03 +0200
> From: Suvayu Ali <fatkasuvayu+linux@gmail.com>
>
> I want to check a text property and display in the minibuffer depending
> on context (in my case, on an org-link).
>
> This is what I have so far (working):
>
> (add-hook 'post-command-hook
> (lambda()
> (if (eq (get-text-property (point) 'face) 'org-link)
> (display-message-or-buffer
> (get-text-property (point) 'help-echo)))))
>
> 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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: How to execute code on cursor move
[not found] ` <<83vc4e4t8a.fsf@gnu.org>
@ 2013-07-13 13:26 ` Drew Adams
2013-07-13 15:32 ` Suvayu Ali
0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2013-07-13 13:26 UTC (permalink / raw)
To: Eli Zaretskii, help-gnu-emacs
> > 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))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to execute code on cursor move
2013-07-13 11:03 ` Eli Zaretskii
@ 2013-07-13 13:28 ` Suvayu Ali
0 siblings, 0 replies; 5+ messages in thread
From: Suvayu Ali @ 2013-07-13 13:28 UTC (permalink / raw)
To: help-gnu-emacs
Hi Eli,
On Sat, Jul 13, 2013 at 02:03:33PM +0300, Eli Zaretskii wrote:
> > Date: Sat, 13 Jul 2013 12:39:03 +0200
> > From: Suvayu Ali <fatkasuvayu+linux@gmail.com>
> >
> > I want to check a text property and display in the minibuffer depending
> > on context (in my case, on an org-link).
[...chomp...chomp...chomp...]
> > Is using the post-command-hook a good idea?
>
> No, because it slows down Emacs's _every_ command.
Thank you, I had a feeling that is the case.
> > 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.
I have the following snippet based on what you say above:
----------8<--------------------8<----------
;; Text for testing
;; some text description some more
;; setup: add tooltip
(add-text-properties 34 45
'(help-echo "tooltip"))
;; test above setup: tooltip b/w 34-45
(get-text-property 40 'help-echo)
;; add special properties
(defun sa-echo-tooltip (old new)
(display-message-or-buffer (or (get-text-property new 'help-echo) "")))
(add-text-properties
34 45 '(point-left sa-echo-tooltip point-entered sa-echo-tooltip))
----------8<--------------------8<----------
Now to convert this to something workable I guess I would have to add
the point-left and point-entered properties to all org-links. I'm not
sure how I can do that, but I guess asking on the Org mode list will be
best.
Thanks a lot!
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to execute code on cursor move
2013-07-13 13:26 ` How to execute code on cursor move Drew Adams
@ 2013-07-13 15:32 ` Suvayu Ali
0 siblings, 0 replies; 5+ messages in thread
From: Suvayu Ali @ 2013-07-13 15:32 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-07-13 15:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <<20130713103903.GA11006@kuru.dyndns-at-home.com>
[not found] ` <<83vc4e4t8a.fsf@gnu.org>
2013-07-13 13:26 ` How to execute code on cursor move Drew Adams
2013-07-13 15:32 ` Suvayu Ali
2013-07-13 10:39 Suvayu Ali
2013-07-13 11:03 ` Eli Zaretskii
2013-07-13 13:28 ` Suvayu Ali
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).