commit c527d0a9f66b50c28dfc44b88c5dd634c770ade2
parent 5681a5df8e157d0dae9c99df5455755353a68c8b
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Sat, 31 Mar 2018 19:40:30 +0100
Use the default Emacs pretty-printer
This is generally more robust, faster, with more attractive results.
Also gracefully handle the user quitting during
pretty-printing (common for large lists like load-history).
Diffstat:
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -19,6 +19,9 @@ being linkified.
Fixed an issue where the definition of interactively defined functions
wasn't shown.
+Pretty-printing is now much more robust, gracefully handling very
+large lists.
+
# v0.8
Added setting `helpful-switch-buffer-function` to allow users to
diff --git a/helpful.el b/helpful.el
@@ -152,12 +152,15 @@ To disable cleanup entirely, set this variable to nil. See also
(defun helpful--pretty-print (value)
"Pretty-print VALUE.
-Break lists over large lines, and ensure strings are surrounded
-with double-quotes."
- (with-temp-buffer
- (delay-mode-hooks (lisp-mode))
- (cl-prettyprint value)
- (s-trim (buffer-string))))
+
+If VALUE is self-referential, or just very big, the user may
+press \\[keyboard-quit] to gracefully stop the printing."
+ ;; Inspired by `ielm-eval-input'.
+ (condition-case nil
+ (s-trim-right (pp-to-string value))
+ (quit
+ (propertize "(User quit during pretty-printing.)"
+ 'face 'font-lock-comment-face))))
(defun helpful--button (text type &rest properties)
;; `make-text-button' mutates our string to add properties. Copy