]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix cl-print for circular sublists (Bug#31146)
authorNoam Postavsky <npostavs@gmail.com>
Sat, 14 Apr 2018 05:02:25 +0000 (01:02 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Sun, 3 Jun 2018 16:48:13 +0000 (12:48 -0400)
* 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.

(cherry picked from commit b8aa7ecf54c9b164a59f1b0e9f9fe90531dadd20)

lisp/emacs-lisp/cl-print.el
test/lisp/emacs-lisp/cl-print-tests.el

index de41d82671373a02165a60bab58c0697d0aa615e..7c0e81c9349c9ff30725f7e04dfb6c302e2d49b3 100644 (file)
@@ -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
index 660d5c806920057166b6e6b5fbaa06bf2ecb5de7..d986c4015d70d2622f7378ec2ca6dcb7b87382f2 100644 (file)
     (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.