all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#31649: 26.1; cl-prin1 doesn't print #' and ignores print-quoted
@ 2018-05-30  0:34 Gemini Lasswell
  2018-06-05  1:03 ` Noam Postavsky
  0 siblings, 1 reply; 4+ messages in thread
From: Gemini Lasswell @ 2018-05-30  0:34 UTC (permalink / raw)
  To: 31649

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

CL printing doesn't observe the print variable print-quoted and always
prints #'foo as (function foo).

To reproduce, execute the following code (I used emacs -Q and IELM):

(let ((quoted-stuff '('a #'b `(,c ,@d))))
  (let ((print-quoted t))
    (cl-prin1 quoted-stuff) (terpri)
    (prin1 quoted-stuff) (terpri))
  (let ((print-quoted nil))
    (cl-prin1 quoted-stuff) (terpri)
    (prin1 quoted-stuff) (terpri)))

Results:
('a (function b) `(,c ,@d))
('a #'b `(,c ,@d))
('a (function b) `(,c ,@d))
((quote a) (function b) (\` ((\, c) (\,@ d))))

I expect cl-prin1 and prin1 to do the same thing in this example.

Here's a patch to make cl-prin1 behave like prin1:


[-- Attachment #2: 0001-Make-cl-print-respect-print-quoted.patch --]
[-- Type: text/plain, Size: 2382 bytes --]

From 99b24a7dc7472d04e6de43fb48f45869a272c26c Mon Sep 17 00:00:00 2001
From: Gemini Lasswell <gazally@runbox.com>
Date: Tue, 29 May 2018 11:41:09 -0700
Subject: [PATCH] Make cl-print respect print-quoted

* lisp/emacs-lisp/cl-print.el (cl-print-object) <cons>: Print quote
and its relatives as lists if print-quoted is nil. Add printing of
'function' as #'.
* test/lisp/emacs-lisp/cl-print-tests.el (cl-print-tests-5): New test.
---
 lisp/emacs-lisp/cl-print.el            |  9 +++++++--
 test/lisp/emacs-lisp/cl-print-tests.el | 10 ++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el
index 55e2bf8bd4..1eae8faf23 100644
--- a/lisp/emacs-lisp/cl-print.el
+++ b/lisp/emacs-lisp/cl-print.el
@@ -61,11 +61,16 @@ cl-print--depth
       (princ "..." stream)
     (let ((car (pop object))
           (count 1))
-      (if (and (memq car '(\, quote \` \,@ \,.))
+      (if (and print-quoted
+               (memq car '(\, quote function \` \,@ \,.))
                (consp object)
                (null (cdr object)))
           (progn
-            (princ (if (eq car 'quote) '\' car) stream)
+            (princ (cond
+                    ((eq car 'quote) '\')
+                    ((eq car 'function) "#'")
+                    (t car))
+                   stream)
             (cl-print-object (car object) stream))
         (princ "(" stream)
         (cl-print-object car stream)
diff --git a/test/lisp/emacs-lisp/cl-print-tests.el b/test/lisp/emacs-lisp/cl-print-tests.el
index bfce4a16ce..404d323d0c 100644
--- a/test/lisp/emacs-lisp/cl-print-tests.el
+++ b/test/lisp/emacs-lisp/cl-print-tests.el
@@ -72,6 +72,16 @@
     (should (equal "#s(cl-print-tests-struct :a (a (b (c ...))) :b nil :c nil :d nil :e nil)"
                    (cl-prin1-to-string deep-struct)))))
 
+(ert-deftest cl-print-tests-5 ()
+  "CL printing observes `print-quoted'."
+  (let ((quoted-stuff '('a #'b `(,c ,@d))))
+    (let ((print-quoted t))
+      (should (equal "('a #'b `(,c ,@d))"
+                     (cl-prin1-to-string quoted-stuff))))
+    (let ((print-quoted nil))
+      (should (equal "((quote a) (function b) (\\` ((\\, c) (\\,@ d))))"
+                     (cl-prin1-to-string quoted-stuff))))))
+
 (ert-deftest cl-print-circle ()
   (let ((x '(#1=(a . #1#) #1#)))
     (let ((print-circle nil))
-- 
2.16.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#31649: 26.1; cl-prin1 doesn't print #' and ignores print-quoted
  2018-05-30  0:34 bug#31649: 26.1; cl-prin1 doesn't print #' and ignores print-quoted Gemini Lasswell
@ 2018-06-05  1:03 ` Noam Postavsky
  2018-06-05  3:31   ` Gemini Lasswell
  0 siblings, 1 reply; 4+ messages in thread
From: Noam Postavsky @ 2018-06-05  1:03 UTC (permalink / raw)
  To: Gemini Lasswell; +Cc: 31649

severity 31649 minor
quit

Gemini Lasswell <gazally@runbox.com> writes:

> Subject: [PATCH] Make cl-print respect print-quoted

Looks good to me.  Just a minor nitpick about the message:

> * lisp/emacs-lisp/cl-print.el (cl-print-object) <cons>: Print quote
> and its relatives as lists if print-quoted is nil. Add printing of
                                                    ^
                                                    double space

I don't think "as lists" is the right description, maybe "with read
syntax".








^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#31649: 26.1; cl-prin1 doesn't print #' and ignores print-quoted
  2018-06-05  1:03 ` Noam Postavsky
@ 2018-06-05  3:31   ` Gemini Lasswell
  2018-06-05 11:51     ` Noam Postavsky
  0 siblings, 1 reply; 4+ messages in thread
From: Gemini Lasswell @ 2018-06-05  3:31 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 31649

Noam Postavsky <npostavs@gmail.com> writes:

>> * lisp/emacs-lisp/cl-print.el (cl-print-object) <cons>: Print quote
>> and its relatives as lists if print-quoted is nil. Add printing of
>                                                     ^
>                                                     double space
>
> I don't think "as lists" is the right description, maybe "with read
> syntax".

I'll fix the message. Should this go in master or emacs-26?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#31649: 26.1; cl-prin1 doesn't print #' and ignores print-quoted
  2018-06-05  3:31   ` Gemini Lasswell
@ 2018-06-05 11:51     ` Noam Postavsky
  0 siblings, 0 replies; 4+ messages in thread
From: Noam Postavsky @ 2018-06-05 11:51 UTC (permalink / raw)
  To: Gemini Lasswell; +Cc: 31649

Gemini Lasswell <gazally@runbox.com> writes:

> Noam Postavsky <npostavs@gmail.com> writes:
>
>>> * lisp/emacs-lisp/cl-print.el (cl-print-object) <cons>: Print quote
>>> and its relatives as lists if print-quoted is nil. Add printing of
>>                                                     ^
>>                                                     double space
>>
>> I don't think "as lists" is the right description, maybe "with read
>> syntax".
>
> I'll fix the message. Should this go in master or emacs-26?

I'd call this a bug/deficiency in a new feature, so emacs-26.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-05 11:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-30  0:34 bug#31649: 26.1; cl-prin1 doesn't print #' and ignores print-quoted Gemini Lasswell
2018-06-05  1:03 ` Noam Postavsky
2018-06-05  3:31   ` Gemini Lasswell
2018-06-05 11:51     ` Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.