Undo the last change.
[elisp/riece.git] / lisp / riece-debug.el
1 ;;; riece-debug.el --- debug support
2 ;; Copyright (C) 1998-2005 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'riece-globals)
28
29 (defvar riece-debug-standard-output-buffer nil)
30
31 (defun riece-debug-reset-standard-output ()
32   (unless riece-debug-standard-output-buffer
33     (setq riece-debug-standard-output-buffer
34           (generate-new-buffer " *riece-debug-standard-output*")))
35   (save-excursion
36     (set-buffer riece-debug-standard-output-buffer)
37     (buffer-disable-undo)
38     (erase-buffer)))
39
40 (defmacro riece-debug-with-backtrace (&rest body)
41   `(unwind-protect
42        (progn ,@body)
43      (riece-debug-reset-standard-output)
44      (let ((standard-output riece-debug-standard-output-buffer))
45        (backtrace))))
46
47 (put 'riece-debug-with-backtrace 'lisp-indent-function 0)
48 (put 'riece-debug-with-backtrace 'edebug-form-spec '(form body))
49
50 (defmacro riece-ignore-errors (location &rest body)
51   `(condition-case error
52        (if riece-debug
53            (riece-debug-with-backtrace ,@body)
54          ,@body)
55      (error
56       (if riece-debug
57           (save-excursion
58             (set-buffer riece-debug-standard-output-buffer)
59             (if (re-search-forward "^  signal(" nil t)
60                 (delete-region (point-min) (match-beginning 0)))
61             (message "Error in `%s': %S\n%s" ,location error (buffer-string))))
62       nil)))
63
64 (put 'riece-ignore-errors 'lisp-indent-function 1)
65 (put 'riece-ignore-errors 'edebug-form-spec '(form body))
66
67 (provide 'riece-debug)
68
69 ;;; riece-debug.el ends here