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 ms0.migadu.com with LMTPS id YPA4NTfd0mFm9QAAgWs5BA (envelope-from ) for ; Mon, 03 Jan 2022 12:25:43 +0100 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 uJngMTfd0mH9RQEAauVa8A (envelope-from ) for ; Mon, 03 Jan 2022 12:25:43 +0100 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 E70C224BBF for ; Mon, 3 Jan 2022 12:25:42 +0100 (CET) Received: from localhost ([::1]:46386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4LTC-0005NV-0X for larch@yhetil.org; Mon, 03 Jan 2022 06:25:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4LSt-0005J8-Gx for guix-patches@gnu.org; Mon, 03 Jan 2022 06:25:23 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:50958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4LSa-0001pB-T5 for guix-patches@gnu.org; Mon, 03 Jan 2022 06:25:19 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n4LSa-0005wh-MP for guix-patches@gnu.org; Mon, 03 Jan 2022 06:25:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52974] [PATCH 5/5] style: '-S format' canonicalizes comments. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 03 Jan 2022 11:25:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52974 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52974@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 52974-submit@debbugs.gnu.org id=B52974.164120910222819 (code B ref 52974); Mon, 03 Jan 2022 11:25:04 +0000 Received: (at 52974) by debbugs.gnu.org; 3 Jan 2022 11:25:02 +0000 Received: from localhost ([127.0.0.1]:34266 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n4LSX-0005vj-Ni for submit@debbugs.gnu.org; Mon, 03 Jan 2022 06:25:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n4LSU-0005uX-G8 for 52974@debbugs.gnu.org; Mon, 03 Jan 2022 06:24:58 -0500 Received: from [2001:470:142:3::e] (port=49194 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4LSP-0001l2-8B; Mon, 03 Jan 2022 06:24:53 -0500 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=wal42SYyj0LkuDwPy6Fz9nJewU+f00OX+CSsDjilEuE=; b=C/rJ1MXCBp4qogJUwMC+ hXUVfAEd19K8W6IgaS05Qo4MUV8Alq/3qznl1CMYGXX6KkvULzhLGti1IGqtDBqfqGM/GNzWl7dxp SDGxBlsbACnv4f8nQXXIkyXpCzo7W68dhpw3UHTJyDWeWaywOAbmf/XVlflxwML82rxS3tyacl3By uxN0V3xGeG9dT13RGUSTA8g+BzMFSS+3VJqdJsBx1LQfCpmq75MNv+c2d8rIrQR7Hnv1gn0gISrYk T7jtUBGbRTcx9LD+J/VYc5i95tsTVKHDRt87Bc77p6K5o5XVtyQSR6hVYGf41SzD5l/6NbElcM7e6 dluFbmCnQvhQBg==; Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=42680 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 1n4LSP-0005n0-Bm; Mon, 03 Jan 2022 06:24:53 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 3 Jan 2022 12:24:39 +0100 Message-Id: <20220103112439.14377-5-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220103112439.14377-1-ludo@gnu.org> References: <20220103112439.14377-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-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641209143; 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=QhZih700GhwChr507mlDbKb4qrryWRd/xE2YM5FcImo=; b=oo1gNS1Sb+585Fjq0mJgxYtBrxiDCf6wSGEHG9NbzoWbJMlAA77NRkaDtkHd09tJ7tjOsM 6bDxxQOe+cLH/2TjrfNBrVAdZPGaBOJRaCmeld+GOx657Xul/6eJAyImXJrM074ENrhnDh yBUXC4cBwV2eoW2rC4w/8o8SB0rGhNeCs/lkRLDuXXd3kN7CsWhs9Bv40KECLil5cQEY7R pyHekuLxT+OJJgxU7h4cn8H8C+UKhPh4twSrzdHB0rG+UD8U1scrapXKzXAp7Mar2wCxwz KYzMPpUlzLhVt3M2l7EPimE6ffZvkEtGKMyH2gkdtwx/pohU6UxnvD+5KRaM7w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641209143; a=rsa-sha256; cv=none; b=g6eTEtse16NcZetaEPqDDAOfo97zPbVZYwVCYAe3ITkcj53Ia1lOfWTddBRVcjVrwoeb/W 6coUNy4ObPDcY4+Wpl8nhzqb+s+HGq3S8qUZZAGRmQEdWep4V49m/fVhUix3nFSOcmRuk5 FEWCXUVRsGTNQSSSf3dCQSOcOBppeJRXXwVJL61/W1A8W8dLY8+3O+oJaIu53egZqSpXFV Lrn5Qwp9GUuu2VzCjcLE41Mz8qlfc/OU3evK1bFpoRNX//e1bxjmNpMA3zf/ojvCkfpmvQ ZaDtVTT5oCe+jnPl6uQxLCE2l+NyYRWDO21MZkPkp/pE7WdzHTNxYmFs9EHFLg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b="C/rJ1MXC"; 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.29 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b="C/rJ1MXC"; 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: E70C224BBF X-Spam-Score: -2.29 X-Migadu-Scanner: scn1.migadu.com X-TUID: +sKbSDK3m+8q * guix/scripts/style.scm (canonicalize-comment): New procedure. (pretty-print-with-comments): Add #:format-comment. and honor it. (object->string*): Add 'args' and honor them. (format-package-definition): Pass #:format-comment to 'object->string*'. * tests/style.scm ("pretty-print-with-comments, canonicalize-comment"): New test. --- guix/scripts/style.scm | 36 +++++++++++++++++++++++++++++------- tests/style.scm | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm index 47549c7e4a..3c83265f8d 100644 --- a/guix/scripts/style.scm +++ b/guix/scripts/style.scm @@ -47,6 +47,7 @@ (define-module (guix scripts style) #:use-module (srfi srfi-37) #:export (pretty-print-with-comments read-with-comments + canonicalize-comment guix-style)) @@ -226,8 +227,23 @@ (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 #\;))))) + (comment (string-append + (if (comment-margin? c) + ";" + (if (string-null? line) + ";;" ;no trailing space + ";; ")) + line "\n") + (comment-margin? c)))) + (define* (pretty-print-with-comments port obj #:key + (format-comment identity) (indent 0) (max-width 78) (long-list 5)) @@ -235,7 +251,9 @@ (define* (pretty-print-with-comments port obj and assuming the current column is INDENT. Comments present in OBJ are included in the output. -Lists longer than LONG-LIST are written as one element per line." +Lists longer than LONG-LIST are written as one element per line. Comments are +passed through FORMAT-COMMENT before being emitted; a useful value for +FORMAT-COMMENT is 'canonicalize-comment'." (let loop ((indent indent) (column indent) (delimited? #t) ;true if comes after a delimiter @@ -300,14 +318,16 @@ (define (special-form? head) (if (comment-margin? comment) (begin (display " " port) - (display (comment->string comment) port)) + (display (comment->string (format-comment comment)) + port)) (begin ;; When already at the beginning of a line, for example because ;; COMMENT follows a margin comment, no need to emit a newline. (unless (= column indent) (newline port) (display (make-string indent #\space) port)) - (display (comment->string comment) port))) + (display (comment->string (format-comment comment)) + port))) (display (make-string indent #\space) port) indent) (('quote lst) @@ -442,11 +462,12 @@ (define new-column (display str port) (+ column (if delimited? 0 1) len)))))))) -(define (object->string* obj indent) +(define (object->string* obj indent . args) (call-with-output-string (lambda (port) - (pretty-print-with-comments port obj - #:indent indent)))) + (apply pretty-print-with-comments port obj + #:indent indent + args)))) ;;; @@ -706,7 +727,8 @@ (define* (format-package-definition package read-with-comments))) (object->string* exp (location-column - (package-definition-location package))))))) + (package-definition-location package)) + #:format-comment canonicalize-comment))))) (define (package-location