From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AMDkKHeb6WLr/wAAbAwnHQ (envelope-from ) for ; Tue, 02 Aug 2022 23:47:35 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id CHPAKHeb6WKPMgEAauVa8A (envelope-from ) for ; Tue, 02 Aug 2022 23:47:35 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 437403D052 for ; Tue, 2 Aug 2022 23:47:35 +0200 (CEST) Received: from localhost ([::1]:33008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIzji-00047Z-39 for larch@yhetil.org; Tue, 02 Aug 2022 17:47:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzhJ-0001xs-Pb for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzhJ-0006Qh-Fs for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oIzhJ-0003AH-D3 for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56898] [PATCH 11/13] read-print: Support printing multi-line comments. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 02 Aug 2022 21:45:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56898 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56898@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 56898-submit@debbugs.gnu.org id=B56898.165947668512031 (code B ref 56898); Tue, 02 Aug 2022 21:45:05 +0000 Received: (at 56898) by debbugs.gnu.org; 2 Aug 2022 21:44:45 +0000 Received: from localhost ([127.0.0.1]:45295 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgz-00037s-8t for submit@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59588) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgt-00035h-BH for 56898@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:40 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55170) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzgo-0006AT-3r; Tue, 02 Aug 2022 17:44:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=Uu20pag2ZjXZAsB2uO02hiBMS5iRlVv/Ghp+wid3TO0=; b=D/bwoI7pbITG3gwaubxh iPAykjtbXM8cF8POlYRmCX17ThcW/IpfOCxWkVzIgiPTm+4rXMNNB88ysZLJUkfjtgkBtNw/ooQ7e pDKVzlLJMwj5vEsFDiF9LdlPFYcysLQsdZMT+bBz+xIMSk+hlSghEHaK6IayHFJw5to+XPzwE3wCF LVX3pkDG7xPdB2dyWfgwhmAcrcazO3DmA0bxpSAW15bSFce6PlBWqd2DPui7LHYFkm8QIFumrQjK2 JSE3foM8Zj3DclnreHv4icMz78t81okFEspu30wT1eLMCvgGRu9g3PGQFk69v2jtHr66/O5pETCcJ dvvCHE/mN/OKVg==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:52235 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzgn-0006W4-O0; Tue, 02 Aug 2022 17:44:33 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 2 Aug 2022 23:44:17 +0200 Message-Id: <20220802214419.19013-11-ludo@gnu.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220802214419.19013-1-ludo@gnu.org> References: <20220802214419.19013-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659476855; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Uu20pag2ZjXZAsB2uO02hiBMS5iRlVv/Ghp+wid3TO0=; b=r3whKvN2Pbpf+lhdChKTkvAuLQetzqa6FfjYDZotQGmm4vxdB8MZ9zkIrcywLZZkK/Vg3t AKdoY5ZPC+pXlkIDr76JF0VgQiDvzyQDNNxHhtpFBk2Zt2YDyHcJaua8SEDQ/VUs2XZ/Il 0SZjCUCqJvVoY2GxQw9dJeb0mT1RAA/JwO+1U/irJSM374X0Kjx0+s/+sPWckeGLm071Wu D6Hr7ARby59RBJNx6dpmWv8hdPHlMGab0KCvWVVasIc2bvWpcJ7p9sJJse/tll6GKKSFJh ElMx9zZIbrwVJXsuapJtQ9L4tMgOInYEM1KSgGnVJYvVgBUDV4Nse/AJMVr0sA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659476855; a=rsa-sha256; cv=none; b=KZe/gcAk+DO7VDm4lTjqXfz1g8kUGl8pFvUMdbRIVWDE2FHhlq9+mLsmuVqINWyOzVmPM6 La41DYMqzLCFhJSSsc9F+b4lFJvKSKMYkNcndnObe6rlmlk7ZdIQt5dHEr7oXxjVYPZT0X LT3T1XbABwaHhX/pmFfYT8754Nvf3/7cVMueT99ctSNGsaj57o7fo9boKZYukg4mqhoeud bygv1ImVCayPQKZ4Q1nxwb8VTaXDd91VnVhj3HP/pvgWDfGP5gHYfl/C+0oNIt0AJG3UT4 HCsu501JG6nVti86fbmbAhQ0hca4hNDnCACQfoY7ZwojE6VPBD4pgFp7dY2flA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="D/bwoI7p"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.82 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="D/bwoI7p"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 437403D052 X-Spam-Score: -2.82 X-Migadu-Scanner: scn0.migadu.com X-TUID: OKpt7ZXAPMKy * guix/read-print.scm (%not-newline): New variable. (print-multi-line-comment): New procedure. (pretty-print-with-comments): Use it. * tests/read-print.scm ("pretty-print-with-comments, multi-line comment"): New test. --- guix/read-print.scm | 26 ++++++++++++++++++++++++-- tests/read-print.scm | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/guix/read-print.scm b/guix/read-print.scm index 2fc3d85a25..df25eb0f50 100644 --- a/guix/read-print.scm +++ b/guix/read-print.scm @@ -387,6 +387,27 @@ (define (canonicalize-comment comment indent) line "\n") (comment-margin? comment))))) +(define %not-newline + (char-set-complement (char-set #\newline))) + +(define (print-multi-line-comment str indent port) + "Print to PORT STR as a multi-line comment, with INDENT spaces preceding +each line except the first one (they're assumed to be already there)." + + ;; While 'read-with-comments' only returns one-line comments, user-provided + ;; comments might span multiple lines, which is why this is necessary. + (let loop ((lst (string-tokenize str %not-newline))) + (match lst + (() #t) + ((last) + (display last port) + (newline port)) + ((head tail ...) + (display head port) + (newline port) + (display (make-string indent #\space) port) + (loop tail))))) + (define* (pretty-print-with-comments port obj #:key (format-comment @@ -486,8 +507,9 @@ (define (special-form? head) (unless (= column indent) (newline port) (display (make-string indent #\space) port)) - (display (comment->string (format-comment comment indent)) - port))) + (print-multi-line-comment (comment->string + (format-comment comment indent)) + indent port))) (display (make-string indent #\space) port) indent) ((? vertical-space? space) diff --git a/tests/read-print.scm b/tests/read-print.scm index e3f23194af..004fcff19f 100644 --- a/tests/read-print.scm +++ b/tests/read-print.scm @@ -341,4 +341,18 @@ (define-module (foo bar) #:format-vertical-space canonicalize-vertical-space))))) +(test-equal "pretty-print-with-comments, multi-line comment" + "\ +(list abc + ;; This comment spans + ;; two lines. + def)" + (call-with-output-string + (lambda (port) + (pretty-print-with-comments port + `(list abc ,(comment "\ +;; This comment spans\n +;; two lines.\n") + def))))) + (test-end) -- 2.37.1