From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id kMG0FyCJfGaFhgEAqHPOHw:P1 (envelope-from ) for ; Wed, 26 Jun 2024 21:33:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id kMG0FyCJfGaFhgEAqHPOHw (envelope-from ) for ; Wed, 26 Jun 2024 23:33:20 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="d2HTX/FB"; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1719437600; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: 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=dWOk9ABYrMCWEhIsmcX3KcyKKq5Zp2NdwPVhy6t7d8o=; b=koyafWt8ZXsXTBsvcXcVoxxL4IdXDlcflh2wuH8INKwoeXIHsaiKu+dJfiigxYhp+CRugY xJW6c8kYLDPvaJb8j5SfZ0b4BeMb71vUPH658FMhkTY271vXh/AE+affE+YQerKUt9UVdL rW7ythV/4TUMcFjScg+WEF0WqxKvARwLsuidyNPxHxfvWglg8JNrGETvMSHSZFdzRXIV1T iiHfESCozuwtDlW9AU+9q7ib7gl04nvprXaV70vP4L1849cTdJ7LqSYcluA+knEkIPM1lD ZMbZ2mYL1Utoo92OvM7zgBOAIwijRnf6SBYQEbZv0bJZzsskpDCcvPX8nK9kCQ== 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="d2HTX/FB"; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1719437600; a=rsa-sha256; cv=none; b=KiwDbHZZNjkiXoDb+dtPKxfCP7rmxeXWqt/Fv9+O694xdmYd81CTOc+gbhkVLfqsdoXm1U EX7Q2vzY/tAoTiLYAUhir50wLgywCrEDPS/yw+AR+nr7IhvRREZIE7YbMQnsZhgrE3v5My N7YVSjuExqD73NnBRfNo8sTRXE7CSCZ78ozUKTWwHKzs1Z/OtAHJ0qdawfdXZ1JO1Oh3Cl 9HZvzCrciOx/44g/UocvNfTg1jN1tTt4PBV8YLKnxcNV9+Z3bHR4Fm0ziTvjl1OOVaUGzz D6uLVu/lp4YiAvNMDmBBXBYbKW+DEg/ScZbDvn1vwq2k2+INDf4zAjI0ZCQoIw== 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 EFDDB229D7 for ; Wed, 26 Jun 2024 23:33:19 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMaGE-0004mV-Pn; Wed, 26 Jun 2024 17:33:02 -0400 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 1sMaGC-0004mC-O4 for guix-patches@gnu.org; Wed, 26 Jun 2024 17:33:00 -0400 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 1sMaGB-0006Gm-GC for guix-patches@gnu.org; Wed, 26 Jun 2024 17:33:00 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sMaGD-0001uA-Pq for guix-patches@gnu.org; Wed, 26 Jun 2024 17:33:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70800] [PATCH] scripts: style: Add 'order' option to alphabetically order file. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 26 Jun 2024 21:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70800 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Herman Rimm Cc: 70800@debbugs.gnu.org, Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , Ricardo Wurmus , Christopher Baines Received: via spool by 70800-submit@debbugs.gnu.org id=B70800.17194375447278 (code B ref 70800); Wed, 26 Jun 2024 21:33:01 +0000 Received: (at 70800) by debbugs.gnu.org; 26 Jun 2024 21:32:24 +0000 Received: from localhost ([127.0.0.1]:40479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMaFc-0001tH-0f for submit@debbugs.gnu.org; Wed, 26 Jun 2024 17:32:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57854) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sMaFZ-0001t3-CH for 70800@debbugs.gnu.org; Wed, 26 Jun 2024 17:32:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sMaFO-0006BW-5H; Wed, 26 Jun 2024 17:32:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=dWOk9ABYrMCWEhIsmcX3KcyKKq5Zp2NdwPVhy6t7d8o=; b=d2HTX/FBS2fNYclmcWLf 2qSnWGKxIpIM92t3XWlOf8j9BPOGlzEzowMbTUBOOqXU48bTVyDtGtYyZ60DeULFhE0SbR8+Zatsj ToVEnGrzgVtj0QyeN0GalsCOu9cIuTCbx6Rkkt9aq2+pm/aVKC0B9+9rRMcdszj3zlEDQqGGPGVhd 3ZcRNWLtwZrNtgtxEe29VixUg7NEFPYJrTLgA1DemCo+9UB+PY3aBN6uyrjP3MpN4AQPnxwG3T7RA jb4teYHFEH5uTKMmG6hzDa8wmXUIQb+QmmPhlt7bUoKD4WKNEcAaVtX+xKkj2dFKkR9Pu5Ussvi5E Q/V0aRC/6g/gkw==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <875xv20yhq.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Sat, 25 May 2024 16:14:57 +0200") References: <8e0df2707343eaee0bf39fa06fcdd5bc5cd9fba2.1714992109.git.herman@rimm.ee> <875xv20yhq.fsf@gnu.org> Date: Wed, 26 Jun 2024 23:32:05 +0200 Message-ID: <87y16r9yqy.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -5.77 X-Migadu-Queue-Id: EFDDB229D7 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -5.77 X-TUID: 2lm9MssFJn9Y Hi Herman, Did you have a chance to look into this? Let us know if anything looks unclear or questionable to you. Thanks, Ludo=E2=80=99. Ludovic Court=C3=A8s skribis: > Herman Rimm skribis: > >> * guix/scripts/style.scm (show-help): Describe option. >> (order-packages): Add procedure. >> (format-whole-file): Add 'order?' argument. >> (%options): Add 'order' option. >> (guix-style): Alphabetically order packages in files. >> * doc/guix.texi (Invoking guix style): Document option. >> >> Change-Id: I4aa7c0bd0b6d42529ae7d304587ffb10bf5f4006 > > Yay! > >> I managed to create a procedure which alphabetically sorts top-level >> package definitions. Sort is not stable as I understand it, so versions >> of packages get swapped. It works well enough in small package modules, >> and should not be a problem once package versions are used in sorting. > > Maybe use =E2=80=98stable-sort=E2=80=99 instead of =E2=80=98sort=E2=80=99? > > Overall LGTM; some suggestions below: > >> +(define (order-packages lst) >> + "Place top-level package definitions in LST in alphabetical order." > > =E2=80=9CReturn LST, a list of top-level expressions and blanks, with top= -level > package definitions in alphabetical order.=E2=80=9D > >> + ;; Group define-public with preceding blanks and defines. >> + (let* ((lst (identity > > I=E2=80=99d drop =E2=80=98identity=E2=80=99. > >> + (package-name (lambda (pkg) >> + (match pkg >> + ((('define-public _ expr) _ ...) >> + (match expr >> + ((or ('package _ ('name name) _ ...) >> + ('package ('name name) _ ...)) >> + name) >> + (_ #f))) >> + (_ #f)))) > > Nitpick: I=E2=80=99d make this an inner =E2=80=98define=E2=80=99 in =E2= =80=98order-packages=E2=80=99, right > below the docstring. > >> + (lst (sort lst (lambda (lst1 lst2) >> + (let ((name1 (package-name lst1)) >> + (name2 (package-name lst2))) >> + (and name1 name2 (string> name1 name2))))))) >> + (reverse (concatenate lst)))) > > Maybe replace =E2=80=98string>=E2=80=99 by =E2=80=98string >> + (option '(#\o "order") #f #f >> + (lambda (opt name arg result) >> + (alist-cons 'order? #t result))) > > I=E2=80=99d avoid =E2=80=98-o=E2=80=99 for this because it=E2=80=99s usua= lly synonymous with =E2=80=98output=E2=80=99. > > But maybe make it =E2=80=98-A=E2=80=99/=E2=80=98--alphabetical-sort=E2=80= =99? > >> (display (G_ " >> - -l, --list-stylings display the list of available style rules")) >> + -l, --list-stylings display the list of available style rules")) > > Oops. :-) > >> + (for-each format-whole-file >> + files (map (const (assoc-ref opts 'order?)) files= ))) > > I=E2=80=99d go with something less inventive here: > > (for-each (cute format-whole-file <> (assoc-ref opts 'order?)) > files) > > Could you send an updated patch? > > Thank you! > > Ludo=E2=80=99.