Variable: before-change-functions
before-change-functions is a variable defined in buffer.c.
Documentation
List of functions to call before each text change.
Two arguments are passed to each function: the positions of
the beginning and end of the range of old text to be changed.
(For an insertion, the beginning and end are at the same place.)
No information is given about the length of the text after the change.
Buffer changes made while executing the before-change-functions
don't call any before-change or after-change functions.
That's because inhibit-modification-hooks is temporarily set non-nil.
If an unhandled error happens in running these functions, the variable's value remains nil. That prevents the error from happening repeatedly and making Emacs nonfunctional.
Probably introduced at or before Emacs version 19.23.
Source Code
// Defined in /usr/src/emacs/src/buffer.c
DEFVAR_LISP ("before-change-functions", Vbefore_change_functions,
doc: /* List of functions to call before each text change.
Two arguments are passed to each function: the positions of
the beginning and end of the range of old text to be changed.
\(For an insertion, the beginning and end are at the same place.)