From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kai Grossjohann Newsgroups: gmane.emacs.help Subject: Re: How can I be notified whenever point of a buffer changed? Date: Fri, 13 Apr 2007 12:22:19 +0200 Message-ID: <86lkgwa810.fsf@ketchup.de.uu.net> References: <1176350448.277558.178010@q75g2000hsh.googlegroups.com> <1176430900.460559.246910@o5g2000hsb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1176459775 20352 80.91.229.12 (13 Apr 2007 10:22:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 13 Apr 2007 10:22:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 13 12:22:52 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HcIvb-0004KR-Gw for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Apr 2007 12:22:51 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HcIzr-0004RN-DV for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Apr 2007 06:27:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HcIza-0004R7-JC for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 06:26:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HcIzY-0004Qu-6P for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 06:26:57 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HcIzX-0004Qr-Vc for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 06:26:55 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HcIvH-0001ie-5k for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 06:22:31 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HcIvF-0000Bb-8g for help-gnu-emacs@gnu.org; Fri, 13 Apr 2007 12:22:29 +0200 Original-Received: from de-lt-054776l.eu.frd.uu.net ([62.191.185.105]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 13 Apr 2007 12:22:29 +0200 Original-Received: from kai by de-lt-054776l.eu.frd.uu.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 13 Apr 2007 12:22:29 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: de-lt-054776l.eu.frd.uu.net User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.97 (gnu/linux) Cancel-Lock: sha1:3Tx//6/aOR2JqbzHyWeIrFAhU+U= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42637 Archived-At: "Ender" 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