[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bug-hunter ba63f00 42/95: Use pretty-printing on values
From: |
Stefan Monnier |
Subject: |
[elpa] externals/bug-hunter ba63f00 42/95: Use pretty-printing on values |
Date: |
Fri, 27 Nov 2020 22:06:53 -0500 (EST) |
branch: externals/bug-hunter
commit ba63f000554a60e4c5fd3d39e7d7a4e624b87b61
Author: Artur Malabarba <bruce.connor.am@gmail.com>
Commit: Artur Malabarba <bruce.connor.am@gmail.com>
Use pretty-printing on values
---
bug-hunter.el | 96 ++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 62 insertions(+), 34 deletions(-)
diff --git a/bug-hunter.el b/bug-hunter.el
index 4683f7d..01a6d81 100644
--- a/bug-hunter.el
+++ b/bug-hunter.el
@@ -98,6 +98,8 @@ file.")
(goto-char (point-min))
(bug-hunter--read-buffer)))
+
+;;; Reporting functions
(defun bug-hunter--report-print (&rest r)
(with-current-buffer (get-buffer-create "*Bug-Hunter Report*")
(goto-char (point-max))
@@ -109,12 +111,72 @@ file.")
(apply #'bug-hunter--report-print r)
(apply #'message r))
+(defun bug-hunter--report-value (value padding)
+ (declare (indent 1))
+ (bug-hunter--report
+ (with-temp-buffer
+ (pp value (current-buffer))
+ (goto-char (point-min))
+ (let ((pad (make-string padding ?\s)))
+ (while (not (eobp))
+ (insert pad)
+ (forward-line 1)))
+ (buffer-string))))
+
(defun bug-hunter--report-user-error (&rest r)
(declare (indent 1))
(apply #'bug-hunter--report-print r)
(bug-hunter--report-print "")
(apply #'user-error r))
+(defun bug-hunter--init-report-buffer ()
+ (or (get-buffer "*Bug-Hunter Report*")
+ (with-current-buffer (get-buffer-create "*Bug-Hunter Report*")
+ (compilation-mode)
+ (set (make-local-variable 'compilation-error-regexp-alist)
+ '(comma))
+ (current-buffer))))
+
+(defun bug-hunter--pretty-format (value padding)
+ "Return a VALUE as a string with PADDING spaces on the left."
+ (with-temp-buffer
+ (pp value (current-buffer))
+ (goto-char (point-min))
+ (let ((pad (make-string padding ?\s)))
+ (while (not (eobp))
+ (insert pad)
+ (forward-line 1)))
+ (buffer-string)))
+
+(defun bug-hunter--report-error (line column error &optional expression)
+ (bug-hunter--report "%S, line %s pos %s:"
+ bug-hunter--current-file line column)
+ (bug-hunter--report " %s"
+ (cl-case (car error)
+ (end-of-file
+ "There's a missing closing parenthesis, the expression on this line
never ends.")
+ (invalid-read-syntax
+ (let ((char (second error)))
+ (if (member char '("]" ")"))
+ (concat "There's an extra " char
+ " on this position. There's probably a missing "
+ (if (string= char ")") "(" "[")
+ " before that.")
+ (concat "There's a " char
+ " on this position, and that is not valid elisp syntax."))))
+ (assertion-triggered
+ (concat "The assertion returned the following value here:\n"
+ (bug-hunter--pretty-format (second error) 4)))
+ (t (format "The following error was signaled here:\n %S"
+ error))))
+ (when expression
+ (bug-hunter--report " Caused by the following expression:\n%s"
+ (bug-hunter--pretty-format expression 4)))
+ (bug-hunter--report "")
+ `[,line ,column ,error ,expression])
+
+
+;;; Execution functions
(defun bug-hunter--run-form (form)
"Run FUNCTION with \"emacs -Q\" and return the result."
(let ((out-buf (generate-new-buffer "*Bug-Hunter Command*"))
@@ -149,13 +211,6 @@ See `bug-hunter' for a description on the ASSERTION."
,assertion)
(error (cons 'bug-caught er)))))
-(defun bug-hunter--init-report-buffer ()
- (or (get-buffer "*Bug-Hunter Report*")
- (with-current-buffer (get-buffer-create "*Bug-Hunter Report*")
- (compilation-mode)
- (set (make-local-variable 'compilation-error-regexp-alist)
- '(comma))
- (current-buffer))))
;;; The actual bisection
@@ -195,33 +250,6 @@ signal an error and value is (bug-caught .
ERROR-SIGNALED)."
(bug-hunter--estimate (ceiling (log (length forms) 2))))
(apply #'bug-hunter--bisect assertion nil (bug-hunter--split forms))))
-(defun bug-hunter--report-error (line column error &optional expression)
- (bug-hunter--report "%S, line %s pos %s:"
- bug-hunter--current-file line column)
- (bug-hunter--report " %s\n"
- (cl-case (car error)
- (end-of-file
- "There's a missing closing parenthesis, the expression on this line
never ends.")
- (invalid-read-syntax
- (let ((char (second error)))
- (if (member char '("]" ")"))
- (concat "There's an extra " char
- " on this position. There's probably a missing "
- (if (string= char ")") "(" "[")
- " before that.")
- (concat "There's a " char
- " on this position, and that is not valid elisp syntax."))))
- (assertion-triggered
- (format "The assertion returned the following value here:\n %S"
- (cdr error)))
- (t (format "The following error was signaled here:\n %S"
- error))))
- (when expression
- (bug-hunter--report " Caused by the following expression:\n %s"
- expression))
- (bug-hunter--report "")
- `[,line ,column ,error ,expression])
-
;;; Main functions
(defun bug-hunter-hunt (rich-forms assertion)
- [elpa] externals/bug-hunter 130cc12 45/95: Report what we can when the user aborts., (continued)
- [elpa] externals/bug-hunter 130cc12 45/95: Report what we can when the user aborts., Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 53a74dd 46/95: Whitespace, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter a4ba22d 49/95: checkdoc, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 91e1fea 50/95: Better Readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 5927de0 51/95: More verbose messages., Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 8d2d20e 63/95: Extended readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 1232c89 64/95: Don't assume Emacs 24.4. Fix #5, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter c796137 69/95: bug-hunter--run-and-test accepts an 'interactive assertion, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter d0f2034 73/95: Use -q when running interactively too., Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 2650778 93/95: Fix #17 - Minibuffer completion pre 25, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter ba63f00 42/95: Use pretty-printing on values,
Stefan Monnier <=
- [elpa] externals/bug-hunter c819db8 47/95: Call-process instead of shell-command., Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 45811c4 52/95: Fix tests, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 08d95ed 56/95: Update email and GH username., Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 0df2a48 53/95: Provide, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter da07f04 61/95: minor typo fixes, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 6c56fc3 80/95: Fix frame -> instance, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 05aace5 48/95: Invert argument order in report-error, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter e81cfe7 54/95: readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter b44c8a3 59/95: Simpler test, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 42bdc9f 62/95: Fix travis badge, Stefan Monnier, 2020/11/27