branch: externals/trie commit defa7e0a219f804e7e3b7cf857fc8c9e055c38de Author: tsc25 <toby-predict...@dr-qubit.org> Commit: Toby S. Cubitt <toby-predict...@dr-qubit.org>
Replaced advice with cedet-edebug.el for pretty-printing tries and dictionaries in edebug. --- trie.el | 82 ++++++++--------------------------------------------------------- 1 file changed, 9 insertions(+), 73 deletions(-) diff --git a/trie.el b/trie.el index 7dce69d..e43dbc9 100644 --- a/trie.el +++ b/trie.el @@ -1883,87 +1883,23 @@ elements that matched the corresponding groups, in order." ;; ---------------------------------------------------------------- -;; Pretty-print tries during edebug +;; Pretty-print tries during edebug -;; Note: -;; ----- - -;; We advise the `edebug-prin1' and `edebug-prin1-to-string' functions -;; (actually, aliases) so that they pring "#<trie>" instead of the full -;; print form for tries. +;; We use `cedet-edebug-add-print-override' from cedet-edebug.el to make +;; edebug print "#<trie>" instead of the full print form for +;; tries. (This is cleaner than using aliases or advice.) ;; ;; This is because, if left to its own devices, edebug hangs for ages ;; whilst printing large tries, and you either have to wait for a *very* ;; long time for it to finish, or kill Emacs entirely. (Even C-g C-g -;; fails!) -;; -;; Since the print form of a trie is practically incomprehensible -;; anyway, we don't lose much by doing this. If you *really* want to -;; print tries in full whilst edebugging, despite this warning, disable -;; the advice. -;; -;; FIXME: Should use `cedet-edebug-prin1-extensions' instead of advice -;; when `cedet-edebug' is loaded, though I believe this still -;; works in that case. - - -(eval-when-compile - (require 'edebug) - (require 'advice)) - - -(defun trie--edebug-pretty-print (object) - (cond - ((trie-p object) "#<trie>") - ((consp object) - (if (consp (cdr object)) - (let ((pretty "(")) - (while object - (setq pretty - (concat pretty - (trie--edebug-pretty-print - (if (atom object) - (prog1 - (trie--edebug-pretty-print object) - (setq object nil)) - (pop object))) - (when object " ")))) - (concat pretty ")")) - (concat "(" (trie--edebug-pretty-print (car object)) - " . " (trie--edebug-pretty-print (cdr object)) ")"))) - ((vectorp object) - (let ((pretty "[") (len (length object))) - (dotimes (i (1- len)) - (setq pretty - (concat pretty - (trie--edebug-pretty-print (aref object i)) - " "))) - (concat pretty - (trie--edebug-pretty-print (aref object (1- len))) - "]"))) - (t (prin1-to-string object)))) - - -(ad-define-subr-args 'edebug-prin1 '(object &optional printcharfun)) - -(defadvice edebug-prin1 - (around trie activate compile preactivate) - (let ((pretty (trie--edebug-pretty-print object))) - (if pretty - (progn - (prin1 pretty printcharfun) - (setq ad-return-value pretty)) - ad-do-it))) +;; fails!) Since the print form of a trie is practically +;; incomprehensible anyway, we don't lose much by doing this. +(require 'cedet-edebug) -(ad-define-subr-args 'edebug-prin1-to-string '(object &optional noescape)) +(defun trie-pretty-print (trie) "#<trie>") -(defadvice edebug-prin1-to-string - (around trie activate compile preactivate) - (let ((pretty (trie--edebug-pretty-print object))) - (if pretty - (setq ad-return-value pretty) - ad-do-it))) +(cedet-edebug-add-print-override 'trie-p 'trie-pretty-print)