X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-debug.el;h=cddd944d93e8aa3b8a8f3903c9903f922ef51521;hp=fb422a523cbfe26e79a07cb295fb0f52a560aedb;hb=3052cb04a561ff5617e886c2b5454f7795946e54;hpb=f260bf0dccaa036b169b63a1475a7b8ef312f2da diff --git a/lisp/riece-debug.el b/lisp/riece-debug.el index fb422a5..cddd944 100644 --- a/lisp/riece-debug.el +++ b/lisp/riece-debug.el @@ -24,28 +24,48 @@ ;;; Code: -(defvar riece-debug-standard-output-buffer nil) +(require 'riece-globals) +(require 'riece-options) + +(defun riece-debug-1 (message detail) + (message "riece-debug: %s" message) + (save-excursion + (set-buffer riece-debug-buffer) + (goto-char (point-max)) + (let ((time (format-time-string "%Y-%m-%d:%H:%M:%S"))) + (if detail + (insert "*** " time ": " message "\n" detail "\n") + (insert "*** " time ": " message "\n"))))) + +(defun riece-debug (message &optional detail) + "Print a one-line debug MESSAGE at the bottom of the frame. +If the optional 2nd argument DETAIL is specified, it is stored into +`riece-debug-buffer'." + (ignore (riece-debug-1 message detail))) (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) @@ -53,15 +73,25 @@ (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)))) + (riece-debug (format "Error in `%s': %S" ,location error) + (buffer-string)))) nil))) (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