]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/edebug.el
Merge from trunk.
[gnu-emacs] / lisp / emacs-lisp / edebug.el
index 77953b37021773e4af8c81e951dc10ae6c6286f2..f47feebe5d2cdd145de01be05af4faca14230bc1 100644 (file)
@@ -1,8 +1,6 @@
 ;;; 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, 2009,
-;;   2010  Free Software Foundation, Inc.
+;; Copyright (C) 1988-1995, 1997, 1999-2012 Free Software Foundation, Inc.
 
 ;; Author: Daniel LaLiberte <liberte@holonexus.org>
 ;; Maintainer: FSF
@@ -193,6 +191,7 @@ Use this with caution since it is not debugged."
 
 (defcustom edebug-unwrap-results nil
   "Non-nil if Edebug should unwrap results of expressions.
+That is, Edebug will try to remove its own instrumentation from the result.
 This is useful when debugging macros where the results of expressions
 are instrumented expressions.  But don't do this when results might be
 circular or an infinite loop will result."
@@ -521,7 +520,8 @@ the minibuffer."
          ((and (eq (car form) 'defcustom)
                (default-boundp (nth 1 form)))
           ;; Force variable to be bound.
-          (set-default (nth 1 form) (eval (nth 2 form))))
+           ;; FIXME: Shouldn't this use the :setter or :initializer?
+          (set-default (nth 1 form) (eval (nth 2 form) lexical-binding)))
           ((eq (car form) 'defface)
            ;; Reset the face.
            (setq face-new-frame-defaults
@@ -534,7 +534,7 @@ the minibuffer."
                                (put ',(nth 1 form) 'customized-face
                                     ,(nth 2 form)))
                        (put (nth 1 form) 'saved-face nil)))))
-    (setq edebug-result (eval form))
+    (setq edebug-result (eval (eval-sexp-add-defvars form) lexical-binding))
     (if (not edebugging)
        (princ edebug-result)
       edebug-result)))
@@ -567,7 +567,8 @@ already is one.)"
    ;; but this causes problems while edebugging edebug.
    (let ((edebug-all-forms t)
         (edebug-all-defs t))
-     (edebug-read-top-level-form))))
+     (eval-sexp-add-defvars
+      (edebug-read-top-level-form)))))
 
 
 (defun edebug-read-top-level-form ()
@@ -1285,7 +1286,7 @@ expressions; a `progn' form will be returned enclosing these forms."
   ;; Wrap a form, usually a defining form, but any evaluated one.
   ;; If speclist is non-nil, this is being called by edebug-defining-form.
   ;; Otherwise it is being called from edebug-read-and-maybe-wrap-form1.
-  ;; This is a hack, but I havent figured out a simpler way yet.
+  ;; This is a hack, but I haven't figured out a simpler way yet.
   (let* ((form-data-entry (edebug-get-form-data-entry form-begin form-end))
         ;; Set this marker before parsing.
         (edebug-form-begin-marker
@@ -1557,7 +1558,7 @@ expressions; a `progn' form will be returned enclosing these forms."
   ;; The first spec is handled and the remainder-handler handles the rest.
   (let ((edebug-matching-depth
         (if (> edebug-matching-depth edebug-max-depth)
-            (error "too deep - perhaps infinite loop in spec?")
+            (error "Too deep - perhaps infinite loop in spec?")
           (1+ edebug-matching-depth))))
     (cond
      ((null specs) nil)
@@ -2028,7 +2029,10 @@ 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.
+;; FIXME?  The manual uses this form (maybe that's just for illustration?):
+;; (def-edebug-spec let
+;;   ((&rest &or symbolp (gate symbolp &optional form))
+;;    body))
 (def-edebug-spec let
   ((&rest &or (symbolp &optional form) symbolp)
    body))
@@ -2131,8 +2135,6 @@ expressions; a `progn' form will be returned enclosing these forms."
 
 (def-edebug-spec with-custom-print body)
 
-(def-edebug-spec sregexq (&rest sexp))
-(def-edebug-spec rx (&rest sexp))
 
 ;;; The debugger itself
 
@@ -2466,6 +2468,7 @@ MSG is printed after `::::} '."
            (if edebug-global-break-condition
                (condition-case nil
                    (setq edebug-global-break-result
+                          ;; FIXME: lexbind.
                          (eval edebug-global-break-condition))
                  (error nil))))
           (edebug-break))
@@ -2477,6 +2480,7 @@ MSG is printed after `::::} '."
                (and edebug-break-data
                     (or (not edebug-break-condition)
                         (setq edebug-break-result
+                               ;; FIXME: lexbind.
                               (eval edebug-break-condition))))))
       (if (and edebug-break
               (nth 2 edebug-break-data)) ; is it temporary?
@@ -3201,7 +3205,7 @@ before returning.  The default is one second."
   "Modify the breakpoint for the form at point or after it.
 Set it if FLAG is non-nil, clear it otherwise.  Then move to that point.
 If CONDITION or TEMPORARY are non-nil, add those attributes to
-the breakpoint.  "
+the breakpoint."
   (let ((edebug-stop-point (edebug-find-stop-point)))
     (if edebug-stop-point
        (let* ((edebug-def-name (car edebug-stop-point))
@@ -3398,7 +3402,7 @@ go to the end of the last sexp, or if that is the same point, then step."
   ;; Return the function symbol, or nil if not instrumented.
   (let ((func-marker (get func 'edebug)))
     (cond
-     ((markerp func-marker)
+     ((and (markerp func-marker) (marker-buffer func-marker))
       ;; It is uninstrumented, so instrument it.
       (with-current-buffer (marker-buffer func-marker)
        (goto-char func-marker)
@@ -3408,7 +3412,7 @@ go to the end of the last sexp, or if that is the same point, then step."
       (message "%s is already instrumented." func)
       func)
      (t
-      (let ((loc (find-function-noselect func)))
+      (let ((loc (find-function-noselect func t)))
        (unless (cdr loc)
          (error "Could not find the definition in its file"))
        (with-current-buffer (car loc)
@@ -3448,7 +3452,7 @@ instrumented.  Then it does `edebug-on-entry' and switches to `go' mode."
 (defun edebug-on-entry (function &optional flag)
   "Cause Edebug to stop when FUNCTION is called.
 With prefix argument, make this temporary so it is automatically
-cancelled the first time the function is entered."
+canceled the first time the function is entered."
   (interactive "aEdebug on entry to: \nP")
   ;; Could store this in the edebug data instead.
   (put function 'edebug-on-entry (if flag 'temp t)))
