unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Thuna <thuna.cing@gmail.com>
To: 72434@debbugs.gnu.org
Subject: bug#72434: [PATCH] Print list-ending comma/backquote forms specially
Date: Sat, 03 Aug 2024 03:31:28 +0200	[thread overview]
Message-ID: <87ikwimlxr.fsf@gmail.com> (raw)

[-- 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


             reply	other threads:[~2024-08-03  1:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-03  1:31 Thuna [this message]
2024-08-03  1:44 ` bug#72434: [PATCH] Print list-ending comma/backquote forms specially Thuna

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ikwimlxr.fsf@gmail.com \
    --to=thuna.cing@gmail.com \
    --cc=72434@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).