]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/edebug.el
* emacs-lisp/checkdoc.el (checkdoc-proper-noun-region-engine): Use
[gnu-emacs] / lisp / emacs-lisp / edebug.el
index 3395259a04f2b0b65702ebdc6e3035986eefeab4..fe47074bf9754bfe54e4f628ef322c582878d658 100644 (file)
@@ -1,7 +1,8 @@
 ;;; edebug.el --- a source-level debugger for Emacs Lisp
 
 ;; Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1997, 1999,
-;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;;   Free Software Foundation, Inc.
 
 ;; Author: Daniel LaLiberte <liberte@holonexus.org>
 ;; Maintainer: FSF
@@ -66,9 +67,9 @@
 (defcustom edebug-setup-hook nil
   "Functions to call before edebug is used.
 Each time it is set to a new value, Edebug will call those functions
-once and then `edebug-setup-hook' is reset to nil.  You could use this
+once and then reset `edebug-setup-hook' to nil.  You could use this
 to load up Edebug specifications associated with a package you are
-using but only when you also use Edebug."
+using, but only when you also use Edebug."
   :type 'hook
   :group 'edebug)
 
@@ -96,7 +97,7 @@ variable.  You may wish to make it local to each buffer with
 
 ;;;###autoload
 (defcustom edebug-all-forms nil
-  "Non-nil evaluation of all forms will instrument for Edebug.
+  "Non-nil means evaluation of all forms will instrument for Edebug.
 This doesn't apply to loading or evaluations in the minibuffer.
 Use the command `edebug-all-forms' to toggle the value of this option."
   :type 'boolean
@@ -106,9 +107,9 @@ Use the command `edebug-all-forms' to toggle the value of this option."
   "Non-nil means all macro call arguments may be evaluated.
 If this variable is nil, the default, Edebug will *not* wrap
 macro call arguments as if they will be evaluated.
-For each macro, a `edebug-form-spec' overrides this option.
+For each macro, an `edebug-form-spec' overrides this option.
 So to specify exceptions for macros that have some arguments evaluated
-and some not, you should specify an `edebug-form-spec'."
+and some not, use `def-edebug-spec' to specify an `edebug-form-spec'."
   :type 'boolean
   :group 'edebug)
 
@@ -128,13 +129,13 @@ restored.
   "If non-nil, save and restore point in all displayed buffers.
 
 Saving and restoring point in other buffers is necessary if you are
-debugging code that changes the point of a buffer which is displayed
+debugging code that changes the point of a buffer that is displayed
 in a non-selected window.  If Edebug or the user then selects the
 window, the buffer's point will be changed to the window's point.
 
 Saving and restoring point in all buffers is expensive, since it
-requires selecting each window twice, so enable this only if you need
-it."
+requires selecting each window twice, so enable this only if you
+need it."
   :type 'boolean
   :group 'edebug)
 
@@ -178,15 +179,15 @@ Use this with caution since it is not debugged."
 
 
 (defcustom edebug-print-length 50
-  "Default value of `print-length' for printing results in Edebug."
+  "If non-nil, default value of `print-length' for printing results in Edebug."
   :type 'integer
   :group 'edebug)
 (defcustom edebug-print-level 50
-  "Default value of `print-level' for printing results in Edebug."
+  "If non-nil, default value of `print-level' for printing results in Edebug."
   :type 'integer
   :group 'edebug)
 (defcustom edebug-print-circle t
-  "Default value of `print-circle' for printing results in Edebug."
+  "If non-nil, default value of `print-circle' for printing results in Edebug."
   :type 'boolean
   :group 'edebug)
 
@@ -227,7 +228,7 @@ If the result is non-nil, then break.  Errors are ignored."
   :group 'edebug)
 
 (defcustom edebug-sit-for-seconds 1
-  "Number of seconds to pause when execution mode is `trace'."
+  "Number of seconds to pause when execution mode is `trace' or `continue'."
   :type 'number
   :group 'edebug)
 
@@ -351,8 +352,7 @@ Return the result of the last expression in BODY."
         (edebug:s-r-end (point-max-marker)))
      (unwind-protect
         (progn ,@body)
-       (save-excursion
-        (set-buffer (marker-buffer edebug:s-r-beg))
+       (with-current-buffer (marker-buffer edebug:s-r-beg)
         (narrow-to-region edebug:s-r-beg edebug:s-r-end)))))
 
 ;;; Display
@@ -2002,6 +2002,7 @@ expressions; a `progn' form will be returned enclosing these forms."
           [&optional stringp]
           [&optional ("interactive" interactive)]
           def-body))
+;; FIXME? Isn't this missing the doc-string?  Cf defun.
 (def-edebug-spec defmacro
   (&define name lambda-list [&optional ("declare" &rest sexp)] def-body))
 
@@ -2045,6 +2046,7 @@ expressions; a `progn' form will be returned enclosing these forms."
 (def-edebug-spec apply (function-form &rest form))
 (def-edebug-spec funcall (function-form &rest form))
 
+;; FIXME? The manual has a gate here.
 (def-edebug-spec let
   ((&rest &or (symbolp &optional form) symbolp)
    body))
@@ -2576,15 +2578,16 @@ MSG is printed after `::::} '."
        (edebug-outside-o-a-p overlay-arrow-position)
        (edebug-outside-o-a-s overlay-arrow-string)
        (edebug-outside-c-i-e-a cursor-in-echo-area)
-       (edebug-outside-d-c-i-n-s-w default-cursor-in-non-selected-windows))
+       (edebug-outside-d-c-i-n-s-w
+         (default-value 'cursor-in-non-selected-windows)))
     (unwind-protect
        (let ((overlay-arrow-position overlay-arrow-position)
              (overlay-arrow-string overlay-arrow-string)
              (cursor-in-echo-area nil)
-             (default-cursor-in-non-selected-windows t)
              (unread-command-events unread-command-events)
              ;; any others??
              )
+          (setq-default cursor-in-non-selected-windows t)
          (if (not (buffer-name edebug-buffer))
              (let ((debug-on-error nil))
                (error "Buffer defining %s not found" edebug-function)))
@@ -2779,10 +2782,8 @@ MSG is printed after `::::} '."
          ;; Restore edebug-buffer's outside point.
          ;;    (edebug-trace "restore edebug-buffer point: %s"
          ;;              edebug-buffer-outside-point)
-         (let ((current-buffer (current-buffer)))
-           (set-buffer edebug-buffer)
-           (goto-char edebug-buffer-outside-point)
-           (set-buffer current-buffer))
+         (with-current-buffer edebug-buffer
+           (goto-char edebug-buffer-outside-point))
          ;; ... nothing more.
          )
       (with-timeout-unsuspend edebug-with-timeout-suspend)
@@ -2791,8 +2792,8 @@ MSG is printed after `::::} '."
        unread-command-events edebug-outside-unread-command-events
        overlay-arrow-position edebug-outside-o-a-p
        overlay-arrow-string edebug-outside-o-a-s
-       cursor-in-echo-area edebug-outside-c-i-e-a
-       default-cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
+       cursor-in-echo-area edebug-outside-c-i-e-a)
+      (setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
       )))
 
 
@@ -2813,17 +2814,15 @@ MSG is printed after `::::} '."
 (defvar edebug-outside-standard-output)
 (defvar edebug-outside-standard-input)
 (defvar edebug-outside-current-prefix-arg)
-(defvar edebug-outside-last-command-char)
 (defvar edebug-outside-last-command)
 (defvar edebug-outside-this-command)
-(defvar edebug-outside-last-input-char)
 
 ;; Note: here we have defvars for variables that are
 ;; built-in in certain versions.
 ;; Each defvar makes a difference
 ;; in versions where the variable is *not* built-in.
 
-;; Emacs 18
+;; Emacs 18  FIXME
 (defvar edebug-outside-unread-command-char)
 
 ;; Emacs 19.
@@ -2838,7 +2837,7 @@ MSG is printed after `::::} '."
 ;; (maybe works with byte-compile-version 2.22 at least)
 (defvar edebug-unread-command-char-warning)
 (defvar edebug-unread-command-event-warning)
-(eval-when-compile
+(eval-when-compile                     ; FIXME
   (setq edebug-unread-command-char-warning
        (get 'unread-command-char 'byte-obsolete-variable))
   (put 'unread-command-char 'byte-obsolete-variable nil))
@@ -2850,8 +2849,7 @@ MSG is printed after `::::} '."
   (let ((edebug-buffer-read-only buffer-read-only)
        ;; match-data must be done in the outside buffer
        (edebug-outside-match-data
-        (save-excursion  ; might be unnecessary now??
-          (set-buffer edebug-outside-buffer)  ; in case match buffer different
+        (with-current-buffer edebug-outside-buffer ; in case match buffer different
           (match-data)))
 
        ;;(edebug-number-of-recursions (1+ edebug-number-of-recursions))
@@ -2869,12 +2867,10 @@ MSG is printed after `::::} '."
        (edebug-outside-standard-input standard-input)
        (edebug-outside-defining-kbd-macro defining-kbd-macro)
 
-       (edebug-outside-last-command-char last-command-char)
        (edebug-outside-last-command last-command)
        (edebug-outside-this-command this-command)
-       (edebug-outside-last-input-char last-input-char)
 
-       (edebug-outside-unread-command-char unread-command-char)
+       (edebug-outside-unread-command-char unread-command-char) ; FIXME
        (edebug-outside-current-prefix-arg current-prefix-arg)
 
        (edebug-outside-last-input-event last-input-event)
@@ -2888,10 +2884,8 @@ MSG is printed after `::::} '."
        (let (
              ;; Declare global values local but using the same global value.
              ;; We could set these to the values for previous edebug call.
-             (last-command-char last-command-char)
              (last-command last-command)
              (this-command this-command)
-             (last-input-char last-input-char)
 
              ;; Assume no edebug command sets unread-command-char.
              (unread-command-char -1)
@@ -2955,13 +2949,11 @@ MSG is printed after `::::} '."
 
       ;; Reset global vars to outside values, in case they have been changed.
       (setq
-       last-command-char edebug-outside-last-command-char
        last-command-event edebug-outside-last-command-event
        last-command edebug-outside-last-command
        this-command edebug-outside-this-command
        unread-command-char edebug-outside-unread-command-char
        current-prefix-arg edebug-outside-current-prefix-arg
-       last-input-char edebug-outside-last-input-char
        last-input-event edebug-outside-last-input-event
        last-event-frame edebug-outside-last-event-frame
        last-nonmenu-event edebug-outside-last-nonmenu-event
@@ -3098,7 +3090,8 @@ Otherwise, toggle for all windows."
   (goto-char edebug-point))
 
 (defun edebug-view-outside ()
-  "Change to the outside window configuration."
+  "Change to the outside window configuration.
+Use `edebug-where' to return."
   (interactive)
   (if (not edebug-active)
       (error "Edebug is not active"))
@@ -3112,8 +3105,8 @@ Otherwise, toggle for all windows."
 
 (defun edebug-bounce-point (arg)
   "Bounce the point in the outside current buffer.
-If prefix arg is supplied, sit for that many seconds before returning.
-The default is one second."
+If prefix argument ARG is supplied, sit for that many seconds
+before returning.  The default is one second."
   (interactive "p")
   (if (not edebug-active)
       (error "Edebug is not active"))
@@ -3274,6 +3267,7 @@ With prefix argument, make it a temporary breakpoint."
 
 
 (defun edebug-set-global-break-condition (expression)
+  "Set `edebug-global-break-condition' to EXPRESSION."
   (interactive
    (list
     (let ((initial (and edebug-global-break-condition
@@ -3323,31 +3317,36 @@ With prefix ARG, set temporary break at current point and go."
   (edebug-set-mode 'go "Go..." "Edebug will go until break."))
 
 (defun edebug-Go-nonstop-mode ()
-  "Go, evaluating without debugging."
+  "Go, evaluating without debugging.
+You can use `edebug-stop', or any editing command, to stop."
   (interactive)
   (edebug-set-mode 'Go-nonstop "Go-Nonstop..."
                   "Edebug will not stop at breaks."))
 
 
 (defun edebug-trace-mode ()
-  "Begin trace mode."
+  "Begin trace mode.
+Pauses for `edebug-sit-for-seconds' at each stop point."
   (interactive)
   (edebug-set-mode 'trace "Tracing..." "Edebug will trace with pause."))
 
 (defun edebug-Trace-fast-mode ()
-  "Trace with no wait at each step."
+  "Trace with no wait at each step.
+Updates the display at each stop point, but does not pause."
   (interactive)
   (edebug-set-mode 'Trace-fast
                   "Trace fast..." "Edebug will trace without pause."))
 
 (defun edebug-continue-mode ()
-  "Begin continue mode."
+  "Begin continue mode.
+Pauses for `edebug-sit-for-seconds' at each break point."
   (interactive)
   (edebug-set-mode 'continue "Continue..."
                   "Edebug will pause at breakpoints."))
 
 (defun edebug-Continue-fast-mode ()
-  "Trace with no wait at each step."
+  "Trace with no wait at each step.
+Updates the display at each break point, but does not pause."
   (interactive)
   (edebug-set-mode 'Continue-fast "Continue fast..."
                   "Edebug will stop and go at breakpoints."))
@@ -3379,7 +3378,7 @@ Useful for exiting from trace or continue loop."
 
 (defun edebug-forward-sexp (arg)
   "Proceed from the current point to the end of the ARGth sexp ahead.
-If there are not ARG sexps ahead, then do edebug-step-out."
+If there are not ARG sexps ahead, then do `edebug-step-out'."
   (interactive "p")
   (condition-case nil
       (let ((parse-sexp-ignore-comments t))
@@ -3580,14 +3579,12 @@ Return the result of the last expression."
      (set-match-data edebug-outside-match-data)
      ;; Restore outside context.
      (let (;; (edebug-inside-map (current-local-map)) ;; restore map??
-          (last-command-char edebug-outside-last-command-char)
           (last-command-event edebug-outside-last-command-event)
           (last-command edebug-outside-last-command)
           (this-command edebug-outside-this-command)
           (unread-command-char edebug-outside-unread-command-char)
           (unread-command-events edebug-outside-unread-command-events)
           (current-prefix-arg edebug-outside-current-prefix-arg)
-          (last-input-char edebug-outside-last-input-char)
           (last-input-event edebug-outside-last-input-event)
           (last-event-frame edebug-outside-last-event-frame)
           (last-nonmenu-event edebug-outside-last-nonmenu-event)
@@ -3605,8 +3602,8 @@ Return the result of the last expression."
           (overlay-arrow-position edebug-outside-o-a-p)
           (overlay-arrow-string edebug-outside-o-a-s)
           (cursor-in-echo-area edebug-outside-c-i-e-a)
-          (default-cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
           )
+       (setq-default cursor-in-non-selected-windows edebug-outside-d-c-i-n-s-w)
        (unwind-protect
           (save-excursion              ; of edebug-buffer
             (set-buffer edebug-outside-buffer)
@@ -3623,14 +3620,12 @@ Return the result of the last expression."
 
         ;; Save values that may have been changed.
         (setq
-         edebug-outside-last-command-char last-command-char
          edebug-outside-last-command-event last-command-event
          edebug-outside-last-command last-command
          edebug-outside-this-command this-command
          edebug-outside-unread-command-char unread-command-char
          edebug-outside-unread-command-events unread-command-events
          edebug-outside-current-prefix-arg current-prefix-arg
-         edebug-outside-last-input-char last-input-char
          edebug-outside-last-input-event last-input-event
          edebug-outside-last-event-frame last-event-frame
          edebug-outside-last-nonmenu-event last-nonmenu-event
@@ -3644,22 +3639,24 @@ Return the result of the last expression."
          edebug-outside-o-a-p overlay-arrow-position
          edebug-outside-o-a-s overlay-arrow-string
          edebug-outside-c-i-e-a cursor-in-echo-area
-         edebug-outside-d-c-i-n-s-w default-cursor-in-non-selected-windows
-         )
+         edebug-outside-d-c-i-n-s-w (default-value
+                                       'cursor-in-non-selected-windows)
+          )
 
         ;; Restore the outside saved values; don't alter
         ;; the outside binding loci.
         (setcdr edebug-outside-pre-command-hook pre-command-hook)
         (setcdr edebug-outside-post-command-hook post-command-hook)
 
+         (setq-default cursor-in-non-selected-windows t)
         ))                             ; let
      ))
 
-(defvar cl-debug-env nil) ;; defined in cl; non-nil when lexical env used.
+(defvar cl-debug-env)  ; defined in cl; non-nil when lexical env used.
 
 (defun edebug-eval (edebug-expr)
   ;; Are there cl lexical variables active?
-  (if cl-debug-env
+  (if (bound-and-true-p cl-debug-env)
       (eval (cl-macroexpand-all edebug-expr cl-debug-env))
     (eval edebug-expr)))
 
@@ -3687,10 +3684,7 @@ Return the result of the last expression."
                                  (prin1-to-string edebug-arg)))
                      (cdr edebug-value) ", ")))
 
-;; Define here in case they are not already defined.
-(defvar print-level nil)
-(defvar print-circle nil)
-(defvar print-readably) ;; defined by lemacs
+(defvar print-readably) ; defined by lemacs
 ;; Alternatively, we could change the definition of
 ;; edebug-safe-prin1-to-string to only use these if defined.
 
@@ -3699,7 +3693,7 @@ Return the result of the last expression."
        (print-length (or edebug-print-length print-length))
        (print-level (or edebug-print-level print-level))
        (print-circle (or edebug-print-circle print-circle))
-       (print-readably nil)) ;; lemacs uses this.
+       (print-readably nil)) ; lemacs uses this.
     (condition-case nil
        (edebug-prin1-to-string value)
       (error "#Apparently circular structure#"))))
@@ -3762,6 +3756,7 @@ This prints the value into current buffer."
 
 ;;; Edebug Minor Mode
 
+;; FIXME eh?
 (defvar gud-inhibit-global-bindings
   "*Non-nil means don't do global rebindings of C-x C-a subcommands.")
 
@@ -3881,6 +3876,7 @@ This prints the value into current buffer."
 
 
 (defun edebug-help ()
+  "Describe `edebug-mode'."
   (interactive)
   (describe-function 'edebug-mode))
 
@@ -3987,6 +3983,7 @@ May only be called from within `edebug-recursive-edit'."
    ))
 
 (defun edebug-visit-eval-list ()
+  "Switch to the evaluation list buffer \"*edebug*\"."
   (interactive)
   (edebug-eval-redisplay)
   (edebug-pop-to-buffer edebug-eval-buffer))
@@ -4112,7 +4109,7 @@ Otherwise call `debug' normally."
   (with-output-to-temp-buffer (buffer-name edebug-backtrace-buffer)
     (setq edebug-backtrace-buffer standard-output)
     (let ((print-escape-newlines t)
-         (print-length 50)
+         (print-length 50)     ; FIXME cf edebug-safe-prin1-to-string
          last-ok-point)
       (backtrace)
 
@@ -4180,6 +4177,7 @@ You must include newlines in FMT to break lines, but one newline is appended."
 \f
 ;;; Frequency count and coverage
 
+;; FIXME should this use overlays instead?
 (defun edebug-display-freq-count ()
   "Display the frequency count data for each line of the current definition.
 The frequency counts are inserted as comment lines after each line,