From: "Ludovic Courtès" <ludo@gnu.org>
To: Herman Rimm <herman@rimm.ee>
Cc: 70800@debbugs.gnu.org, Josselin Poiret <dev@jpoiret.xyz>,
Simon Tournier <zimon.toutoune@gmail.com>,
Mathieu Othacehe <othacehe@gnu.org>,
Tobias Geerinckx-Rice <me@tobias.gr>,
Ricardo Wurmus <rekado@elephly.net>,
Christopher Baines <guix@cbaines.net>
Subject: [bug#70800] [PATCH] scripts: style: Add 'order' option to alphabetically order file.
Date: Wed, 26 Jun 2024 23:32:05 +0200 [thread overview]
Message-ID: <87y16r9yqy.fsf@gnu.org> (raw)
In-Reply-To: <875xv20yhq.fsf@gnu.org> ("Ludovic Courtès"'s message of "Sat, 25 May 2024 16:14:57 +0200")
Hi Herman,
Did you have a chance to look into this? Let us know if anything looks
unclear or questionable to you.
Thanks,
Ludo’.
Ludovic Courtès <ludo@gnu.org> skribis:
> Herman Rimm <herman@rimm.ee> 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 ‘stable-sort’ instead of ‘sort’?
>
> Overall LGTM; some suggestions below:
>
>> +(define (order-packages lst)
>> + "Place top-level package definitions in LST in alphabetical order."
>
> “Return LST, a list of top-level expressions and blanks, with top-level
> package definitions in alphabetical order.”
>
>> + ;; Group define-public with preceding blanks and defines.
>> + (let* ((lst (identity
>
> I’d drop ‘identity’.
>
>> + (package-name (lambda (pkg)
>> + (match pkg
>> + ((('define-public _ expr) _ ...)
>> + (match expr
>> + ((or ('package _ ('name name) _ ...)
>> + ('package ('name name) _ ...))
>> + name)
>> + (_ #f)))
>> + (_ #f))))
>
> Nitpick: I’d make this an inner ‘define’ in ‘order-packages’, 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 ‘string>’ by ‘string<?’ and drop ‘reverse’.
>
>> + (option '(#\o "order") #f #f
>> + (lambda (opt name arg result)
>> + (alist-cons 'order? #t result)))
>
> I’d avoid ‘-o’ for this because it’s usually synonymous with ‘output’.
>
> But maybe make it ‘-A’/‘--alphabetical-sort’?
>
>> (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’d 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’.
next prev parent reply other threads:[~2024-06-26 21:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-06 10:50 [bug#70800] [PATCH] scripts: style: Add 'order' option to alphabetically order file Herman Rimm via Guix-patches via
2024-05-25 14:14 ` Ludovic Courtès
2024-05-31 15:36 ` Simon Tournier
2024-06-26 21:32 ` Ludovic Courtès [this message]
2024-07-04 15:55 ` [bug#70800] [PATCH v2] scripts: style: Add 'alphabetical-sort' option Herman Rimm via Guix-patches via
2024-07-18 15:12 ` Ludovic Courtès
2024-09-02 18:58 ` [bug#70800] [PATCH] " Herman Rimm via Guix-patches via
2024-09-03 9:50 ` bug#70800: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y16r9yqy.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=70800@debbugs.gnu.org \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=herman@rimm.ee \
--cc=me@tobias.gr \
--cc=othacehe@gnu.org \
--cc=rekado@elephly.net \
--cc=zimon.toutoune@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).