changeset 26325:8523249aaee3

(debug): If noninteractive, display the backtrace using `message', then exit Emacs. (debugger-batch-max-lines): New variable. (debugger-setup-buffer): New subroutine, broken out of `debug'. Change the messages put at the start, to say that the debugger was entered.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 03 Nov 1999 13:43:19 +0000
parents d772d01c5650
children 3a3ec0d0725d
files lisp/emacs-lisp/debug.el
diffstat 1 files changed, 89 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/debug.el	Wed Nov 03 13:39:34 1999 +0000
+++ b/lisp/emacs-lisp/debug.el	Wed Nov 03 13:43:19 1999 +0000
@@ -39,6 +39,14 @@
   :group 'debugger
   :version "20.3")
 
+(defcustom debugger-batch-max-lines 40
+  "*Maximum lines to show in debugger buffer in a noninteractive Emacs.
+When the debugger is entered and Emacs is running in batch mode,
+if the backtrace text has more than this many lines,
+the middle is discarded, and just the beginning and end are displayed."
+  :type 'integer
+  :group 'debugger
+  :version "21.1")
 
 (defcustom debug-function-list nil
   "List of functions currently set for debug on entry."
@@ -87,7 +95,8 @@
 any other args you like.  In that case, the list of args after the
 first will be printed into the backtrace buffer."
   (interactive)
-  (message "Entering debugger...")
+  (unless noninteractive
+    (message "Entering debugger..."))
   (let (debugger-value
 	(debug-on-error nil)
 	(debug-on-quit nil)
@@ -141,56 +150,28 @@
 	  (save-excursion
 	    (save-window-excursion
 	      (pop-to-buffer debugger-buffer)
-	      (setq buffer-read-only nil)
-	      (erase-buffer)
-	      (set-buffer-multibyte nil)
-	      (let ((standard-output (current-buffer))
-		    (print-escape-newlines t)
-		    (print-length 50))
-		(backtrace))
-	      (goto-char (point-min))
 	      (debugger-mode)
-	      (delete-region (point)
-			     (progn
-			       (search-forward "\n  debug(")
-			       (forward-line 1)
-			       (point)))
+	      (debugger-setup-buffer debugger-args)
+	      (when noninteractive
+		;; If the backtrace is long, save the beginning
+		;; and the end, but discard the middle.
+		(when (> (count-lines (point-min) (point-max))
+			 debugger-batch-max-lines)
+		  (goto-char (point-min))
+		  (forward-line (/ 2 debugger-batch-max-lines))
+		  (let ((middlestart (point)))
+		    (goto-char (point-max))
+		    (forward-line (- (/ 2 debugger-batch-max-lines)
+				     debugger-batch-max-lines))
+		    (delete-region middlestart (point)))
+		  (insert "...\n"))
+		(goto-char (point-min))
+		(message (buffer-string))
+		(kill-emacs))
+	      (if (eq (car debugger-args) 'debug)
+		  ;; Skip the frames for backtrace-debug, byte-code, and debug.
+		  (backtrace-debug 3 t))
 	      (debugger-reenable)
-	      ;; lambda is for debug-on-call when a function call is next.
-	      ;; debug is for debug-on-entry function called.
-	      (cond ((memq (car debugger-args) '(lambda debug))
-		     (insert "Entering:\n")
-		     (if (eq (car debugger-args) 'debug)
-			 (progn
-			   ;; Skip the frames for backtrace-debug, byte-code,
-			   ;; and debug.
-			   (backtrace-debug 3 t)
-			   (delete-char 1)
-			   (insert ?*)
-			   (beginning-of-line))))
-		    ;; Exiting a function.
-		    ((eq (car debugger-args) 'exit)
-		     (insert "Return value: ")
-		     (setq debugger-value (nth 1 debugger-args))
-		     (prin1 debugger-value (current-buffer))
-		     (insert ?\n)
-		     (delete-char 1)
-		     (insert ? )
-		     (beginning-of-line))
-		    ;; Debugger entered for an error.
-		    ((eq (car debugger-args) 'error)
-		     (insert "Signaling: ")
-		     (prin1 (nth 1 debugger-args) (current-buffer))
-		     (insert ?\n))
-		    ;; debug-on-call, when the next thing is an eval.
-		    ((eq (car debugger-args) t)
-		     (insert "Beginning evaluation of function call form:\n"))
-		    ;; User calls debug directly.
-		    (t
-		     (prin1 (if (eq (car debugger-args) 'nil)
-				(cdr debugger-args) debugger-args)
-			    (current-buffer))
-		     (insert ?\n)))
 	      (message "")
 	      (let ((inhibit-trace t)
 		    (standard-output nil)
@@ -236,6 +217,58 @@
     (setq debug-on-next-call debugger-step-after-exit)
     debugger-value))
 
+(defun debugger-setup-buffer (debugger-args)
+  "Initialize the `*Backtrace*' buffer for entry to the debugger.
+That buffer should be current already."
+  (setq buffer-read-only nil)
+  (erase-buffer)
+  (set-buffer-multibyte nil)
+  (let ((standard-output (current-buffer))
+	(print-escape-newlines t)
+	(print-level 8)
+	(print-length 50))
+    (backtrace))
+  (goto-char (point-min))
+  (delete-region (point)
+		 (progn
+		   (search-forward "\n  debug(")
+		   (forward-line 1)
+		   (point)))
+  (insert "Debugger entered")
+  ;; lambda is for debug-on-call when a function call is next.
+  ;; debug is for debug-on-entry function called.
+  (cond ((memq (car debugger-args) '(lambda debug))
+	 (insert "--entering a function:\n")
+	 (if (eq (car debugger-args) 'debug)
+	     (progn
+	       (delete-char 1)
+	       (insert ?*)
+	       (beginning-of-line))))
+	;; Exiting a function.
+	((eq (car debugger-args) 'exit)
+	 (insert "--returning value: ")
+	 (setq debugger-value (nth 1 debugger-args))
+	 (prin1 debugger-value (current-buffer))
+	 (insert ?\n)
+	 (delete-char 1)
+	 (insert ? )
+	 (beginning-of-line))
+	;; Debugger entered for an error.
+	((eq (car debugger-args) 'error)
+	 (insert "--Lisp error: ")
+	 (prin1 (nth 1 debugger-args) (current-buffer))
+	 (insert ?\n))
+	;; debug-on-call, when the next thing is an eval.
+	((eq (car debugger-args) t)
+	 (insert "--beginning evaluation of function call form:\n"))
+	;; User calls debug directly.
+	(t
+	 (insert ": ")
+	 (prin1 (if (eq (car debugger-args) 'nil)
+		    (cdr debugger-args) debugger-args)
+		(current-buffer))
+	 (insert ?\n))))
+
 (defun debugger-step-through ()
   "Proceed, stepping through subexpressions of this expression.
 Enter another debugger on next entry to eval, apply or funcall."
@@ -260,6 +293,13 @@
   (prin1 debugger-value)
   (exit-recursive-edit))
 
+;; Chosen empirically to account for all the frames
+;; that will exist when debugger-frame is called
+;; within the first one that appears in the backtrace buffer.
+;; Assumes debugger-frame is called from a key;
+;; will be wrong if it is called with Meta-x.
+(defconst debugger-frame-offset 8 "")
+
 (defun debugger-jump ()
   "Continue to exit from this frame, with all debug-on-entry suspended."
   (interactive)
@@ -311,13 +351,6 @@
 	(setq count (1+ count)))
       count)))
 
-;; Chosen empirically to account for all the frames
-;; that will exist when debugger-frame is called
-;; within the first one that appears in the backtrace buffer.
-;; Assumes debugger-frame is called from a key;
-;; will be wrong if it is called with Meta-x.
-(defconst debugger-frame-offset 8 "")
-
 (defun debugger-frame ()
   "Request entry to debugger when this frame exits.
 Applies to the frame whose line point is on in the backtrace."