all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kai Grossjohann <kai@emptydomain.de>
To: help-gnu-emacs@gnu.org
Subject: Re: How can I be notified whenever point of a buffer changed?
Date: Fri, 13 Apr 2007 12:22:19 +0200	[thread overview]
Message-ID: <86lkgwa810.fsf@ketchup.de.uu.net> (raw)
In-Reply-To: 1176430900.460559.246910@o5g2000hsb.googlegroups.com

"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	other threads:[~2007-04-13 10:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-12  4:00 How can I be notified whenever point of a buffer changed? Ender
2007-04-12  8:09 ` Kai Grossjohann
     [not found] ` <mailman.1978.1176365678.7795.help-gnu-emacs@gnu.org>
2007-04-13  2:21   ` Ender
2007-04-13 10:22     ` Kai Grossjohann [this message]
2007-04-13 10:25 ` Kai Grossjohann
     [not found] ` <mailman.2027.1176460480.7795.help-gnu-emacs@gnu.org>
2007-04-17  7:39   ` Ender

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86lkgwa810.fsf@ketchup.de.uu.net \
    --to=kai@emptydomain.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.