help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How can I be notified whenever point of a buffer changed?


From: Kai Grossjohann
Subject: Re: How can I be notified whenever point of a buffer changed?
Date: Fri, 13 Apr 2007 12:22:19 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.97 (gnu/linux)

"Ender" <oldcode@gmail.com> writes:

> (defun text-entered-hook (old-point new-point)
>   (save-current-buffer
>     (set-buffer (get-buffer-create "*scratch*"))
>     (insert "From " (number-to-string old-point) " to " (number-to-
> string new-point) "\n")))
>
> (setq default-text-properties '(point-left nil))
> (setq default-text-properties '(point-entered text-entered-hook))

The first line sets default-text-properties to a value, and the second
line sets it to a new value.  The second line overwrites the effect of
the first line.

Did you mean the following?

(setq default-text-properties 
      '(point-left nil
        point-entered text-entered-hook))

> After M-x eval-buffer,  I found two problem with the code:
>
> 1). Not all the point change will trigger text-entered-hook and I
> can't find any rule of which kind of point changing will trigger the
> hook. It confused me.

Only when the text property changes, then the hook is called.  So you
would have to have two functions, and set the text property of the
first, third, fifth, ... character in the buffer to the first
function, and the text property of the second, fourth, sixth,
... character in the buffer to the second function.

Ayee.

I think these text properties were not the right solution to your
original problem.  Let me go back and reread your original posting.

> 2). When the hook was triggered, it will be called twice. Yes I know
> why this happens (info node of point-left/point-entered explained
> clearly), but how can I fix it?

I'm afraid you'll have to write your function so that it is harmless
that it is called twice.


Kai






reply via email to

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