From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#69168: [BUG] 30.0.50; pp-emacs-lisp-code produces invalid elisp for backquoted forms Date: Thu, 29 Feb 2024 03:30:12 +0100 Message-ID: <87y1b4vw7f.fsf@web.de> References: <877cj5y1qg.fsf@gmail.com> <87mss1nono.fsf@web.de> <87v86dt9xl.fsf@web.de> <86bk85xd21.fsf@gnu.org> <87le79t1j6.fsf@web.de> Reply-To: Michael Heerdegen Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16269"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 69168@debbugs.gnu.org, Stefan Monnier , iarchivedmywholelife@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 29 03:35:58 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rfWH8-00042u-5y for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Feb 2024 03:35:58 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfWGo-0002EW-PT; Wed, 28 Feb 2024 21:35:38 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfWGm-0002EI-AD for bug-gnu-emacs@gnu.org; Wed, 28 Feb 2024 21:35:36 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfWGm-0007PD-1p for bug-gnu-emacs@gnu.org; Wed, 28 Feb 2024 21:35:36 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rfWHC-0002n7-G8 for bug-gnu-emacs@gnu.org; Wed, 28 Feb 2024 21:36:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Feb 2024 02:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69168 X-GNU-PR-Package: emacs Original-Received: via spool by 69168-submit@debbugs.gnu.org id=B69168.170917413610665 (code B ref 69168); Thu, 29 Feb 2024 02:36:02 +0000 Original-Received: (at 69168) by debbugs.gnu.org; 29 Feb 2024 02:35:36 +0000 Original-Received: from localhost ([127.0.0.1]:39338 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rfWGm-0002lx-5D for submit@debbugs.gnu.org; Wed, 28 Feb 2024 21:35:36 -0500 Original-Received: from mout.web.de ([212.227.15.4]:48325) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rfWGj-0002lW-PZ for 69168@debbugs.gnu.org; Wed, 28 Feb 2024 21:35:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1709174100; x=1709778900; i=michael_heerdegen@web.de; bh=jIA2V1/zsvNmcJWYYVm1xj0Iz/wT3NH7lw09YlUhNd4=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References: Date; b=M2YCF6ODQ4/ILa3lkn6lC/wbnQv20Ma/Sq9PBkeloXqFi2c0Cf4xZauvX+TAsIUu K80g8Ym185gnH+CjmE2PSefXDFohfKyB2iZnxIiU9+gERJXHuobwScyHUkSSRuBiX d+0WcOq8sUyXfnlvLA+4p/insggCOpfcuM/UE7LKTKYU7eECuNBf1L+lmnWtFv8Wb pr/4YKSQ1wydHEb6n68KewUdLHnpE55bSGOevOkrWeSMFM4jEVIxBLHl6K/yJoCjz xEIlaTvIhiltfBczaVnn07b4JEsOVmkA/vBlEs0kAUUe4+ro9SAtOaDknJ2yx+TrQ OZzH+Nsxx3otTNR/aA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([92.76.229.82]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MZjEJ-1rQJ723Eox-00WqTz; Thu, 29 Feb 2024 03:29:43 +0100 In-Reply-To: <87le79t1j6.fsf@web.de> (Michael Heerdegen's message of "Sun, 25 Feb 2024 09:02:05 +0100") X-Provags-ID: V03:K1:efPiNigzPm5d1zTNoaKxmZJdCMTUFsFnmlp4feKt23tYIFn5mew ugaHmgoGzb7SDxmRS7W76kKsUZNlbHolzQF/9bYEUzCBfuUu/Hsb4skK1HuthQPQ0cesGYs wRI2Y9421rm2uNXuZ9DQyXa5iMIKti4NF5H/dB+frIMjUtcHzxo83bf5ts3yKjE0NnPNMtP kK0WAb2s6IchMrvzF5Iag== UI-OutboundReport: notjunk:1;M01:P0:ea4CeJLB+IQ=;5kn5al7Y06dYOCVe8sTNO2xnwA1 AlLoDG7DkXtf8+1d1kS0O0EV2UbAfhnGhNdy8Npson+wbuVcDLrN60PuoZnXWdhsIIjL4BopI 2qsl/00YDLePhbpbZIVnhOs3mfqNgETfmUlHmFDIGvEx18CrHYSxkw7WbSv5ZDqrDnHq5VjTN +vqUy1P5oaWj9By2SAVnq3wlGn1WaZW+uqGI79+pYIhbqavbyoXuC8/E136ZsWctvhkr5fAK9 Xmb4t/706j8wPCxoHRbgSxULmnBnoPNRrq76/gTOIR0m7292PaJlVEKET2kNNSWoSzqnHTjN+ bboNStTMEwaVIaR6bVxp1CaHXp4oBPyQ6Va3cnLF4v++83Ms7XnECdY+jKFZYblg+l/gQvoo2 XQvAoQM8tzf7c+oyyPCPd4EzIS7lWfP9JrF5EspqpRAbd/uRLGewgkUCLsKTJDPOVsrbB/a8c knE/DfVW9uGbFxfku5v1k/Gn5cpzt8wOvqgNIN83XD+fF0nT1YrprpNdfyiP/9thvId4S7kXt FsUNPYvm+u3XP8ksOidsVkuYO/YtC50clXuG/H9aKuDedgzsgIIxg+6RwuFqvDcifcfN9ufQA hbsuJBBHWTjpWg7g7XQ4ciXCwitTMhW3rmY7lL2zF9BGz2P8XY7HbwWbf1Jg3JnfKuTHO1o5X YMLGS7AhGnvkn5ls2bwL1EKYnSKHsj62fcuI8bRQax02ETo6sV6uUuGTxKcWSa+/747/QbeoO AEvzsJD8yKdPYAzhGqgsPFSlRTSMaHThIeGUyPVlFAwJakRSieUrCwGFKAlPYNnXGiaGjGwj X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280780 Archived-At: --=-=-= Content-Type: text/plain Michael Heerdegen writes: > One from me: I'm working on a second patch for pp that will make > printing of backquote forms using the nicer `X syntax. Here is the additional patch. No Wayman, maybe you can try if it gives good results? This change seems quite straightforward, and I tried to avoid to make the code less efficient. For me, it seems to give good results. Please (Eli), if names and comments are bad English, please feel free to suggest a better wording. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-WIP-Improve-pp-emacs-lisp-code-backquote-form-printi.patch Content-Transfer-Encoding: quoted-printable =46rom a6ad2e056b7ac136ac766b1fcdb5f59f2f505e15 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Sun, 18 Feb 2024 01:55:54 +0100 Subject: [PATCH] WIP: Improve pp-emacs-lisp-code backquote form printing * lisp/emacs-lisp/pp.el (pp--quoted-or-unquoted-form-p): New helper function. (pp--insert-lisp): Take care of quoted, backquoted and unquoted expressions; print using an recursive call. (pp--format-list): Exclude more cases from printing as a function call by default. Print lists whose second-last element is an (un)quoting symbol using dotted list syntax; e.g. (a b . ,c) instead of (a b \, c). =2D-- lisp/emacs-lisp/pp.el | 56 ++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el index 944dd750839..045cc171eaa 100644 =2D-- a/lisp/emacs-lisp/pp.el +++ b/lisp/emacs-lisp/pp.el @@ -430,23 +430,33 @@ pp-emacs-lisp-code (replace-match "")) (insert-into-buffer obuf))))) +(defvar pp--quoting-syntaxes + `((quote . "'") + (function . "#'") + (,backquote-backquote-symbol . "`") + (,backquote-unquote-symbol . ",") + (,backquote-splice-symbol . ",@"))) + +(defun pp--quoted-or-unquoted-form-p (cons) + ;; Return non-nil when CONS has one of the forms 'X, `X, ,X or ,@X + (let ((head (car cons))) + (and (symbolp head) + (assq head pp--quoting-syntaxes) + (let ((rest (cdr cons))) + (and (consp rest) (null (cdr rest))))))) + (defun pp--insert-lisp (sexp) (cl-case (type-of sexp) (vector (pp--format-vector sexp)) (cons (cond ((consp (cdr sexp)) - (if (and (length=3D sexp 2) - (memq (car sexp) '(quote function))) - (cond - ((symbolp (cadr sexp)) - (let ((print-quoted t)) - (prin1 sexp (current-buffer)))) - ((consp (cadr sexp)) - (insert (if (eq (car sexp) 'quote) - "'" "#'")) - (pp--format-list (cadr sexp) - (set-marker (make-marker) (1- (point))= )))) - (pp--format-list sexp))) + (let ((head (car sexp))) + (if-let (((null (cddr sexp))) + (syntax-entry (assq head pp--quoting-syntaxes))) + (progn + (insert (cdr syntax-entry)) + (pp--insert-lisp (cadr sexp))) + (pp--format-list sexp)))) (t (prin1 sexp (current-buffer))))) ;; Print some of the smaller integers as characters, perhaps? @@ -470,15 +480,29 @@ pp--format-vector (insert "]")) (defun pp--format-list (sexp &optional start) - (if (and (symbolp (car sexp)) - (not pp--inhibit-function-formatting) - (not (keywordp (car sexp)))) + (if (not (let ((head (car sexp))) + (or pp--inhibit-function-formatting + (not (symbolp head)) + (keywordp head) + (let ((l sexp)) + (catch 'not-funcall + (while l + (when (or + (not (consp l)) ; SEXP is a dotted list + ;; Is SEXP is of a form like (ELT... . ,X) = ? + (pp--quoted-or-unquoted-form-p l)) + (throw 'not-funcall t)) + (setq l (cdr l))) + nil))))) (pp--format-function sexp) (insert "(") (pp--insert start (pop sexp)) (while sexp (if (consp sexp) - (pp--insert " " (pop sexp)) + (if (not (pp--quoted-or-unquoted-form-p sexp)) + (pp--insert " " (pop sexp)) + (pp--insert " . " sexp) + (setq sexp nil)) (pp--insert " . " sexp) (setq sexp nil))) (insert ")"))) =2D- 2.39.2 --=-=-= Content-Type: text/plain Michael. --=-=-=--