From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id yLyrM7XyUWaXEgEAA41jLg (envelope-from ) for ; Sat, 25 May 2024 16:16:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id kEuFMLXyUWYaKAAA62LTzQ (envelope-from ) for ; Sat, 25 May 2024 16:16:21 +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=F2Sq3Bpv; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1716646581; a=rsa-sha256; cv=none; b=MPcRPDV1SdclIGrDNRVG1M8lyTYzkBr/AruEVP7JomxmPs3HxoqKdMgkS0H4t8+OhY+ono 7LzH5ijUVOwlNH6X16uBIlKOUKQZe2jSvZSpsRbie1k3QqtMOVhQEOCXacASrF6bZndGSG B+7sgIEtV5uIxciDX/tFzyWo52PcVwY1QvjWGfDXSNkYRFtcVcMZk9jwVm+zPC/KwdQNCJ 2m5X0pym6U/9/muRGHhP6j8YADq66b9oU2mSvZId02+y6fGkeHafRlbbhNseFWJ3KSDJ91 VbOjTnKMHgpkU9IdU7CanlS+j8mRyzq3SoKLNAvCZUDaNAFU0FXwrO8ilnpwhw== 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=F2Sq3Bpv; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1716646581; 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=U2oFtY6DngiY94kSAXJaOcKuy9uhaDTCjb7BYYfLe7E=; b=HyaJQEjOHGUMUBoiXuCitbSCBDDaMhUCJOaaJspWSLAGPo6pu82auxB6LmrljB8UEB1c3b nZuwI8ehJkVDMA3bQhY/xTR54L99Z6ULymYo17cA1YDoGzCrtMx9++4hLexFr+Y/FwnnaR IA/dJJy/2VOG/+7V0HSFmCVlfUblMRz8QXBD/rbesvCa5fm2PGWeDTB1l0wW/veM1IY6cN iWM0b4E37pixORe7hyH0yXZ0XAGK0lAHG4+E7CDovR1iSVTVWPIpjj/i6cDEY2TR/WEBix y7iAiA7l6hx3DSkJQc880t7JJYt2+kVu3qZBM5InZP1f9S4XMsScoFLGCen7pg== 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 AB6361B204 for ; Sat, 25 May 2024 16:16:21 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAsBp-00014f-3I; Sat, 25 May 2024 10:16:05 -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 1sAsBf-00013o-0l for guix-patches@gnu.org; Sat, 25 May 2024 10:15:55 -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 1sAsBe-0003W6-7e for guix-patches@gnu.org; Sat, 25 May 2024 10:15:54 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sAsBl-0000do-Nf for guix-patches@gnu.org; Sat, 25 May 2024 10:16: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: Sat, 25 May 2024 14:16: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.17166465322376 (code B ref 70800); Sat, 25 May 2024 14:16:01 +0000 Received: (at 70800) by debbugs.gnu.org; 25 May 2024 14:15:32 +0000 Received: from localhost ([127.0.0.1]:43685 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAsBH-0000cF-Vv for submit@debbugs.gnu.org; Sat, 25 May 2024 10:15:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAsBF-0000bp-US for 70800@debbugs.gnu.org; Sat, 25 May 2024 10:15:30 -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 1sAsB0-0003Li-9c; Sat, 25 May 2024 10:15:14 -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=U2oFtY6DngiY94kSAXJaOcKuy9uhaDTCjb7BYYfLe7E=; b=F2Sq3Bpv3SdkNBR+Sd49 8UbVGbniRsGeBeHfqhaKU23Sy0WL24JMeC2YxjbDby37SPlqPyQorC+ciQ11q6ERv0H6qYbzQtj6b tq2o9l92y0Njiv0Mat+XxqN/miSZkRgeEBJ6upkOPXvSveAQc00BltdPmV7xyWbXc5TafMVp9lC42 6xSzz9ZCdfi7K2rYc2Fkorc7aJAoJCmwYLkCXBmd5hYMP9/8DNlxaklMk4mFimkLwFDQ35v/k8nyr UZsp4dWqWkXmiTo9az2SMwjQDSW5eITFbEaVwDRUf8EHRXN1boAQWXn7W+/ymZPOrj6SHFX+kY4cm 5QS/64prQEbYlg==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <8e0df2707343eaee0bf39fa06fcdd5bc5cd9fba2.1714992109.git.herman@rimm.ee> (Herman Rimm's message of "Mon, 6 May 2024 12:50:34 +0200") References: <8e0df2707343eaee0bf39fa06fcdd5bc5cd9fba2.1714992109.git.herman@rimm.ee> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Septidi 7 Prairial an 232 de la =?UTF-8?Q?R=C3=A9volution, ?= jour du Fromental X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Sat, 25 May 2024 16:14:57 +0200 Message-ID: <875xv20yhq.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-Migadu-Queue-Id: AB6361B204 X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -5.75 X-Spam-Score: -5.75 X-TUID: tGBiYnBYDvwP 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-l= evel 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 usuall= y 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.