From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4EgqG1Kb6WJ/FQAAbAwnHQ (envelope-from ) for ; Tue, 02 Aug 2022 23:46:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id iI4FG1Kb6WLtQgAAauVa8A (envelope-from ) for ; Tue, 02 Aug 2022 23:46:58 +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 305A48CDC for ; Tue, 2 Aug 2022 23:46:58 +0200 (CEST) Received: from localhost ([::1]:60288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIzj7-0003Rl-B1 for larch@yhetil.org; Tue, 02 Aug 2022 17:46:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzhJ-0001xB-AU for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oIzhJ-0006QY-0t 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 1oIzhI-0003A9-U2 for guix-patches@gnu.org; Tue, 02 Aug 2022 17:45:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56898] [PATCH 09/13] read-print: 'canonicalize-comment' leaves top-level comments unchanged. 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:04 +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.165947668512023 (code B ref 56898); Tue, 02 Aug 2022 21:45:04 +0000 Received: (at 56898) by debbugs.gnu.org; 2 Aug 2022 21:44:45 +0000 Received: from localhost ([127.0.0.1]:45293 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgy-00037l-SH for submit@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59580) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oIzgs-00035e-Fg for 56898@debbugs.gnu.org; Tue, 02 Aug 2022 17:44:38 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIzgm-0006A9-U8; Tue, 02 Aug 2022 17:44:32 -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=gB9ZTp7URun+su0eqU4MpFljdsqgu/OtWTeD0CuD8AI=; b=hW5ZeySLY/TvtlsuATfo g0b3ECKB8PAeTXf1cdOkiFg+F0bfHXqZ1iM29ADlgpGU4biFGC9PIIZ/KCA3IaR5R/8oF3881emEx PSVIESKsaYJBRU26B12DQkbwA65km+vbjY4lqrcx0tQxbX2YFonJRYh/fjOioYy2Zjuo06fO9gaSx 9LTC4PV6LHCsBjn2BjM7xG4602VK4PVWWfFcAd23LovBjtWfXoCcYieRZqV/aQez1qQVWXTcNaaua OTknafl7WlE7x1jaKK14mkXFPpBPJWLY56cdvtOZ80RWqWKJ7qjIEt/hKtiuKTQ3+MH5kE4RWRcra goRJDhOQKZPqng==; 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 1oIzgm-0006W4-GU; Tue, 02 Aug 2022 17:44:32 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 2 Aug 2022 23:44:15 +0200 Message-Id: <20220802214419.19013-9-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=1659476818; 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=gB9ZTp7URun+su0eqU4MpFljdsqgu/OtWTeD0CuD8AI=; b=nSH1D7fTSEaNtpis/yRZqaE2ouZvuBAXhmj/Cx8+ZaUPotaf4X5FEaiVwsh+Xx95aUnKn5 9EjV+AWfzhZ9xZYGiPlF8Lem0Lx8bhvvbux03z7vlPD+cAfhM+XsZTvNrfKNRJRBa8lx0P eadG9U/0QAZ4/IAJvVKfY+iqZMWeqbXyz7bYdjbEMG/017FgKxxJsdzl0vpJCLIyhtS9po Ytov9MYEFtBn5luSPmR+PBEGbj7P/WUX91cdK6E7FiEhNctmTptK2GZ+zChfdaBagOj/8U hClBDVx6ip6OZhrYM9IVm5xNnEigifZe8OzS/dsXSOXjNDVsK5BWmHlGpjJS0A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659476818; a=rsa-sha256; cv=none; b=uIefZaGT+7FpFaD2uBpPCs4RnHIy3erAOPaCe0TwVstCknwrFcKhruTCiEYSglPjW8ZM13 IAWEYRF6C7ashp9QzXq6BEJoeV5WQzxVMxn/133hM4oDKyYnndkEQrGV76Yshf6Z2G4gJ0 Pvo58qPpZ410xhtU162M2qN+4qn6PpO5rsTXGaTPd0mKisnBxWZVRRNCXQJswOybiHoRFu cB3I9JG61L6sWrrqHqClNYThrWQlgINGTmn+E0EX3qdybUfYn46CKlExgjPjNrPoav/R22 hzk149nTqrOhr0PotbvnMk39WX0kZWP6wPmddwEdSy6WkMEGhFwSWzWAKDVZOA== 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=hW5ZeySL; 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=hW5ZeySL; 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: 305A48CDC X-Spam-Score: -2.82 X-Migadu-Scanner: scn0.migadu.com X-TUID: TlO7MMSMN+e7 This lets users use three leading semicolons, for instance, in top-level comments. * guix/read-print.scm (canonicalize-comment): Add INDENT parameter and honor it. (pretty-print-with-comments): Change default value of #:format-comment. Call FORMAT-COMMENT with INDENT as the second argument. * tests/read-print.scm: Adjust test accordingly. --- guix/read-print.scm | 35 +++++++++++++++++++---------------- tests/read-print.scm | 4 +++- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/guix/read-print.scm b/guix/read-print.scm index 4a3afdd4f9..2fc3d85a25 100644 --- a/guix/read-print.scm +++ b/guix/read-print.scm @@ -371,23 +371,26 @@ (define (string-width str) "Return the \"width\" of STR--i.e., the width of the longest line of STR." (apply max (map string-length (string-split str #\newline)))) -(define (canonicalize-comment c) - "Canonicalize comment C, ensuring it has the \"right\" number of leading -semicolons." - (let ((line (string-trim-both - (string-trim (comment->string c) (char-set #\;))))) - (string->comment (string-append - (if (comment-margin? c) - ";" - (if (string-null? line) - ";;" ;no trailing space - ";; ")) - line "\n") - (comment-margin? c)))) +(define (canonicalize-comment comment indent) + "Canonicalize COMMENT, which is to be printed at INDENT, ensuring it has the +\"right\" number of leading semicolons." + (if (zero? indent) + comment ;leave top-level comments unchanged + (let ((line (string-trim-both + (string-trim (comment->string comment) (char-set #\;))))) + (string->comment (string-append + (if (comment-margin? comment) + ";" + (if (string-null? line) + ";;" ;no trailing space + ";; ")) + line "\n") + (comment-margin? comment))))) (define* (pretty-print-with-comments port obj #:key - (format-comment identity) + (format-comment + (lambda (comment indent) comment)) (format-vertical-space identity) (indent 0) (max-width 78) @@ -475,7 +478,7 @@ (define (special-form? head) (if (comment-margin? comment) (begin (display " " port) - (display (comment->string (format-comment comment)) + (display (comment->string (format-comment comment indent)) port)) (begin ;; When already at the beginning of a line, for example because @@ -483,7 +486,7 @@ (define (special-form? head) (unless (= column indent) (newline port) (display (make-string indent #\space) port)) - (display (comment->string (format-comment comment)) + (display (comment->string (format-comment comment indent)) port))) (display (make-string indent #\space) port) indent) diff --git a/tests/read-print.scm b/tests/read-print.scm index 94f018dd44..e3f23194af 100644 --- a/tests/read-print.scm +++ b/tests/read-print.scm @@ -274,6 +274,7 @@ (define-syntax-rule (test-pretty-print/sequence str args ...) (test-pretty-print/sequence " ;;; Hello! +;;; Notice that there are three semicolons here. (define-module (foo bar) #:use-module (guix) @@ -286,7 +287,8 @@ (define-module (foo bar) (locale \"eo_EO.UTF-8\") (services - (cons (service mcron-service-type) %base-services)))\n") + (cons (service mcron-service-type) %base-services)))\n" + #:format-comment canonicalize-comment) (test-equal "pretty-print-with-comments, canonicalize-comment" "\ -- 2.37.1