Fix cl-print for circular sublists (Bug#31146)
* lisp/emacs-lisp/cl-print.el (cl-print-object) <cons>: Push each element of list being printed onto cl-print--currently-printing. * test/lisp/emacs-lisp/cl-print-tests.el (cl-print-circle-2): New test.
This commit is contained in:
parent
a92e7b4ef6
commit
b8aa7ecf54
2 changed files with 16 additions and 3 deletions
|
@ -62,9 +62,12 @@ call other entry points instead, such as `cl-prin1'."
|
|||
(princ "(" stream)
|
||||
(cl-print-object car stream)
|
||||
(while (and (consp object)
|
||||
(not (if cl-print--number-table
|
||||
(numberp (gethash object cl-print--number-table))
|
||||
(memq object cl-print--currently-printing))))
|
||||
(not (cond
|
||||
(cl-print--number-table
|
||||
(numberp (gethash object cl-print--number-table)))
|
||||
((memq object cl-print--currently-printing))
|
||||
(t (push object cl-print--currently-printing)
|
||||
nil))))
|
||||
(princ " " stream)
|
||||
(cl-print-object (pop object) stream))
|
||||
(when object
|
||||
|
|
|
@ -55,4 +55,14 @@
|
|||
(let ((print-circle t))
|
||||
(should (equal "(#1=(a . #1#) #1#)" (cl-prin1-to-string x))))))
|
||||
|
||||
(ert-deftest cl-print-circle-2 ()
|
||||
;; Bug#31146.
|
||||
(let ((x '(0 . #1=(0 . #1#))))
|
||||
(let ((print-circle nil))
|
||||
(should (string-match "\\`(0 0 . #[0-9])\\'"
|
||||
(cl-prin1-to-string x))))
|
||||
(let ((print-circle t))
|
||||
(should (equal "(0 . #1=(0 . #1#))" (cl-prin1-to-string x))))))
|
||||
|
||||
|
||||
;;; cl-print-tests.el ends here.
|
||||
|
|
Loading…
Add table
Reference in a new issue