comparison lisp/edebug/edebug.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents b82b59fe008d
children 56c54cf7c5b6
comparison
equal deleted inserted replaced
25:383a494979f8 26:441bb1e64a06
20 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; 02111-1307, USA. 23 ;; 02111-1307, USA.
24 24
25 ;;; Synched up with: Not in FSF 25 ;;; Synched up with: FSF 19.34.
26 26
27 ;;; Commentary: 27 ;;; Commentary:
28 28
29 ;; LCD Archive Entry: 29 ;; LCD Archive Entry:
30 ;; edebug|Daniel LaLiberte|liberte@cs.uiuc.edu 30 ;; edebug|Daniel LaLiberte|liberte@cs.uiuc.edu
31 ;; |A source level debugger for Emacs Lisp. 31 ;; |A source level debugger for Emacs Lisp.
32 ;; |$Date: 1996/12/18 03:54:30 $|$Revision: 1.1.1.2 $|~/modes/edebug.el| 32 ;; |$Date: 1997/03/02 03:42:50 $|$Revision: 1.2 $|~/modes/edebug.el|
33 33
34 ;; This minor mode allows programmers to step through Emacs Lisp 34 ;; This minor mode allows programmers to step through Emacs Lisp
35 ;; source code while executing functions. You can also set 35 ;; source code while executing functions. You can also set
36 ;; breakpoints, trace (stopping at each expression), evaluate 36 ;; breakpoints, trace (stopping at each expression), evaluate
37 ;; expressions as if outside Edebug, reevaluate and display a list of 37 ;; expressions as if outside Edebug, reevaluate and display a list of
38 ;; expressions, trap errors normally caught by debug, and display a 38 ;; expressions, trap errors normally caught by debug, and display a
39 ;; debug style backtrace. 39 ;; debug style backtrace.
40 40
41 ;; Installation 41 ;;; Installation
42 ;; ============= 42 ;; =============
43 43
44 ;; Put edebug.el in some directory in your load-path and 44 ;; Put edebug.el in some directory in your load-path and
45 ;; byte-compile it. Also read the beginning of edebug-epoch.el, 45 ;; byte-compile it. Also read the beginning of edebug-epoch.el,
46 ;; cl-specs.el, and edebug-cl-read.el if they apply to you. 46 ;; cl-specs.el, and edebug-cl-read.el if they apply to you.
57 57
58 ;; In previous versions of Edebug, users were directed to set 58 ;; In previous versions of Edebug, users were directed to set
59 ;; `debugger' to `edebug-debug'. This is no longer necessary 59 ;; `debugger' to `edebug-debug'. This is no longer necessary
60 ;; since Edebug automatically sets it whenever Edebug is active. 60 ;; since Edebug automatically sets it whenever Edebug is active.
61 61
62 ;; Minimal Instructions 62 ;;; Minimal Instructions
63 ;; ===================== 63 ;; =====================
64 64
65 ;; First evaluate a defun with C-xx, then run the function. Step 65 ;; First evaluate a defun with C-xx, then run the function. Step
66 ;; through the code with SPC, mark breakpoints with b, go until a 66 ;; through the code with SPC, mark breakpoints with b, go until a
67 ;; breakpoint is reached with g, and quit execution with q. Use the 67 ;; breakpoint is reached with g, and quit execution with q. Use the
80 ;; Urbana, IL 61801 80 ;; Urbana, IL 61801
81 81
82 ;; uiucdcs!liberte 82 ;; uiucdcs!liberte
83 ;; liberte@cs.uiuc.edu 83 ;; liberte@cs.uiuc.edu
84 84
85 ;; ===============================
86 ;; For the early revision history, see edebug-history. 85 ;; For the early revision history, see edebug-history.
87 86
88 ;;; Code: 87 ;;; Code:
89 88
90 (defconst edebug-version 89 (defconst edebug-version
91 (let ((raw-version "$Revision: 1.1.1.2 $")) 90 (let ((raw-version "$Revision: 1.2 $"))
92 (substring raw-version (string-match "[0-9.]*" raw-version) 91 (substring raw-version (string-match "[0-9.]*" raw-version)
93 (match-end 0)))) 92 (match-end 0))))
94 93
95 (require 'backquote) 94 (require 'backquote)
96 95
97 ;; Emacs 18 doesnt have defalias. 96 ;; Emacs 18 doesn't have defalias.
98 (eval-and-compile 97 (eval-and-compile
99 (or (fboundp 'defalias) (fset 'defalias 'fset))) 98 (or (fboundp 'defalias) (fset 'defalias 'fset)))
100 99
101 100
102 ;; Bug reporting 101 ;;; Bug reporting
103 ;; ==============
104 102
105 (defconst edebug-maintainer-address "liberte@cs.uiuc.edu") 103 (defconst edebug-maintainer-address "liberte@cs.uiuc.edu")
106 104
107 (defun edebug-submit-bug-report () 105 (defun edebug-submit-bug-report ()
108 "Submit, via mail, a bug report on edebug." 106 "Submit, via mail, a bug report on edebug."
126 'edebug-print-length 124 'edebug-print-length
127 'edebug-print-level 125 'edebug-print-level
128 'edebug-print-circle 126 'edebug-print-circle
129 )))) 127 ))))
130 128
131 129 ;;; Options
132 ;; Options
133 ;; ===============================
134 130
135 (defvar edebug-setup-hook nil 131 (defvar edebug-setup-hook nil
136 "*Functions to call before edebug is used. 132 "*Functions to call before edebug is used.
137 Each time it is set to a new value, Edebug will call those functions 133 Each time it is set to a new value, Edebug will call those functions
138 once and then `edebug-setup-hook' is reset to nil. You could use this 134 once and then `edebug-setup-hook' is reset to nil. You could use this
250 246
251 (defvar edebug-global-break-condition nil 247 (defvar edebug-global-break-condition nil
252 "*If non-nil, an expression to test for at every stop point. 248 "*If non-nil, an expression to test for at every stop point.
253 If the result is non-nil, then break. Errors are ignored.") 249 If the result is non-nil, then break. Errors are ignored.")
254 250
255 251 ;;; Form spec utilities.
256 ;; Form spec utilities.
257 ;; ===============================
258 252
259 ;;;###autoload 253 ;;;###autoload
260 (defmacro def-edebug-spec (symbol spec) 254 (defmacro def-edebug-spec (symbol spec)
261 "Set the edebug-form-spec property of SYMBOL according to SPEC. 255 "Set the edebug-form-spec property of SYMBOL according to SPEC.
262 Both SYMBOL and SPEC are unevaluated. The SPEC can be 0, t, a symbol 256 Both SYMBOL and SPEC are unevaluated. The SPEC can be 0, t, a symbol
277 ;; (edebug-trace "indirection: %s" edebug-form-spec) 271 ;; (edebug-trace "indirection: %s" edebug-form-spec)
278 (setq edebug-form-spec indirect)) 272 (setq edebug-form-spec indirect))
279 edebug-form-spec 273 edebug-form-spec
280 )) 274 ))
281 275
282 276 ;;; Utilities
283 ;; Utilities
284 ;; ===============================
285 277
286 ;; Define edebug-gensym - from old cl.el 278 ;; Define edebug-gensym - from old cl.el
287 (defvar edebug-gensym-index 0 279 (defvar edebug-gensym-index 0
288 "Integer used by `edebug-gensym' to produce new names.") 280 "Integer used by `edebug-gensym' to produce new names.")
289 281
328 (point)) 320 (point))
329 (point))))) 321 (point)))))
330 322
331 (defun edebug-window-list () 323 (defun edebug-window-list ()
332 "Return a list of windows, in order of `next-window'." 324 "Return a list of windows, in order of `next-window'."
333 ;; This doesnt work for epoch. 325 ;; This doesn't work for epoch.
334 (let* ((first-window (selected-window)) 326 (let* ((first-window (selected-window))
335 (window-list (list first-window)) 327 (window-list (list first-window))
336 (next (next-window first-window))) 328 (next (next-window first-window)))
337 (while (not (eq next first-window)) 329 (while (not (eq next first-window))
338 (setq window-list (cons next window-list)) 330 (setq window-list (cons next window-list))
370 362
371 (defun edebug-functionp (object) 363 (defun edebug-functionp (object)
372 "Returns the function named by OBJECT, or nil if it is not a function." 364 "Returns the function named by OBJECT, or nil if it is not a function."
373 (setq object (edebug-lookup-function object)) 365 (setq object (edebug-lookup-function object))
374 (if (or (subrp object) 366 (if (or (subrp object)
375 (compiled-function-p object) 367 (compiled-function-p object) ; XEmacs
376 (and (listp object) 368 (and (listp object)
377 (eq (car object) 'lambda) 369 (eq (car object) 'lambda)
378 (listp (car (cdr object))))) 370 (listp (car (cdr object)))))
379 object)) 371 object))
380 372
401 (progn (,@ body)) 393 (progn (,@ body))
402 (save-excursion 394 (save-excursion
403 (set-buffer (marker-buffer edebug:s-r-beg)) 395 (set-buffer (marker-buffer edebug:s-r-beg))
404 (narrow-to-region edebug:s-r-beg edebug:s-r-end)))))) 396 (narrow-to-region edebug:s-r-beg edebug:s-r-end))))))
405 397
406 ;; Display 398 ;;; Display
407 ;; ============
408 399
409 (defconst edebug-trace-buffer "*edebug-trace*" 400 (defconst edebug-trace-buffer "*edebug-trace*"
410 "Name of the buffer to put trace info in.") 401 "Name of the buffer to put trace info in.")
411 402
412 (defun edebug-pop-to-buffer (buffer &optional window) 403 (defun edebug-pop-to-buffer (buffer &optional window)
424 (select-window window) 415 (select-window window)
425 (if (one-window-p) 416 (if (one-window-p)
426 (split-window)) 417 (split-window))
427 ;; (message "next window: %s" (next-window)) (sit-for 1) 418 ;; (message "next window: %s" (next-window)) (sit-for 1)
428 (if (eq (get-buffer-window edebug-trace-buffer) (next-window)) 419 (if (eq (get-buffer-window edebug-trace-buffer) (next-window))
429 ;; Dont select trace window 420 ;; Don't select trace window
430 nil 421 nil
431 (select-window (next-window)))) 422 (select-window (next-window))))
432 (set-window-buffer (selected-window) buffer) 423 (set-window-buffer (selected-window) buffer)
433 (set-window-hscroll (selected-window) 0);; should this be?? 424 (set-window-hscroll (selected-window) 0);; should this be??
434 ;; Selecting the window does not set the buffer until command loop. 425 ;; Selecting the window does not set the buffer until command loop.
496 (defalias 'edebug-get-buffer-window 'get-buffer-window) 487 (defalias 'edebug-get-buffer-window 'get-buffer-window)
497 (defalias 'edebug-sit-for 'sit-for) 488 (defalias 'edebug-sit-for 'sit-for)
498 (defalias 'edebug-input-pending-p 'input-pending-p) 489 (defalias 'edebug-input-pending-p 'input-pending-p)
499 490
500 491
501 ;; Redefine read and eval functions 492 ;;; Redefine read and eval functions
502 ;; =================================
503 ;; read is redefined to maybe instrument forms. 493 ;; read is redefined to maybe instrument forms.
504 ;; eval-defun is redefined to check edebug-all-forms and edebug-all-defs. 494 ;; eval-defun is redefined to check edebug-all-forms and edebug-all-defs.
505 495
506 ;; Use the Lisp version of eval-region. 496 ;; Use the Lisp version of eval-region.
507 (require 'eval-reg "eval-reg") 497 (require 'eval-reg "eval-reg")
520 call it with a char as argument to push a char back) 510 call it with a char as argument to push a char back)
521 a string (takes text from string, starting at the beginning) 511 a string (takes text from string, starting at the beginning)
522 t (read text line using minibuffer and use it). 512 t (read text line using minibuffer and use it).
523 513
524 This version, from Edebug, maybe instruments the expression. But the 514 This version, from Edebug, maybe instruments the expression. But the
525 STREAM must be the current buffer to do so. Whether it instuments is 515 STREAM must be the current buffer to do so. Whether it instruments is
526 also dependent on the values of `edebug-all-defs' and 516 also dependent on the values of `edebug-all-defs' and
527 `edebug-all-forms'." 517 `edebug-all-forms'."
528 (or stream (setq stream standard-input)) 518 (or stream (setq stream standard-input))
529 (if (eq stream (current-buffer)) 519 (if (eq stream (current-buffer))
530 (edebug-read-and-maybe-wrap-form) 520 (edebug-read-and-maybe-wrap-form)
531 (edebug-original-read stream))) 521 (edebug-original-read stream)))
532 522
533 (or (fboundp 'edebug-original-eval-defun) 523 (or (fboundp 'edebug-original-eval-defun)
534 (defalias 'edebug-original-eval-defun (symbol-function 'eval-defun))) 524 (defalias 'edebug-original-eval-defun (symbol-function 'eval-defun)))
535 525
526 ;; We should somehow arrange to be able to do this
527 ;; without actually replacing the eval-defun command.
536 (defun edebug-eval-defun (edebug-it) 528 (defun edebug-eval-defun (edebug-it)
537 "Evaluate the top-level form containing point, or after point. 529 "Evaluate the top-level form containing point, or after point.
538 530
539 This version, from Edebug, has the following differences: With a 531 This version, from Edebug, has the following differences: With a
540 prefix argument instrument the code for Edebug. If `edebug-all-defs' is 532 prefix argument instrument the code for Edebug. If `edebug-all-defs' is
541 non-nil, then the code is instrumented *unless* there is a prefix 533 non-nil, then the code is instrumented *unless* there is a prefix
542 argument. If instrumenting, it prints: `Edebug: FUNCTIONNAME'. 534 argument. If instrumenting, it prints: `Edebug: FUNCTIONNAME'.
543 Otherwise, it prints in the minibuffer." 535 Otherwise, it prints in the minibuffer."
544 (interactive "P") 536 (interactive "P")
545 (let ((edebugging (not (eq (not edebug-it) (not edebug-all-defs)))) 537 (let* ((edebugging (not (eq (not edebug-it) (not edebug-all-defs))))
546 (edebug-result)) 538 (edebug-result)
547 (setq edebug-result 539 (form
548 (eval 540 (let ((edebug-all-forms edebugging)
549 (let ((edebug-all-forms edebugging) 541 (edebug-all-defs (eq edebug-all-defs (not edebug-it))))
550 (edebug-all-defs (eq edebug-all-defs (not edebug-it)))) 542 (edebug-read-top-level-form))))
551 (edebug-read-top-level-form)))) 543 (if (and (eq (car form) 'defvar)
544 (cdr-safe (cdr-safe form)))
545 (setq form (cons 'defconst (cdr form))))
546 (setq edebug-result (eval form))
552 (if (not edebugging) 547 (if (not edebugging)
553 (princ edebug-result) 548 (princ edebug-result)
554 edebug-result))) 549 edebug-result)))
555 550
556 551
563 This is like `eval-defun', but the code is always instrumented for Edebug. 558 This is like `eval-defun', but the code is always instrumented for Edebug.
564 Print its name in the minibuffer and leave point where it is, 559 Print its name in the minibuffer and leave point where it is,
565 or if an error occurs, leave point after it with mark at the original point." 560 or if an error occurs, leave point after it with mark at the original point."
566 (interactive) 561 (interactive)
567 (eval 562 (eval
568 ;; Bind edebug-all-forms only while reading, not while evaling 563 ;; Bind edebug-all-forms only while reading, not while evalling
569 ;; but this causes problems while edebugging edebug. 564 ;; but this causes problems while edebugging edebug.
570 (let ((edebug-all-forms t) 565 (let ((edebug-all-forms t)
571 (edebug-all-defs t)) 566 (edebug-all-defs t))
572 (edebug-read-top-level-form)))) 567 (edebug-read-top-level-form))))
573 568
614 (elisp-eval-region-uninstall) 609 (elisp-eval-region-uninstall)
615 (defalias 'read (symbol-function 'edebug-original-read)) 610 (defalias 'read (symbol-function 'edebug-original-read))
616 (defalias 'eval-defun (symbol-function 'edebug-original-eval-defun))) 611 (defalias 'eval-defun (symbol-function 'edebug-original-eval-defun)))
617 612
618 613
619 ;; Edebug internal data 614 ;;; Edebug internal data
620 ;; ===============================
621 615
622 ;; The internal data that is needed for edebugging is kept in the 616 ;; The internal data that is needed for edebugging is kept in the
623 ;; buffer-local variable `edebug-form-data'. 617 ;; buffer-local variable `edebug-form-data'.
624 618
625 ;; XEmacs change? 619 ;; XEmacs change?
700 ;; (get (car entry) 'edebug-dependents)) 694 ;; (get (car entry) 'edebug-dependents))
701 ;; (set-marker (nth 1 entry) nil) 695 ;; (set-marker (nth 1 entry) nil)
702 ;; (set-marker (nth 2 entry) nil) 696 ;; (set-marker (nth 2 entry) nil)
703 (setq edebug-form-data (delq entry edebug-form-data))))) 697 (setq edebug-form-data (delq entry edebug-form-data)))))
704 698
705 699 ;;; Parser utilities
706 ;; Parser utilities
707 ;; ===============================
708
709 700
710 (defun edebug-syntax-error (&rest args) 701 (defun edebug-syntax-error (&rest args)
711 ;; Signal an invalid-read-syntax with ARGS. 702 ;; Signal an invalid-read-syntax with ARGS.
712 (signal 'invalid-read-syntax args)) 703 (signal 'invalid-read-syntax args))
713 704
721 (aset table i 'space) 712 (aset table i 'space)
722 (setq i (1+ i))) 713 (setq i (1+ i)))
723 (aset table ?\( 'lparen) 714 (aset table ?\( 'lparen)
724 (aset table ?\) 'rparen) 715 (aset table ?\) 'rparen)
725 (aset table ?\' 'quote) 716 (aset table ?\' 'quote)
717 (aset table ?\` 'backquote)
718 (aset table ?\, 'comma)
726 (aset table ?\" 'string) 719 (aset table ?\" 'string)
727 (aset table ?\? 'char) 720 (aset table ?\? 'char)
728 (aset table ?\[ 'lbracket) 721 (aset table ?\[ 'lbracket)
729 (aset table ?\] 'rbracket) 722 (aset table ?\] 'rbracket)
730 (aset table ?\. 'dot) 723 (aset table ?\. 'dot)
731 (aset table ?\# 'hash) 724 (aset table ?\# 'hash)
732 ;; We treat numbers as symbols, because of confusion with -, -1, and 1-. 725 ;; We treat numbers as symbols, because of confusion with -, -1, and 1-.
733 ;; We dont care about any other chars since they wont be seen. 726 ;; We don't care about any other chars since they won't be seen.
734 table)) 727 table))
735 728
736 (defun edebug-next-token-class () 729 (defun edebug-next-token-class ()
737 ;; Move to the next token and return its class. We only care about 730 ;; Move to the next token and return its class. We only care about
738 ;; lparen, rparen, dot, quote, string, char, vector, or symbol. 731 ;; lparen, rparen, dot, quote, backquote, comma, string, char, vector,
732 ;; or symbol.
739 (edebug-skip-whitespace) 733 (edebug-skip-whitespace)
740 (aref edebug-read-syntax-table (following-char))) 734 (aref edebug-read-syntax-table (following-char)))
741 735
742 736
743 (defun edebug-skip-whitespace () 737 (defun edebug-skip-whitespace ()
770 (edebug-original-read (current-buffer)) 764 (edebug-original-read (current-buffer))
771 (if (/= (preceding-char) ?\") 765 (if (/= (preceding-char) ?\")
772 (forward-char -1)))) 766 (forward-char -1))))
773 ((eq class 'quote) (forward-char 1) 767 ((eq class 'quote) (forward-char 1)
774 (list 'quote (edebug-read-sexp))) 768 (list 'quote (edebug-read-sexp)))
769 ((eq class 'backquote)
770 (list '\` (edebug-read-sexp)))
771 ((eq class 'comma)
772 (list '\, (edebug-read-sexp)))
775 (t ; anything else, just read it. 773 (t ; anything else, just read it.
776 (edebug-original-read (current-buffer)))))) 774 (edebug-original-read (current-buffer))))))
777 775
778 776 ;;; Offsets for reader
779 ;; Offsets for reader
780 ;; ==============================
781 777
782 ;; Define a structure to represent offset positions of expressions. 778 ;; Define a structure to represent offset positions of expressions.
783 ;; Each offset structure looks like: (before . after) for constituents, 779 ;; Each offset structure looks like: (before . after) for constituents,
784 ;; or for structures that have elements: (before <subexpressions> . after) 780 ;; or for structures that have elements: (before <subexpressions> . after)
785 ;; where the <subexpressions> are the offset structures for subexpressions 781 ;; where the <subexpressions> are the offset structures for subexpressions
850 (edebug-store-before-offset (, point)) 846 (edebug-store-before-offset (, point))
851 (,@ body)) 847 (,@ body))
852 (edebug-store-after-offset (point))))) 848 (edebug-store-after-offset (point)))))
853 849
854 850
855 ;; Reader for Emacs Lisp. 851 ;;; Reader for Emacs Lisp.
856 ;; ========================================== 852
857 ;; Uses edebug-next-token-class (and edebug-skip-whitespace) above. 853 ;; Uses edebug-next-token-class (and edebug-skip-whitespace) above.
858 854
859 (defconst edebug-read-alist 855 (defconst edebug-read-alist
860 '((symbol . edebug-read-symbol) 856 '((symbol . edebug-read-symbol)
861 (lparen . edebug-read-list) 857 (lparen . edebug-read-list)
862 (string . edebug-read-string) 858 (string . edebug-read-string)
863 (quote . edebug-read-quote) 859 (quote . edebug-read-quote)
860 (backquote . edebug-read-backquote)
861 (comma . edebug-read-comma)
864 (lbracket . edebug-read-vector) 862 (lbracket . edebug-read-vector)
865 (hash . edebug-read-function) 863 (hash . edebug-read-function)
866 )) 864 ))
867 865
868 (defun edebug-read-storing-offsets (stream) 866 (defun edebug-read-storing-offsets (stream)
895 (forward-char 1) 893 (forward-char 1)
896 (list 894 (list
897 (edebug-storing-offsets (point) 'quote) 895 (edebug-storing-offsets (point) 'quote)
898 (edebug-read-storing-offsets stream))) 896 (edebug-read-storing-offsets stream)))
899 897
898 (defun edebug-read-backquote (stream)
899 ;; Turn `thing into (\` thing)
900 (let ((opoint (point)))
901 (forward-char 1)
902 ;; Generate the same structure of offsets we would have
903 ;; if the resulting list appeared verbatim in the input text.
904 (edebug-storing-offsets opoint
905 (list
906 (edebug-storing-offsets opoint '\`)
907 (edebug-read-storing-offsets stream)))))
908
909 (defvar edebug-read-backquote-new nil
910 "Non-nil if reading the inside of a new-style backquote with no parens around it.
911 Value of nil means reading the inside of an old-style backquote construct
912 which is surrounded by an extra set of parentheses.
913 This controls how we read comma constructs.")
914
915 (defun edebug-read-comma (stream)
916 ;; Turn ,thing into (\, thing). Handle ,@ and ,. also.
917 (let ((opoint (point)))
918 (forward-char 1)
919 (let ((symbol '\,))
920 (cond ((eq (following-char) ?\.)
921 (setq symbol '\,\.)
922 (forward-char 1))
923 ((eq (following-char) ?\@)
924 (setq symbol '\,@)
925 (forward-char 1)))
926 ;; Generate the same structure of offsets we would have
927 ;; if the resulting list appeared verbatim in the input text.
928 (if edebug-read-backquote-new
929 (list
930 (edebug-storing-offsets opoint symbol)
931 (edebug-read-storing-offsets stream))
932 (edebug-storing-offsets opoint symbol)))))
933
900 (defun edebug-read-function (stream) 934 (defun edebug-read-function (stream)
901 ;; Turn #'thing into (function thing) 935 ;; Turn #'thing into (function thing)
902 (forward-char 1) 936 (forward-char 1)
903 (if (/= ?\' (following-char)) (edebug-syntax-error "Bad char")) 937 (if (/= ?\' (following-char)) (edebug-syntax-error "Bad char"))
904 (forward-char 1) 938 (forward-char 1)
910 (defun edebug-read-list (stream) 944 (defun edebug-read-list (stream)
911 (forward-char 1) ; skip \( 945 (forward-char 1) ; skip \(
912 (prog1 946 (prog1
913 (let ((elements)) 947 (let ((elements))
914 (while (not (memq (edebug-next-token-class) '(rparen dot))) 948 (while (not (memq (edebug-next-token-class) '(rparen dot)))
915 (setq elements (cons (edebug-read-storing-offsets stream) elements))) 949 (if (eq (edebug-next-token-class) 'backquote)
950 (let ((edebug-read-backquote-new (not (null elements)))
951 (opoint (point)))
952 (if edebug-read-backquote-new
953 (setq elements (cons (edebug-read-backquote stream) elements))
954 (forward-char 1) ; Skip backquote.
955 ;; Call edebug-storing-offsets here so that we
956 ;; produce the same offsets we would have had
957 ;; if the backquote were an ordinary symbol.
958 (setq elements (cons (edebug-storing-offsets opoint '\`)
959 elements))))
960 (setq elements (cons (edebug-read-storing-offsets stream) elements))))
916 (setq elements (nreverse elements)) 961 (setq elements (nreverse elements))
917 (if (eq 'dot (edebug-next-token-class)) 962 (if (eq 'dot (edebug-next-token-class))
918 (let (dotted-form) 963 (let (dotted-form)
919 (forward-char 1) ; skip \. 964 (forward-char 1) ; skip \.
920 (setq dotted-form (edebug-read-storing-offsets stream)) 965 (setq dotted-form (edebug-read-storing-offsets stream))
935 (setq elements (cons (edebug-read-storing-offsets stream) elements))) 980 (setq elements (cons (edebug-read-storing-offsets stream) elements)))
936 (apply 'vector (nreverse elements))) 981 (apply 'vector (nreverse elements)))
937 (forward-char 1) ; skip \] 982 (forward-char 1) ; skip \]
938 )) 983 ))
939 984
940 985 ;;; Cursors for traversal of list and vector elements with offsets.
941
942 ;; Cursors for traversal of list and vector elements with offsets.
943 ;;====================================================================
944 986
945 (defvar edebug-dotted-spec nil) 987 (defvar edebug-dotted-spec nil)
946 988
947 (defun edebug-new-cursor (expressions offsets) 989 (defun edebug-new-cursor (expressions offsets)
948 ;; Return a new cursor for EXPRESSIONS with OFFSETS. 990 ;; Return a new cursor for EXPRESSIONS with OFFSETS.
1015 (let ((offset (edebug-top-offset cursor))) 1057 (let ((offset (edebug-top-offset cursor)))
1016 (while (consp offset) 1058 (while (consp offset)
1017 (setq offset (cdr offset))) 1059 (setq offset (cdr offset)))
1018 offset)) 1060 offset))
1019 1061
1020 ;; The Parser 1062 ;;; The Parser
1021 ;; ===============================
1022 1063
1023 ;; The top level function for parsing forms is 1064 ;; The top level function for parsing forms is
1024 ;; edebug-read-and-maybe-wrap-form; it calls all the rest. It checks the 1065 ;; edebug-read-and-maybe-wrap-form; it calls all the rest. It checks the
1025 ;; syntax a bit and leaves point at any error it finds, but otherwise 1066 ;; syntax a bit and leaves point at any error it finds, but otherwise
1026 ;; should appear to work like eval-defun. 1067 ;; should appear to work like eval-defun.
1068 (setq edebug-setup-hook nil) 1109 (setq edebug-setup-hook nil)
1069 1110
1070 (let (result 1111 (let (result
1071 edebug-top-window-data 1112 edebug-top-window-data
1072 edebug-def-name;; make sure it is locally nil 1113 edebug-def-name;; make sure it is locally nil
1073 ;; I dont like these here!! 1114 ;; I don't like these here!!
1074 edebug-&optional 1115 edebug-&optional
1075 edebug-&rest 1116 edebug-&rest
1076 edebug-gate 1117 edebug-gate
1077 edebug-best-error 1118 edebug-best-error
1078 edebug-error-point 1119 edebug-error-point
1092 (defun edebug-read-and-maybe-wrap-form1 () 1133 (defun edebug-read-and-maybe-wrap-form1 ()
1093 (let (spec 1134 (let (spec
1094 def-kind 1135 def-kind
1095 defining-form-p 1136 defining-form-p
1096 def-name 1137 def-name
1097 ;; These offset things dont belong here, but to support recursive 1138 ;; These offset things don't belong here, but to support recursive
1098 ;; calls to edebug-read, they need to be here. 1139 ;; calls to edebug-read, they need to be here.
1099 edebug-offsets 1140 edebug-offsets
1100 edebug-offsets-stack 1141 edebug-offsets-stack
1101 edebug-current-offset ; reset to nil 1142 edebug-current-offset ; reset to nil
1102 ) 1143 )
1111 ;; This is incorrect in general!! But OK most of the time. 1152 ;; This is incorrect in general!! But OK most of the time.
1112 def-name (if (and defining-form-p 1153 def-name (if (and defining-form-p
1113 (eq 'name (car (cdr spec))) 1154 (eq 'name (car (cdr spec)))
1114 (eq 'symbol (edebug-next-token-class))) 1155 (eq 'symbol (edebug-next-token-class)))
1115 (edebug-original-read (current-buffer)))))) 1156 (edebug-original-read (current-buffer))))))
1116 ;;(message "all defs: %s all forms: %s" edebug-all-defs edebug-all-forms) 1157 ;;;(message "all defs: %s all forms: %s" edebug-all-defs edebug-all-forms)
1117 (cond 1158 (cond
1118 (defining-form-p 1159 (defining-form-p
1119 (if (or edebug-all-defs edebug-all-forms) 1160 (if (or edebug-all-defs edebug-all-forms)
1120 ;; If it is a defining form and we are edebugging defs, 1161 ;; If it is a defining form and we are edebugging defs,
1121 ;; then let edebug-list-form start it. 1162 ;; then let edebug-list-form start it.
1186 (or edebug-def-name edebug-old-def-name (edebug-gensym "edebug-anon"))) 1227 (or edebug-def-name edebug-old-def-name (edebug-gensym "edebug-anon")))
1187 (` (edebug-enter 1228 (` (edebug-enter
1188 (quote (, edebug-def-name)) 1229 (quote (, edebug-def-name))
1189 (, (if edebug-inside-func 1230 (, (if edebug-inside-func
1190 (` (list (,@ 1231 (` (list (,@
1191 ;; Doesnt work with more than one def-body!! 1232 ;; Doesn't work with more than one def-body!!
1192 ;; But the list will just be reversed. 1233 ;; But the list will just be reversed.
1193 (nreverse edebug-def-args)))) 1234 (nreverse edebug-def-args))))
1194 'nil)) 1235 'nil))
1195 (function (lambda () (,@ forms))) 1236 (function (lambda () (,@ forms)))
1196 ))) 1237 )))
1215 ;; Return the edebug form for the current function at offset BEFORE-INDEX 1256 ;; Return the edebug form for the current function at offset BEFORE-INDEX
1216 ;; given FORM. Looks like: 1257 ;; given FORM. Looks like:
1217 ;; (edebug-after (edebug-before BEFORE-INDEX) AFTER-INDEX FORM) 1258 ;; (edebug-after (edebug-before BEFORE-INDEX) AFTER-INDEX FORM)
1218 ;; Also increment the offset index for subsequent use. 1259 ;; Also increment the offset index for subsequent use.
1219 ;; if (not edebug-stop-before-symbols) and form is a symbol, 1260 ;; if (not edebug-stop-before-symbols) and form is a symbol,
1220 ;; then dont call edebug-before. 1261 ;; then don't call edebug-before.
1221 (list 'edebug-after 1262 (list 'edebug-after
1222 (list 'edebug-before before-index) 1263 (list 'edebug-before before-index)
1223 after-index form)) 1264 after-index form))
1224 1265
1225 (defun edebug-make-after-form (form after-index) 1266 (defun edebug-make-after-form (form after-index)
1404 (edebug-inc-offset (edebug-cursor-offsets new-cursor)))) 1445 (edebug-inc-offset (edebug-cursor-offsets new-cursor))))
1405 ))) 1446 )))
1406 1447
1407 ((symbolp form) 1448 ((symbolp form)
1408 (cond 1449 (cond
1409 ;; Check for constant symbols that dont get wrapped. 1450 ;; Check for constant symbols that don't get wrapped.
1410 ((or (memq form '(t nil)) 1451 ((or (memq form '(t nil))
1411 (and (fboundp 'edebug-keywordp) (edebug-keywordp form))) 1452 (and (fboundp 'edebug-keywordp) (edebug-keywordp form)))
1412 form) 1453 form)
1413 1454
1414 ;; This option may go away. 1455 ;; This option may go away.
1493 1534
1494 (t (edebug-syntax-error 1535 (t (edebug-syntax-error
1495 "Head of list form must be a symbol or lambda expression."))) 1536 "Head of list form must be a symbol or lambda expression.")))
1496 )) 1537 ))
1497 1538
1498 1539 ;;; Matching of specs.
1499 ;; Matching of specs.
1500 ;; ===================
1501 1540
1502 (defvar edebug-after-dotted-spec nil) 1541 (defvar edebug-after-dotted-spec nil)
1503 1542
1504 (defvar edebug-matching-depth 0) ;; initial value 1543 (defvar edebug-matching-depth 0) ;; initial value
1505 (defconst edebug-max-depth 150) ;; maximum number of matching recursions. 1544 (defconst edebug-max-depth 150) ;; maximum number of matching recursions.
1506 1545
1507 1546
1508 ;; Failure to match 1547 ;;; Failure to match
1509 ;; ================== 1548
1510 ;; This throws to no-match, if there are higher alternatives. 1549 ;; This throws to no-match, if there are higher alternatives.
1511 ;; Otherwise it signals an error. The place of the error is found 1550 ;; Otherwise it signals an error. The place of the error is found
1512 ;; with the two before- and after-offset functions. 1551 ;; with the two before- and after-offset functions.
1513 1552
1514 (defun edebug-no-match (cursor &rest edebug-args) 1553 (defun edebug-no-match (cursor &rest edebug-args)
1592 (edebug-match-one-spec cursor spec))) 1631 (edebug-match-one-spec cursor spec)))
1593 (funcall remainder-handler cursor rest remainder-handler))))))) 1632 (funcall remainder-handler cursor rest remainder-handler)))))))
1594 1633
1595 1634
1596 ;; Define specs for all the symbol specs with functions used to process them. 1635 ;; Define specs for all the symbol specs with functions used to process them.
1597 ;; Perhaps we shouldnt be doing this with edebug-form-specs since the 1636 ;; Perhaps we shouldn't be doing this with edebug-form-specs since the
1598 ;; user may want to define macros or functions with the same names. 1637 ;; user may want to define macros or functions with the same names.
1599 ;; We could use an internal obarray for these primitive specs. 1638 ;; We could use an internal obarray for these primitive specs.
1600 1639
1601 (mapcar 1640 (mapcar
1602 (function (lambda (pair) 1641 (function (lambda (pair)
1710 (catch 'no-match 1749 (catch 'no-match
1711 (throw 'matched 1750 (throw 'matched
1712 (let (edebug-gate ;; only while matching each spec 1751 (let (edebug-gate ;; only while matching each spec
1713 edebug-best-error 1752 edebug-best-error
1714 edebug-error-point) 1753 edebug-error-point)
1715 ;; Doesnt support e.g. &or symbolp &rest form 1754 ;; Doesn't support e.g. &or symbolp &rest form
1716 (edebug-match-one-spec cursor (car specs))))) 1755 (edebug-match-one-spec cursor (car specs)))))
1717 ;; Match failed, so reset and try again. 1756 ;; Match failed, so reset and try again.
1718 (setq specs (cdr specs)) 1757 (setq specs (cdr specs))
1719 ;; Reset the cursor for the next match. 1758 ;; Reset the cursor for the next match.
1720 (edebug-set-cursor cursor this-form this-offset)) 1759 (edebug-set-cursor cursor this-form this-offset))
1739 (def-edebug-spec &key edebug-match-&key) 1778 (def-edebug-spec &key edebug-match-&key)
1740 1779
1741 (defun edebug-match-&key (cursor specs) 1780 (defun edebug-match-&key (cursor specs)
1742 ;; Following specs must look like (<name> <spec>) ... 1781 ;; Following specs must look like (<name> <spec>) ...
1743 ;; where <name> is the name of a keyword, and spec is its spec. 1782 ;; where <name> is the name of a keyword, and spec is its spec.
1744 ;; This really doesnt save much over the expanded form and takes time. 1783 ;; This really doesn't save much over the expanded form and takes time.
1745 (edebug-match-&rest 1784 (edebug-match-&rest
1746 cursor 1785 cursor
1747 (cons '&or 1786 (cons '&or
1748 (mapcar (function (lambda (pair) 1787 (mapcar (function (lambda (pair)
1749 (vector (format ":%s" (car pair)) 1788 (vector (format ":%s" (car pair))
1843 (defun edebug-match-function (cursor) 1882 (defun edebug-match-function (cursor)
1844 (error "Use function-form instead of function in edebug spec")) 1883 (error "Use function-form instead of function in edebug spec"))
1845 1884
1846 (defun edebug-match-&define (cursor specs) 1885 (defun edebug-match-&define (cursor specs)
1847 ;; Match a defining form. 1886 ;; Match a defining form.
1848 ;; Normally, &define is interpretted specially other places. 1887 ;; Normally, &define is interpreted specially other places.
1849 ;; This should only be called inside of a spec list to match the remainder 1888 ;; This should only be called inside of a spec list to match the remainder
1850 ;; of the current list. e.g. ("lambda" &define args def-body) 1889 ;; of the current list. e.g. ("lambda" &define args def-body)
1851 (edebug-make-form-wrapper 1890 (edebug-make-form-wrapper
1852 cursor 1891 cursor
1853 (edebug-before-offset cursor) 1892 (edebug-before-offset cursor)
1930 ;; Not to be used otherwise. 1969 ;; Not to be used otherwise.
1931 (let ((edebug-inside-func t)) 1970 (let ((edebug-inside-func t))
1932 (list (edebug-wrap-def-body (edebug-forms cursor))))) 1971 (list (edebug-wrap-def-body (edebug-forms cursor)))))
1933 1972
1934 1973
1935 ;; Edebug Form Specs 1974 ;;;; Edebug Form Specs
1936 ;; ========================================================== 1975 ;;; ==========================================================
1937 ;; See cl-specs.el for common lisp specs. 1976 ;;; See cl-specs.el for common lisp specs.
1938 1977
1939 ;;* Spec for def-edebug-spec 1978 ;;;;* Spec for def-edebug-spec
1940 ;; Out of date. 1979 ;;; Out of date.
1941 1980
1942 (defun edebug-spec-p (object) 1981 (defun edebug-spec-p (object)
1943 "Return non-nil if OBJECT is a symbol with an edebug-form-spec property." 1982 "Return non-nil if OBJECT is a symbol with an edebug-form-spec property."
1944 (and (symbolp object) 1983 (and (symbolp object)
1945 (get object 'edebug-form-spec))) 1984 (get object 'edebug-form-spec)))
1965 edebug-spec-p ;; Including all the special ones e.g. form. 2004 edebug-spec-p ;; Including all the special ones e.g. form.
1966 symbolp;; a predicate 2005 symbolp;; a predicate
1967 )) 2006 ))
1968 2007
1969 2008
1970 ;;* Emacs special forms and some functions. 2009 ;;;* Emacs special forms and some functions.
1971 2010
1972 ;; quote expects only one argument, although it allows any number. 2011 ;; quote expects only one argument, although it allows any number.
1973 (def-edebug-spec quote sexp) 2012 (def-edebug-spec quote sexp)
1974 2013
1975 ;; The standard defining forms. 2014 ;; The standard defining forms.
1982 [&optional ("interactive" interactive)] 2021 [&optional ("interactive" interactive)]
1983 def-body)) 2022 def-body))
1984 (def-edebug-spec defmacro 2023 (def-edebug-spec defmacro
1985 (&define name lambda-list def-body)) 2024 (&define name lambda-list def-body))
1986 2025
1987 (def-edebug-spec arglist lambda-list) ;; denegrated - use lambda-list. 2026 (def-edebug-spec arglist lambda-list) ;; deprecated - use lambda-list.
1988 2027
1989 (def-edebug-spec lambda-list 2028 (def-edebug-spec lambda-list
1990 (([&rest arg] 2029 (([&rest arg]
1991 [&optional ["&optional" arg &rest arg]] 2030 [&optional ["&optional" arg &rest arg]]
1992 &optional ["&rest" arg] 2031 &optional ["&rest" arg]
2083 (def-edebug-spec eval-and-compile t) 2122 (def-edebug-spec eval-and-compile t)
2084 2123
2085 ;; Anything else? 2124 ;; Anything else?
2086 2125
2087 2126
2088 ;;====================
2089 ;; Some miscellaneous specs for macros in public packages. 2127 ;; Some miscellaneous specs for macros in public packages.
2090 ;; Send me yours. 2128 ;; Send me yours.
2091 2129
2092 ;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu) 2130 ;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu)
2093 2131
2101 ) 2139 )
2102 [&optional stringp] 2140 [&optional stringp]
2103 [&optional ("interactive" interactive)] 2141 [&optional ("interactive" interactive)]
2104 def-body)) 2142 def-body))
2105 2143
2106 2144 ;;; The debugger itself
2107 ;; The debugger itself
2108 ;; ===============================
2109 2145
2110 (defvar edebug-active nil) ;; Non-nil when edebug is active 2146 (defvar edebug-active nil) ;; Non-nil when edebug is active
2111 2147
2112 ;; add minor-mode-alist entry 2148 ;;; add minor-mode-alist entry
2113 (or (assq 'edebug-active minor-mode-alist) 2149 (or (assq 'edebug-active minor-mode-alist)
2114 (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*") 2150 (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*")
2115 minor-mode-alist))) 2151 minor-mode-alist)))
2116 2152
2117 (defvar edebug-stack nil) 2153 (defvar edebug-stack nil)
2169 (defvar post-command-hook nil) 2205 (defvar post-command-hook nil)
2170 (defvar post-command-idle-hook nil) 2206 (defvar post-command-idle-hook nil)
2171 2207
2172 (defvar cl-lexical-debug) ;; Defined in cl.el 2208 (defvar cl-lexical-debug) ;; Defined in cl.el
2173 2209
2174 ;; Handling signals 2210 ;;; Handling signals
2175 ;; =================
2176 2211
2177 (if (not (fboundp 'edebug-original-signal)) 2212 (if (not (fboundp 'edebug-original-signal))
2178 (defalias 'edebug-original-signal (symbol-function 'signal))) 2213 (defalias 'edebug-original-signal (symbol-function 'signal)))
2179 ;; We should use advise for this!! 2214 ;; We should use advise for this!!
2180 2215
2198 ;; If we reach here without another non-local exit, then send signal again. 2233 ;; If we reach here without another non-local exit, then send signal again.
2199 ;; i.e. the signal is not continuable, yet. 2234 ;; i.e. the signal is not continuable, yet.
2200 (edebug-original-signal edebug-signal-name edebug-signal-data)) 2235 (edebug-original-signal edebug-signal-name edebug-signal-data))
2201 2236
2202 2237
2203 ;; Entering Edebug 2238 ;;; Entering Edebug
2204 ;; ==================
2205 2239
2206 (defun edebug-enter (edebug-function edebug-args edebug-body) 2240 (defun edebug-enter (edebug-function edebug-args edebug-body)
2207 ;; Entering FUNC. The arguments are ARGS, and the body is BODY. 2241 ;; Entering FUNC. The arguments are ARGS, and the body is BODY.
2208 ;; Setup edebug variables and evaluate BODY. This function is called 2242 ;; Setup edebug variables and evaluate BODY. This function is called
2209 ;; when a function evaluated with edebug-eval-top-level-form is entered. 2243 ;; when a function evaluated with edebug-eval-top-level-form is entered.
2516 2550
2517 (if edebug-save-displayed-buffer-points 2551 (if edebug-save-displayed-buffer-points
2518 (setq edebug-buffer-points (edebug-get-displayed-buffer-points))) 2552 (setq edebug-buffer-points (edebug-get-displayed-buffer-points)))
2519 2553
2520 ;; First move the edebug buffer point to edebug-point 2554 ;; First move the edebug buffer point to edebug-point
2521 ;; so that window start doesnt get changed when we display it. 2555 ;; so that window start doesn't get changed when we display it.
2522 ;; I dont know if this is going to help. 2556 ;; I don't know if this is going to help.
2523 ;;(set-buffer edebug-buffer) 2557 ;;(set-buffer edebug-buffer)
2524 ;;(goto-char edebug-point) 2558 ;;(goto-char edebug-point)
2525 2559
2526 ;; If edebug-buffer is not currently displayed, 2560 ;; If edebug-buffer is not currently displayed,
2527 ;; first find a window for it. 2561 ;; first find a window for it.
2612 (if (or edebug-stop 2646 (if (or edebug-stop
2613 (memq edebug-execution-mode '(step next)) 2647 (memq edebug-execution-mode '(step next))
2614 (eq edebug-arg-mode 'error)) 2648 (eq edebug-arg-mode 'error))
2615 (progn 2649 (progn
2616 ;; (setq edebug-execution-mode 'step) 2650 ;; (setq edebug-execution-mode 'step)
2617 ;; (edebug-overlay-arrow) ; this doesnt always show up. 2651 ;; (edebug-overlay-arrow) ; this doesn't always show up.
2618 (edebug-recursive-edit))) ; <---------- Recursive edit 2652 (edebug-recursive-edit))) ; <---------- Recursive edit
2619 2653
2620 ;; Reset the edebug-window-data to whatever it is now. 2654 ;; Reset the edebug-window-data to whatever it is now.
2621 (let ((window (if (eq (window-buffer) edebug-buffer) 2655 (let ((window (if (eq (window-buffer) edebug-buffer)
2622 (selected-window) 2656 (selected-window)
2658 (progn 2692 (progn
2659 (set-window-start window (cdr edebug-window-data) 2693 (set-window-start window (cdr edebug-window-data)
2660 'no-force) 2694 'no-force)
2661 ;; Unrestore edebug-buffer's window-point. 2695 ;; Unrestore edebug-buffer's window-point.
2662 ;; Needed in addition to setting the buffer point 2696 ;; Needed in addition to setting the buffer point
2663 ;; - otherwise quitting doesnt leave point as is. 2697 ;; - otherwise quitting doesn't leave point as is.
2664 ;; But this causes point to not be restored at times. 2698 ;; But this causes point to not be restored at times.
2665 ;; Also, it may not be a visible window. 2699 ;; Also, it may not be a visible window.
2666 ;; (set-window-point window edebug-point) 2700 ;; (set-window-point window edebug-point)
2667 ))) 2701 )))
2668 2702
2678 2712
2679 ;; Restore current buffer always, in case application needs it. 2713 ;; Restore current buffer always, in case application needs it.
2680 (set-buffer edebug-outside-buffer) 2714 (set-buffer edebug-outside-buffer)
2681 ;; Restore point, and mark. 2715 ;; Restore point, and mark.
2682 ;; Needed even if restoring windows because 2716 ;; Needed even if restoring windows because
2683 ;; that doesnt restore point and mark in the current buffer. 2717 ;; that doesn't restore point and mark in the current buffer.
2684 ;; But dont restore point if edebug-buffer is current buffer. 2718 ;; But don't restore point if edebug-buffer is current buffer.
2685 (if (not (eq edebug-buffer edebug-outside-buffer)) 2719 (if (not (eq edebug-buffer edebug-outside-buffer))
2686 (goto-char edebug-outside-point)) 2720 (goto-char edebug-outside-point))
2687 (if (marker-buffer (edebug-mark-marker)) 2721 (if (marker-buffer (edebug-mark-marker))
2688 ;; Does zmacs-regions need to be nil while doing set-marker? 2722 ;; Does zmacs-regions need to be nil while doing set-marker?
2689 (set-marker (edebug-mark-marker) edebug-outside-mark)) 2723 (set-marker (edebug-mark-marker) edebug-outside-mark))
2902 defining-kbd-macro edebug-outside-defining-kbd-macro 2936 defining-kbd-macro edebug-outside-defining-kbd-macro
2903 )) 2937 ))
2904 )) 2938 ))
2905 2939
2906 2940
2907 ;; Display related functions 2941 ;;; Display related functions
2908 ;; ===============================
2909 2942
2910 (defun edebug-adjust-window (old-start) 2943 (defun edebug-adjust-window (old-start)
2911 ;; If pos is not visible, adjust current window to fit following context. 2944 ;; If pos is not visible, adjust current window to fit following context.
2912 ;; (message "window: %s old-start: %s window-start: %s pos: %s" 2945 ;;; (message "window: %s old-start: %s window-start: %s pos: %s"
2913 ;; (selected-window) old-start (window-start) (point)) (sit-for 5) 2946 ;;; (selected-window) old-start (window-start) (point)) (sit-for 5)
2914 (if (not (pos-visible-in-window-p)) 2947 (if (not (pos-visible-in-window-p))
2915 (progn 2948 (progn
2916 ;; First try old-start 2949 ;; First try old-start
2917 (if old-start 2950 (if old-start
2918 (set-window-start (selected-window) old-start)) 2951 (set-window-start (selected-window) old-start))
3076 (delq buffer edebug-display-buffer-list) 3109 (delq buffer edebug-display-buffer-list)
3077 (cons buffer edebug-display-buffer-list))) 3110 (cons buffer edebug-display-buffer-list)))
3078 (message "Displaying %s %s" buffer 3111 (message "Displaying %s %s" buffer
3079 (if already-displaying "off" "on")))) 3112 (if already-displaying "off" "on"))))
3080 3113
3081 3114 ;;; Breakpoint related functions
3082 ;; Breakpoint related functions
3083 ;; ===============================
3084 3115
3085 (defun edebug-find-stop-point () 3116 (defun edebug-find-stop-point ()
3086 ;; Return (function . index) of the nearest edebug stop point. 3117 ;; Return (function . index) of the nearest edebug stop point.
3087 (let* ((edebug-def-name (edebug-form-data-symbol)) 3118 (let* ((edebug-def-name (edebug-form-data-symbol))
3088 (edebug-data 3119 (edebug-data
3142 ;; goto the first breakpoint 3173 ;; goto the first breakpoint
3143 (car edebug-breakpoints))) 3174 (car edebug-breakpoints)))
3144 (goto-char (+ edebug-def-mark 3175 (goto-char (+ edebug-def-mark
3145 (aref offset-vector (car breakpoint)))) 3176 (aref offset-vector (car breakpoint))))
3146 3177
3147 (message (concat (if (nth 2 breakpoint) 3178 (message "%s"
3179 (concat (if (nth 2 breakpoint)
3148 "Temporary " "") 3180 "Temporary " "")
3149 (if (car (cdr breakpoint)) 3181 (if (car (cdr breakpoint))
3150 (format "Condition: %s" 3182 (format "Condition: %s"
3151 (edebug-safe-prin1-to-string 3183 (edebug-safe-prin1-to-string
3152 (car (cdr breakpoint)))) 3184 (car (cdr breakpoint))))
3236 "Global Condition: " 3268 "Global Condition: "
3237 (format "%s" edebug-global-break-condition)))) 3269 (format "%s" edebug-global-break-condition))))
3238 (setq edebug-global-break-condition expression)) 3270 (setq edebug-global-break-condition expression))
3239 3271
3240 3272
3241 ;; Mode switching functions 3273 ;;; Mode switching functions
3242 ;; ===============================
3243 3274
3244 (defun edebug-set-mode (mode shortmsg msg) 3275 (defun edebug-set-mode (mode shortmsg msg)
3245 ;; Set the edebug mode to MODE. 3276 ;; Set the edebug mode to MODE.
3246 ;; Display SHORTMSG, or MSG if not within edebug. 3277 ;; Display SHORTMSG, or MSG if not within edebug.
3247 (if (eq (1+ edebug-recursion-depth) (recursion-depth)) 3278 (if (eq (1+ edebug-recursion-depth) (recursion-depth))
3462 ;; "Go until the current function exits." 3493 ;; "Go until the current function exits."
3463 ;; (interactive) 3494 ;; (interactive)
3464 ;; (edebug-set-mode 'exiting "Exit...")) 3495 ;; (edebug-set-mode 'exiting "Exit..."))
3465 3496
3466 3497
3467 ;; ----------------------------------------------------------------- 3498 ;;; The following initial mode setting definitions are not used yet.
3468 ;; The following initial mode setting definitions are not used yet.
3469 3499
3470 '(defconst edebug-initial-mode-alist 3500 '(defconst edebug-initial-mode-alist
3471 '((edebug-Continue-fast . Continue-fast) 3501 '((edebug-Continue-fast . Continue-fast)
3472 (edebug-Trace-fast . Trace-fast) 3502 (edebug-Trace-fast . Trace-fast)
3473 (edebug-continue . continue) 3503 (edebug-continue . continue)
3508 (message "Initial mode for %s is now: %s" 3538 (message "Initial mode for %s is now: %s"
3509 this-function mode)) 3539 this-function mode))
3510 (error "Key must map to one of the mode changing commands") 3540 (error "Key must map to one of the mode changing commands")
3511 ))) 3541 )))
3512 3542
3513 3543 ;;; Evaluation of expressions
3514 ;; Evaluation of expressions
3515 ;; ===============================
3516 3544
3517 (def-edebug-spec edebug-outside-excursion t) 3545 (def-edebug-spec edebug-outside-excursion t)
3518 3546
3519 (defmacro edebug-outside-excursion (&rest body) 3547 (defmacro edebug-outside-excursion (&rest body)
3520 "Evaluate an expression list in the outside context. 3548 "Evaluate an expression list in the outside context.
3618 (edebug-eval edebug-expr) 3646 (edebug-eval edebug-expr)
3619 (error (edebug-format "%s: %s" ;; could 3647 (error (edebug-format "%s: %s" ;; could
3620 (get (car edebug-err) 'error-message) 3648 (get (car edebug-err) 'error-message)
3621 (car (cdr edebug-err)))))) 3649 (car (cdr edebug-err))))))
3622 3650
3623 ;; Printing 3651 ;;; Printing
3624 ;; ========= 3652
3625 ;; Replace printing functions. 3653 ;; Replace printing functions.
3626 3654
3627 ;; obsolete names 3655 ;; obsolete names
3628 (defalias 'edebug-install-custom-print-funcs 'edebug-install-custom-print) 3656 (defalias 'edebug-install-custom-print-funcs 'edebug-install-custom-print)
3629 (defalias 'edebug-reset-print-funcs 'edebug-uninstall-custom-print) 3657 (defalias 'edebug-reset-print-funcs 'edebug-uninstall-custom-print)
3701 (defun edebug-previous-result () 3729 (defun edebug-previous-result ()
3702 "Print the previous result." 3730 "Print the previous result."
3703 (interactive) 3731 (interactive)
3704 (message "%s" edebug-previous-result)) 3732 (message "%s" edebug-previous-result))
3705 3733
3706 ;; Read, Eval and Print 3734 ;;; Read, Eval and Print
3707 ;; =====================
3708 3735
3709 (defun edebug-eval-expression (edebug-expr) 3736 (defun edebug-eval-expression (edebug-expr)
3710 "Evaluate an expression in the outside environment. 3737 "Evaluate an expression in the outside environment.
3711 If interactive, prompt for the expression. 3738 If interactive, prompt for the expression.
3712 Print result in minibuffer." 3739 Print result in minibuffer."
3735 ;; princ the string to get rid of quotes. 3762 ;; princ the string to get rid of quotes.
3736 (princ edebug-result-string) 3763 (princ edebug-result-string)
3737 (princ "\n") 3764 (princ "\n")
3738 )) 3765 ))
3739 3766
3740 3767 ;;; Edebug Minor Mode
3741 ;; Edebug Minor Mode
3742 ;; ===============================
3743 3768
3744 ;; Global GUD bindings for all emacs-lisp-mode buffers. 3769 ;; Global GUD bindings for all emacs-lisp-mode buffers.
3745 (define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode) 3770 (define-key emacs-lisp-mode-map "\C-x\C-a\C-s" 'edebug-step-mode)
3746 (define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode) 3771 (define-key emacs-lisp-mode-map "\C-x\C-a\C-n" 'edebug-next-mode)
3747 (define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode) 3772 (define-key emacs-lisp-mode-map "\C-x\C-a\C-c" 'edebug-go-mode)
3900 edebug-unwrap-results 3925 edebug-unwrap-results
3901 edebug-global-break-condition 3926 edebug-global-break-condition
3902 " 3927 "
3903 (use-local-map edebug-mode-map)) 3928 (use-local-map edebug-mode-map))
3904 3929
3905 3930 ;;; edebug eval list mode
3906 ;; edebug eval list mode 3931
3907 ;; ===============================================
3908 ;; A list of expressions and their evaluations is displayed in *edebug*. 3932 ;; A list of expressions and their evaluations is displayed in *edebug*.
3909 3933
3910 (defun edebug-eval-result-list () 3934 (defun edebug-eval-result-list ()
3911 "Return a list of evaluations of edebug-eval-list" 3935 "Return a list of evaluations of edebug-eval-list"
3912 ;; Assumes in outside environment. 3936 ;; Assumes in outside environment.
4037 (lisp-interaction-mode) 4061 (lisp-interaction-mode)
4038 (setq major-mode 'edebug-eval-mode) 4062 (setq major-mode 'edebug-eval-mode)
4039 (setq mode-name "Edebug-Eval") 4063 (setq mode-name "Edebug-Eval")
4040 (use-local-map edebug-eval-mode-map)) 4064 (use-local-map edebug-eval-mode-map))
4041 4065
4042 4066 ;;; Interface with standard debugger.
4043 ;; Interface with standard debugger.
4044 ;; ========================================
4045 4067
4046 ;; (setq debugger 'edebug) ; to use the edebug debugger 4068 ;; (setq debugger 'edebug) ; to use the edebug debugger
4047 ;; (setq debugger 'debug) ; use the standard debugger 4069 ;; (setq debugger 'debug) ; use the standard debugger
4048 4070
4049 ;; Note that debug and its utilities must be byte-compiled to work, 4071 ;; Note that debug and its utilities must be byte-compiled to work,
4118 (delete-region last-ok-point (point)) 4140 (delete-region last-ok-point (point))
4119 ))) 4141 )))
4120 ))))) 4142 )))))
4121 4143
4122 4144
4123 ;; Trace display 4145 ;;; Trace display
4124 ;; ===============================
4125 4146
4126 (defun edebug-trace-display (buf-name fmt &rest args) 4147 (defun edebug-trace-display (buf-name fmt &rest args)
4127 "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible. 4148 "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
4128 The buffer is created if it does not exist. 4149 The buffer is created if it does not exist.
4129 You must include newlines in FMT to break lines, but one newline is appended." 4150 You must include newlines in FMT to break lines, but one newline is appended."
4130 ;; e.g. 4151 ;; e.g.
4131 ;; (edebug-trace-display "*trace-point*" 4152 ;; (edebug-trace-display "*trace-point*"
4132 ;; "saving: point = %s window-start = %s" 4153 ;; "saving: point = %s window-start = %s"
4133 ;; (point) (window-start)) 4154 ;; (point) (window-start))
4134 (let* ((selected-window (selected-window)) 4155 (let* ((oldbuf (current-buffer))
4156 (selected-window (selected-window))
4135 (buffer (get-buffer-create buf-name)) 4157 (buffer (get-buffer-create buf-name))
4136 buf-window) 4158 buf-window)
4137 ;; (message "before pop-to-buffer") (sit-for 1) 4159 ;; (message "before pop-to-buffer") (sit-for 1)
4138 (edebug-pop-to-buffer buffer) 4160 (edebug-pop-to-buffer buffer)
4139 (setq truncate-lines t) 4161 (setq truncate-lines t)
4145 (set-window-start buf-window (point)) 4167 (set-window-start buf-window (point))
4146 (goto-char (point-max)) 4168 (goto-char (point-max))
4147 ;; (set-window-point buf-window (point)) 4169 ;; (set-window-point buf-window (point))
4148 ;; (edebug-sit-for 0) 4170 ;; (edebug-sit-for 0)
4149 (bury-buffer buffer) 4171 (bury-buffer buffer)
4150 (select-window selected-window)) 4172 (select-window selected-window)
4173 (set-buffer oldbuf))
4151 buf-name) 4174 buf-name)
4152 4175
4153 4176
4154 (defun edebug-trace (fmt &rest args) 4177 (defun edebug-trace (fmt &rest args)
4155 "Convenience call to edebug-trace-display using edebug-trace-buffer" 4178 "Convenience call to edebug-trace-display using edebug-trace-buffer"
4156 (apply 'edebug-trace-display edebug-trace-buffer fmt args)) 4179 (apply 'edebug-trace-display edebug-trace-buffer fmt args))
4157 4180
4158 4181
4159 ;; Frequency count and coverage 4182 ;;; Frequency count and coverage
4160 ;; ==============================
4161 4183
4162 (defun edebug-display-freq-count () 4184 (defun edebug-display-freq-count ()
4163 "Display the frequency count data for each line of the current 4185 "Display the frequency count data for each line of the current
4164 definition. The frequency counts are inserted as comment lines after 4186 definition. The frequency counts are inserted as comment lines after
4165 each line, and you can undo all insertions with one `undo' command. 4187 each line, and you can undo all insertions with one `undo' command.
4238 (edebug-display-freq-count) 4260 (edebug-display-freq-count)
4239 (setq unread-command-char (read-char)) 4261 (setq unread-command-char (read-char))
4240 (undo))) 4262 (undo)))
4241 4263
4242 4264
4243 ;; Menus 4265 ;;; Menus
4244 ;;=========
4245 4266
4246 (defun edebug-toggle (variable) 4267 (defun edebug-toggle (variable)
4247 (set variable (not (eval variable))) 4268 (set variable (not (eval variable)))
4248 (message "%s: %s" variable (eval variable))) 4269 (message "%s: %s" variable (eval variable)))
4249 4270
4306 (edebug-toggle 'edebug-save-displayed-buffer-points) t] 4327 (edebug-toggle 'edebug-save-displayed-buffer-points) t]
4307 )) 4328 ))
4308 "XEmacs style menus for Edebug.") 4329 "XEmacs style menus for Edebug.")
4309 4330
4310 4331
4311 ;; Emacs version specific code 4332 ;;; Emacs version specific code
4312 ;;============================= 4333
4313 ;; The default for all above is Emacs 18, because it is easier to compile 4334 ;;; The default for all above is Emacs 18, because it is easier to compile
4314 ;; Emacs 18 code in Emacs 19 than vice versa. This default will 4335 ;;; Emacs 18 code in Emacs 19 than vice versa. This default will
4315 ;; change once most people are using Emacs 19 or derivatives. 4336 ;;; change once most people are using Emacs 19 or derivatives.
4316 4337
4317 ;; Epoch specific code is in a separate file: edebug-epoch.el. 4338 ;; Epoch specific code is in a separate file: edebug-epoch.el.
4318 4339
4319 ;; The byte-compiler will complain about changes in number of arguments 4340 ;; The byte-compiler will complain about changes in number of arguments
4320 ;; to functions like mark and read-from-minibuffer. These warnings 4341 ;; to functions like mark and read-from-minibuffer. These warnings
4321 ;; may be ignored because the right call should always be made. 4342 ;; may be ignored because the right call should always be made.
4373 (edebug-outside-excursion 4394 (edebug-outside-excursion
4374 (setq values (cons (edebug-eval edebug-expr) values)) 4395 (setq values (cons (edebug-eval edebug-expr) values))
4375 (edebug-safe-prin1-to-string (car values))))) 4396 (edebug-safe-prin1-to-string (car values)))))
4376 4397
4377 (easy-menu-define edebug-menu edebug-mode-map "Edebug menus" edebug-mode-menus) 4398 (easy-menu-define edebug-menu edebug-mode-map "Edebug menus" edebug-mode-menus)
4378 (if (eq (console-type) 'x) 4399 (if (eq (console-type) 'x) ; XEmacs
4379 (x-popup-menu nil (lookup-key edebug-mode-map [menu-bar Edebug]))) 4400 (x-popup-menu nil (lookup-key edebug-mode-map [menu-bar Edebug])))
4380 ) 4401 )
4381 4402
4382 4403
4383 (defun edebug-xemacs-specific () 4404 (defun edebug-xemacs-specific ()
4417 (edebug-emacs-19-specific)))) 4438 (edebug-emacs-19-specific))))
4418 4439
4419 (edebug-emacs-version-specific) 4440 (edebug-emacs-version-specific)
4420 4441
4421 4442
4422 ;; Byte-compiler 4443 ;;; Byte-compiler
4423 ;; ==================== 4444
4424 ;; Extension for bytecomp to resolve undefined function references. 4445 ;; Extension for bytecomp to resolve undefined function references.
4425 ;; Requires new byte compiler. 4446 ;; Requires new byte compiler.
4426 4447
4427 ;; Reenable byte compiler warnings about unread-command-char and -event. 4448 ;; Reenable byte compiler warnings about unread-command-char and -event.
4428 ;; Disabled before edebug-recursive-edit. 4449 ;; Disabled before edebug-recursive-edit.
4488 ;; XEmacs 4509 ;; XEmacs
4489 zmacs-deactivate-region 4510 zmacs-deactivate-region
4490 popup-menu 4511 popup-menu
4491 ;; CL 4512 ;; CL
4492 cl-macroexpand-all 4513 cl-macroexpand-all
4493 ;; And believe it or not, the byte compiler doesnt know about: 4514 ;; And believe it or not, the byte compiler doesn't know about:
4494 byte-compile-resolve-functions 4515 byte-compile-resolve-functions
4495 )) 4516 ))
4496 4517
4497 '(byte-compile-resolve-free-references 4518 '(byte-compile-resolve-free-references
4498 '(read-expression-history 4519 '(read-expression-history
4502 '(read-expression-history)) 4523 '(read-expression-history))
4503 4524
4504 ))) 4525 )))
4505 4526
4506 4527
4507 ;; Autoloading of Edebug accessories 4528 ;;; Autoloading of Edebug accessories
4508 ;;===================================
4509 4529
4510 (if (featurep 'cl) 4530 (if (featurep 'cl)
4511 (add-hook 'edebug-setup-hook 4531 (add-hook 'edebug-setup-hook
4512 (function (lambda () (require 'cl-specs)))) 4532 (function (lambda () (require 'cl-specs))))
4513 ;; The following causes cl-specs to be loaded if you load cl.el. 4533 ;; The following causes cl-specs to be loaded if you load cl.el.
4521 ;; The following causes edebug-cl-read to be loaded when you load cl-read.el. 4541 ;; The following causes edebug-cl-read to be loaded when you load cl-read.el.
4522 (add-hook 'cl-read-load-hooks 4542 (add-hook 'cl-read-load-hooks
4523 (function (lambda () (require 'edebug-cl-read))))) 4543 (function (lambda () (require 'edebug-cl-read)))))
4524 4544
4525 4545
4526 ;; Finalize Loading 4546 ;;; Finalize Loading
4527 ;;=================== 4547
4528 4548 ;;; Finally, hook edebug into the rest of Emacs.
4529 ;; Finally, hook edebug into the rest of Emacs. 4549 ;;; There are probably some other things that could go here.
4530 ;; There are probably some other things that could go here.
4531 4550
4532 ;; Install edebug read and eval functions. 4551 ;; Install edebug read and eval functions.
4533 (edebug-install-read-eval-functions) 4552 (edebug-install-read-eval-functions)
4534 4553
4535 (provide 'edebug) 4554 (provide 'edebug)