comparison lispref/text.texi @ 78602:b86e73d7c635

(reset_var_on_error): New fun. (signal_before_change, signal_after_change): Use it to reset (after|before)-change-functions to nil in case of error. Bind inhibit-modification-hooks to t. Don't bind (after|before)-change-functions to nil while they run.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 21 Aug 2007 18:22:03 +0000
parents 602257788b4a
children e8263132a24d
comparison
equal deleted inserted replaced
78601:047d1fc93812 78602:b86e73d7c635
4362 parts of the buffer, this will still work, but it is not advisable, 4362 parts of the buffer, this will still work, but it is not advisable,
4363 because it may lead to inefficient behavior for some change hook 4363 because it may lead to inefficient behavior for some change hook
4364 functions. 4364 functions.
4365 @end defmac 4365 @end defmac
4366 4366
4367 The two variables above are temporarily bound to @code{nil} during the
4368 time that any of these functions is running. This means that if one of
4369 these functions changes the buffer, that change won't run these
4370 functions. If you do want a hook function to make changes that run
4371 these functions, make it bind these variables back to their usual
4372 values.
4373
4374 One inconvenient result of this protective feature is that you cannot
4375 have a function in @code{after-change-functions} or
4376 @code{before-change-functions} which changes the value of that variable.
4377 But that's not a real limitation. If you want those functions to change
4378 the list of functions to run, simply add one fixed function to the hook,
4379 and code that function to look in another variable for other functions
4380 to call. Here is an example:
4381
4382 @example
4383 (setq my-own-after-change-functions nil)
4384 (defun indirect-after-change-function (beg end len)
4385 (let ((list my-own-after-change-functions))
4386 (while list
4387 (funcall (car list) beg end len)
4388 (setq list (cdr list)))))
4389
4390 @group
4391 (add-hooks 'after-change-functions
4392 'indirect-after-change-function)
4393 @end group
4394 @end example
4395
4396 @defvar first-change-hook 4367 @defvar first-change-hook
4397 This variable is a normal hook that is run whenever a buffer is changed 4368 This variable is a normal hook that is run whenever a buffer is changed
4398 that was previously in the unmodified state. 4369 that was previously in the unmodified state.
4399 @end defvar 4370 @end defvar
4400 4371
4402 If this variable is non-@code{nil}, all of the change hooks are 4373 If this variable is non-@code{nil}, all of the change hooks are
4403 disabled; none of them run. This affects all the hook variables 4374 disabled; none of them run. This affects all the hook variables
4404 described above in this section, as well as the hooks attached to 4375 described above in this section, as well as the hooks attached to
4405 certain special text properties (@pxref{Special Properties}) and overlay 4376 certain special text properties (@pxref{Special Properties}) and overlay
4406 properties (@pxref{Overlay Properties}). 4377 properties (@pxref{Overlay Properties}).
4378
4379 Also, this variable is bound to non-@code{nil} while running those
4380 same hook variables, so that by default modifying the buffer from
4381 a modification hook does not cause other modification hooks to be run.
4382 If you do want modification hooks to be run in a particular piece of
4383 code that is itself run from a modification hook, then rebind locally
4384 @code{inhibit-modification-hooks} to @code{nil}.
4407 @end defvar 4385 @end defvar
4408 4386
4409 @ignore 4387 @ignore
4410 arch-tag: 3721e738-a1cb-4085-bc1a-6cb8d8e1d32b 4388 arch-tag: 3721e738-a1cb-4085-bc1a-6cb8d8e1d32b
4411 @end ignore 4389 @end ignore