unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#72434: [PATCH] Print list-ending comma/backquote forms specially
@ 2024-08-03  1:31 Thuna
  2024-08-03  1:44 ` Thuna
  0 siblings, 1 reply; 2+ messages in thread
From: Thuna @ 2024-08-03  1:31 UTC (permalink / raw)
  To: 72434

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

(This patch follows from 72334, but that patch is not necessary for this
one to work.)

Currently something like the following (unevaluated) form:
  `(foo bar . ,baz)
prints as
  `(foo bar \, baz)
which, while technically accurate, is not helpful.  This comes up quite
often in pcase forms where a pattern like `(,head . ,_) is extremely
common.

This patch fixes that, such that if the tail of a list is a proper list
of two elements whose car is a backquote, comma, or comma-at (so ,foo
,@foo and `foo), and print-quoted is non-nil, the printed text will be
in the first form above.

Better ways to implement this are likely possible; this was simply the
easiest and quickest one.  Feel free to change the patch as needed.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Print-list-terminating-backquote-and-comma-forms-spe.patch --]
[-- Type: text/x-patch, Size: 1023 bytes --]

From 4cea5d48a772870df40f7d33fc0a87cdcfc9bbc1 Mon Sep 17 00:00:00 2001
From: Thuna <thuna.cing@gmail.com>
Date: Sat, 3 Aug 2024 03:17:49 +0200
Subject: [PATCH] Print list terminating backquote and comma forms specially

* src/print.c (print_object): When `print-quoted' is non-nil print a
list-terminating (\` obj) as though it terminates the list with a " . "
---
 src/print.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/print.c b/src/print.c
index 256f19aeb90..d654ab76799 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2656,7 +2656,13 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
 		--print_depth;
 		goto next_obj;
 	      }
-	    else if (CONSP (next))
+	    else if (CONSP (next)
+		     && !(print_quoted
+			  && (EQ (Qbackquote, XCAR (next))
+			      || EQ (Qcomma, XCAR (next))
+			      || EQ (Qcomma_at, XCAR (next)))
+			  && CONSP (XCDR (next))
+			  && NILP (XCDR (XCDR (next)))))
 	      {
 		if (!NILP (Vprint_circle))
 		  {
-- 
2.44.2


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

* bug#72434: [PATCH] Print list-ending comma/backquote forms specially
  2024-08-03  1:31 bug#72434: [PATCH] Print list-ending comma/backquote forms specially Thuna
@ 2024-08-03  1:44 ` Thuna
  0 siblings, 0 replies; 2+ messages in thread
From: Thuna @ 2024-08-03  1:44 UTC (permalink / raw)
  To: 72434


> (This patch follows from 72334, but that patch is not necessary for this
> one to work.)

Actually, that is incorrect...-ish.  The specific problem happens when
you encounter a comma or comma-at while not inside a backquote.  With
72334 this is not a problem, but without it you end up with the
(unevaluated) form
  (foo bar . ,baz)
printed as
  (foo bar . (\, baz))
which is obviously not ideal.

It /should/ be possible to lightly change the patch to have it work, by
checking `new_backquote_output' in case the car is a comma or a comma-at
but honestly I would just rather 72334 be pushed instead.






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

end of thread, other threads:[~2024-08-03  1:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-03  1:31 bug#72434: [PATCH] Print list-ending comma/backquote forms specially Thuna
2024-08-03  1:44 ` Thuna

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).