From f260bf0dccaa036b169b63a1475a7b8ef312f2da Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Wed, 2 Feb 2005 04:50:15 +0000 Subject: [PATCH] Send standard-output to a buffer. --- lisp/riece-debug.el | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lisp/riece-debug.el b/lisp/riece-debug.el index 24b7f57..fb422a5 100644 --- a/lisp/riece-debug.el +++ b/lisp/riece-debug.el @@ -24,28 +24,22 @@ ;;; Code: -(defvar riece-debug-standard-output - (make-string 4096 ?\x0)) +(defvar riece-debug-standard-output-buffer nil) -(defvar riece-debug-standard-output-index 0) - -(defun riece-debug-standard-output (character) - (let ((length (length riece-debug-standard-output))) - (if (= riece-debug-standard-output-index length) - (setq riece-debug-standard-output - (concat riece-debug-standard-output - (make-string length ?\x0)))) - (aset riece-debug-standard-output - riece-debug-standard-output-index - character) - (setq riece-debug-standard-output-index - (1+ riece-debug-standard-output-index)))) +(defun riece-debug-reset-standard-output () + (unless riece-debug-standard-output-buffer + (setq riece-debug-standard-output-buffer + (generate-new-buffer " *riece-debug-standard-output*"))) + (save-excursion + (set-buffer riece-debug-standard-output-buffer) + (buffer-disable-undo) + (erase-buffer))) (defmacro riece-debug-with-backtrace (&rest body) `(unwind-protect (progn ,@body) - (setq riece-debug-standard-output-index 0) - (let ((standard-output #'riece-debug-standard-output)) + (riece-debug-reset-standard-output) + (let ((standard-output riece-debug-standard-output-buffer)) (backtrace)))) (put 'riece-debug-with-backtrace 'lisp-indent-function 0) @@ -58,11 +52,11 @@ ,@body) (error (if riece-debug - (let ((backtrace (substring riece-debug-standard-output - 0 riece-debug-standard-output-index))) - (if (string-match "^ signal(" backtrace) - (setq backtrace (substring backtrace 0 (match-beginning 0)))) - (message "Error in `%s': %S\n%s" ,location error backtrace))) + (save-excursion + (set-buffer riece-debug-standard-output-buffer) + (if (re-search-forward "^ signal(" nil t) + (delete-region (point-min) (match-beginning 0))) + (message "Error in `%s': %S\n%s" ,location error (buffer-string)))) nil))) (put 'riece-ignore-errors 'lisp-indent-function 1) -- 2.25.1