@@ -3637,9 +3641,10 @@ Return the result of the last expression."
 
 (defun edebug-eval (edebug-expr)
   ;; Are there cl lexical variables active?
-  (if (bound-and-true-p cl-debug-env)
-      (eval (cl-macroexpand-all edebug-expr cl-debug-env))
-    (eval edebug-expr)))
+  (eval (if (bound-and-true-p cl-debug-env)
+            (cl-macroexpand-all edebug-expr cl-debug-env)
+          edebug-expr)
+        lexical-binding))
 
 (defun edebug-safe-eval (edebug-expr)
   ;; Evaluate EXPR safely.
@@ -3739,7 +3744,7 @@ This prints the value into current buffer."
 
 ;; FIXME eh?
 (defvar gud-inhibit-global-bindings
-  "*Non-nil means don't do global rebindings of C-x C-a subcommands.")
+  "Non-nil means don't do global rebindings of C-x C-a subcommands.")
 
 ;; Global GUD bindings for all emacs-lisp-mode buffers.
 (unless gud-inhibit-global-bindings
@@ -3878,24 +3883,23 @@ Global commands prefixed by `global-edebug-prefix':
 \\{global-edebug-map}
 
 Options:
-edebug-setup-hook
-edebug-all-defs
-edebug-all-forms
-edebug-save-windows
-edebug-save-displayed-buffer-points
-edebug-initial-mode
-edebug-trace
-edebug-test-coverage
-edebug-continue-kbd-macro
-edebug-print-length
-edebug-print-level
-edebug-print-circle
-edebug-on-error
-edebug-on-quit
-edebug-on-signal
-edebug-unwrap-results
-edebug-global-break-condition
-"
+`edebug-setup-hook'
+`edebug-all-defs'
+`edebug-all-forms'
+`edebug-save-windows'
+`edebug-save-displayed-buffer-points'
+`edebug-initial-mode'
+`edebug-trace'
+`edebug-test-coverage'
+`edebug-continue-kbd-macro'
+`edebug-print-length'
+`edebug-print-level'
+`edebug-print-circle'
+`edebug-on-error'
+`edebug-on-quit'
+`edebug-on-signal'
+`edebug-unwrap-results'
+`edebug-global-break-condition'"
   ;; If the user kills the buffer in which edebug is currently active,
   ;; exit to top level, because the edebug command loop can't usefully
   ;; continue running in such a case.
@@ -4157,6 +4161,8 @@ You must include newlines in FMT to break lines, but one newline is appended."
 ;;; Frequency count and coverage
 
 ;; FIXME should this use overlays instead?
+;; Definitely, IMO.  The current business with undo in
+;; edebug-temp-display-freq-count is horrid.
 (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,
@@ -4226,6 +4232,8 @@ reinstrument it."
        (insert "\n")
        (setq i first-index)))))
 
+;; FIXME this does not work very well.  Eg if you press an arrow key,
+;; or make a mouse-click, it fails with "Non-character input-event".
 (defun edebug-temp-display-freq-count ()
   "Temporarily display the frequency count data for the current definition.
 It is removed when you hit any char."
@@ -4235,14 +4243,15 @@ It is removed when you hit any char."
     (undo-boundary)
     (edebug-display-freq-count)
     (setq unread-command-char (read-char))
+    ;; Yuck!  This doesn't seem to work at all for me.
     (undo)))
 
 \f
 ;;; Menus
 
 (defun edebug-toggle (variable)
-  (set variable (not (eval variable)))
-  (message "%s: %s" variable (eval variable)))
+  (set variable (not (symbol-value variable)))
+  (message "%s: %s" variable (symbol-value variable)))
 
 ;; We have to require easymenu (even for Emacs 18) just so
 ;; the easy-menu-define macro call is compiled correctly.