X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Friece-debug.el;h=abe461c99adaada5f02dcc230297b9a153fe569d;hb=c25472a32afa906719ebb03c81bbc2f0d34d6abf;hp=2a301a4922f9629fad541e130dc2e0a32618ca80;hpb=f5c32b354870fd4d16eabad94d83e5d4e89ce0fb;p=riece diff --git a/lisp/riece-debug.el b/lisp/riece-debug.el index 2a301a4..abe461c 100644 --- a/lisp/riece-debug.el +++ b/lisp/riece-debug.el @@ -25,29 +25,31 @@ ;;; Code: (require 'riece-globals) - -(defvar riece-debug-standard-output-buffer nil) +(require 'riece-options) (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*"))) + "Reset `riece-temp-buffer' to be used as `standard-output'." (save-excursion - (set-buffer riece-debug-standard-output-buffer) + (set-buffer riece-temp-buffer) (buffer-disable-undo) (erase-buffer))) (defmacro riece-debug-with-backtrace (&rest body) + "Execute BODY and send a backtrace to `riece-temp-buffer'." `(unwind-protect (progn ,@body) (riece-debug-reset-standard-output) - (let ((standard-output riece-debug-standard-output-buffer)) + (let ((standard-output riece-temp-buffer)) (backtrace)))) (put 'riece-debug-with-backtrace 'lisp-indent-function 0) (put 'riece-debug-with-backtrace 'edebug-form-spec '(form body)) (defmacro riece-ignore-errors (location &rest body) + "Execute BODY; if an error occurs, return nil. +Otherwise, return result of last FORM. +If `riece-debug' is non-nil and an error occurred, it sends a +backtrace to standard-output." `(condition-case error (if riece-debug (riece-debug-with-backtrace ,@body) @@ -55,7 +57,8 @@ (error (if riece-debug (save-excursion - (set-buffer riece-debug-standard-output-buffer) + (set-buffer riece-temp-buffer) + (goto-char (point-min)) (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)))) @@ -64,6 +67,14 @@ (put 'riece-ignore-errors 'lisp-indent-function 1) (put 'riece-ignore-errors 'edebug-form-spec '(form body)) +(defun riece-funcall-ignore-errors (location function &rest args) + "Call FUNCTION with ARGS; if an error occurs, return nil. +Otherwise, return result of the function. +If `riece-debug' is non-nil and an error occurred, it sends a +backtrace to standard-output." + (riece-ignore-errors location + (apply function args))) + (provide 'riece-debug) ;;; riece-debug.el ends here