aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/debugging.texi31
-rw-r--r--doc/lispref/elisp.texi2
-rw-r--r--doc/lispref/variables.texi61
3 files changed, 94 insertions, 0 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi
index 6c0908acccb..c80b0f95b37 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -69,6 +69,7 @@ debugger recursively. @xref{Recursive Editing}.
69* Error Debugging:: Entering the debugger when an error happens. 69* Error Debugging:: Entering the debugger when an error happens.
70* Infinite Loops:: Stopping and debugging a program that doesn't exit. 70* Infinite Loops:: Stopping and debugging a program that doesn't exit.
71* Function Debugging:: Entering it when a certain function is called. 71* Function Debugging:: Entering it when a certain function is called.
72* Variable Debugging:: Entering it when a variable is modified.
72* Explicit Debug:: Entering it at a certain point in the program. 73* Explicit Debug:: Entering it at a certain point in the program.
73* Using Debugger:: What the debugger does; what you see while in it. 74* Using Debugger:: What the debugger does; what you see while in it.
74* Debugger Commands:: Commands used while in the debugger. 75* Debugger Commands:: Commands used while in the debugger.
@@ -290,6 +291,36 @@ Calling @code{cancel-debug-on-entry} does nothing to a function which is
290not currently set up to break on entry. 291not currently set up to break on entry.
291@end deffn 292@end deffn
292 293
294@node Variable Debugging
295@subsection Entering the debugger when a variable is modified
296@cindex variable write debugging
297@cindex debugging changes to variables
298
299Sometimes a problem with a function is due to a wrong setting of a
300variable. Setting up the debugger to trigger whenever the variable is
301changed is a quick way to find the origin of the setting.
302
303@deffn Command debug-on-variable-change variable
304This function arranges for the debugger to be called whenever
305@var{variable} is modified.
306
307It is implemented using the watchpoint mechanism, so it inherits the
308same characteristics and limitations: all aliases of @var{variable}
309will be watched together, only dynamic variables can be watched, and
310changes to the objects referenced by variables are not detected. For
311details, see @ref{Watching Variables}.
312@end deffn
313
314@deffn Command cancel-debug-on-variable-change &optional variable
315This function undoes the effect of @code{debug-on-variable-change} on
316@var{variable}. When called interactively, it prompts for
317@var{variable} in the minibuffer. If @var{variable} is omitted or
318@code{nil}, it cancels break-on-change for all variables. Calling
319@code{cancel-debug-on-variable-change} does nothing to a variable
320which is not currently set up to break on change.
321@end deffn
322
323
293@node Explicit Debug 324@node Explicit Debug
294@subsection Explicit Entry to the Debugger 325@subsection Explicit Entry to the Debugger
295@cindex debugger, explicit entry 326@cindex debugger, explicit entry
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 708bd9c3094..6983ab77c63 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -498,6 +498,7 @@ Variables
498* Accessing Variables:: Examining values of variables whose names 498* Accessing Variables:: Examining values of variables whose names
499 are known only at run time. 499 are known only at run time.
500* Setting Variables:: Storing new values in variables. 500* Setting Variables:: Storing new values in variables.
501* Watching Variables:: Running a function when a variable is changed.
501* Variable Scoping:: How Lisp chooses among local and global values. 502* Variable Scoping:: How Lisp chooses among local and global values.
502* Buffer-Local Variables:: Variable values in effect only in one buffer. 503* Buffer-Local Variables:: Variable values in effect only in one buffer.
503* File Local Variables:: Handling local variable lists in files. 504* File Local Variables:: Handling local variable lists in files.
@@ -642,6 +643,7 @@ The Lisp Debugger
642* Error Debugging:: Entering the debugger when an error happens. 643* Error Debugging:: Entering the debugger when an error happens.
643* Infinite Loops:: Stopping and debugging a program that doesn't exit. 644* Infinite Loops:: Stopping and debugging a program that doesn't exit.
644* Function Debugging:: Entering it when a certain function is called. 645* Function Debugging:: Entering it when a certain function is called.
646* Variable Debugging:: Entering it when a variable is modified.
645* Explicit Debug:: Entering it at a certain point in the program. 647* Explicit Debug:: Entering it at a certain point in the program.
646* Using Debugger:: What the debugger does; what you see while in it. 648* Using Debugger:: What the debugger does; what you see while in it.
647* Debugger Commands:: Commands used while in the debugger. 649* Debugger Commands:: Commands used while in the debugger.
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 4f2274f81a0..d777e4da509 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -34,6 +34,7 @@ representing the variable.
34* Accessing Variables:: Examining values of variables whose names 34* Accessing Variables:: Examining values of variables whose names
35 are known only at run time. 35 are known only at run time.
36* Setting Variables:: Storing new values in variables. 36* Setting Variables:: Storing new values in variables.
37* Watching Variables:: Running a function when a variable is changed.
37* Variable Scoping:: How Lisp chooses among local and global values. 38* Variable Scoping:: How Lisp chooses among local and global values.
38* Buffer-Local Variables:: Variable values in effect only in one buffer. 39* Buffer-Local Variables:: Variable values in effect only in one buffer.
39* File Local Variables:: Handling local variable lists in files. 40* File Local Variables:: Handling local variable lists in files.
@@ -766,6 +767,66 @@ error is signaled.
766@end example 767@end example
767@end defun 768@end defun
768 769
770@node Watching Variables
771@section Running a function when a variable is changed.
772@cindex variable watchpoints
773@cindex watchpoints for Lisp variables
774
775It is sometimes useful to take some action when a variable changes its
776value. The watchpoint facility provides the means to do so. Some
777possible uses for this feature include keeping display in sync with
778variable settings, and invoking the debugger to track down unexpected
779changes to variables (@pxref{Variable Debugging}).
780
781The following functions may be used to manipulate and query the watch
782functions for a variable.
783
784@defun add-variable-watcher symbol watch-function
785This function arranges for @var{watch-function} to be called whenever
786@var{symbol} is modified. Modifications through aliases
787(@pxref{Variable Aliases}) will have the same effect.
788
789@var{watch-function} will be called with 4 arguments: (@var{symbol}
790@var{newval} @var{operation} @var{where}).
791
792@var{symbol} is the variable being changed.
793@var{newval} is the value it will be changed to.
794@var{operation} is a symbol representing the kind of change, one of:
795`set', `let', `unlet', `makunbound', and `defvaralias'.
796@var{where} is a buffer if the buffer-local value of the variable is
797being changed, nil otherwise.
798@end defun
799
800@defun remove-variable-watch symbol watch-function
801This function removes @var{watch-function} from @var{symbol}'s list of
802watchers.
803@end defun
804
805@defun get-variable-watchers symbol
806This function returns the list of @var{symbol}'s active watcher
807functions.
808@end defun
809
810@subsection Limitations
811
812There are a couple of ways in which a variable could be modifed (or at
813least appear to be modified) without triggering a watchpoint.
814
815Since watchpoints are attached to symbols, modification to the
816objects contained within variables (e.g., by a list modification
817function @pxref{Modifying Lists}) is not caught by this mechanism.
818
819Additionally, C code can modify the value of variables directly,
820bypassing the watchpoint mechanism.
821
822A minor limitation of this feature, again because it targets symbols,
823is that only variables of dynamic scope may be watched. This poses
824little difficulty, since modifications to lexical variables can be
825discovered easily by inspecting the code within the scope of the
826variable (unlike dynamic variables, which can be modified by any code
827at all, @pxref{Variable Scoping}).
828
829
769@node Variable Scoping 830@node Variable Scoping
770@section Scoping Rules for Variable Bindings 831@section Scoping Rules for Variable Bindings
771@cindex scoping rule 832@cindex scoping rule