unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* hook into change of position?
@ 2007-06-09 15:47 troelskn
  2007-06-10 12:35 ` Daniel Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: troelskn @ 2007-06-09 15:47 UTC (permalink / raw)
  To: help-gnu-emacs

Hi

I'm trying to hack together some elisp, and I need to somehow hook a
function callback up to be called whenever the position changes. Is
there an obvious way to do that?

--
thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: hook into change of position?
  2007-06-09 15:47 hook into change of position? troelskn
@ 2007-06-10 12:35 ` Daniel Jensen
  2007-06-10 23:26   ` troelskn
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jensen @ 2007-06-10 12:35 UTC (permalink / raw)
  To: help-gnu-emacs

troelskn <troelskn@gmail.com> writes:

> I'm trying to hack together some elisp, and I need to somehow hook a
> function callback up to be called whenever the position changes. Is
> there an obvious way to do that?

Depending on what you're trying to do, there are different options.

With post-command-hook, you can do something after every user command.
You'll have to check how point changed.

You can use an idle timer. Same thing here.

Text properties point-left and point-entered can be used to do
something for specific areas in the buffer.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: hook into change of position?
  2007-06-10 12:35 ` Daniel Jensen
@ 2007-06-10 23:26   ` troelskn
  2007-06-11 13:38     ` Daniel Jensen
  0 siblings, 1 reply; 4+ messages in thread
From: troelskn @ 2007-06-10 23:26 UTC (permalink / raw)
  To: help-gnu-emacs

On Jun 10, 2:35 pm, dan...@bigwalter.net (Daniel Jensen) wrote:
> Depending on what you're trying to do, there are different options.
Thanks. After some experiments, I ended up writing wrappers explicitly
for the functions, which I need to extend. I can't help feeling, that
there is some smarter way of accomplishing this, though.

For example:
(defun my-end-of-line (&optional arg)
  ""
  (interactive "p")
  (setq mark-active nil)
  (end-of-line arg)
  (my-hook-function))

I'm not even sure, that the (optional) argument `arg` will be passed
on correctly to the wrapped function `end-of-line`

--
troels

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: hook into change of position?
  2007-06-10 23:26   ` troelskn
@ 2007-06-11 13:38     ` Daniel Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jensen @ 2007-06-11 13:38 UTC (permalink / raw)
  To: help-gnu-emacs

troelskn <troelskn@gmail.com> writes:

> Thanks. After some experiments, I ended up writing wrappers explicitly
> for the functions, which I need to extend. I can't help feeling, that
> there is some smarter way of accomplishing this, though.

It's not necessarily bad; many modes define their own movement commands.
You still haven't told exactly what you are doing, so I cannot tell.

> (defun my-end-of-line (&optional arg)
>   ""
>   (interactive "p")
>   (setq mark-active nil)
>   (end-of-line arg)
>   (my-hook-function))

Maybe this was only example code, but I'll point out anyway that it's in
bad style. Use descriptive names and write a documentation string, so
that one can at least guess what the function does.

> I'm not even sure, that the (optional) argument `arg` will be passed
> on correctly to the wrapped function `end-of-line`

What makes you think that? Did you try it?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-06-11 13:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-09 15:47 hook into change of position? troelskn
2007-06-10 12:35 ` Daniel Jensen
2007-06-10 23:26   ` troelskn
2007-06-11 13:38     ` Daniel Jensen

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).