diff mbox series

[bug#50401] scripts: import: Increase column width for pretty-printer.

Message ID 3418edcdafdf9b6551759f4a392d8d3466f255c4.1630850420.git.public@yoctocell.xyz
State Accepted
Headers show
Series [bug#50401] scripts: import: Increase column width for pretty-printer. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Xinglu Chen Sept. 5, 2021, 2:05 p.m. UTC
Previously, the max column width for the pretty-printer was 50, which caused
generated package definitions to include unnecessary newlines, e.g.,

  (home-page
    "https://gitlab.com/ttyperacer/terminal-typeracer")

instead of

  (home-page "https://gitlab.com/ttyperacer/terminal-typeracer")

* guix/scripts/import.scm (guix-import): Set max expression width to 80 when
pretty-printing.
---
I don’t know if there is an official stance on the column width, but I
most people seem to go with 80.

Before, a generated package definition might look like this

--8<---------------cut here---------------start------------->8---
(define-public rust-typeracer-2
  (package
    (name "rust-typeracer")
    (version "2.0.7")
    (source
      (origin
        (method url-fetch)
        (uri (crate-uri "typeracer" version))
        (file-name  ; unnecessary newline here
          (string-append name "-" version ".tar.gz"))
        (sha256
          (base32
            "1q1f6aslmqab8kqds6azsz7li0r5z7alqar17r1d675vsqfiidml"))))
    (build-system cargo-build-system)
    (arguments
      `(#:cargo-inputs
        (("rust-clap" ,rust-clap-2)
         ("rust-directories-next"
          ,rust-directories-next-2)
         ("rust-git2" ,rust-git2-0.13)
         ("rust-itertools" ,rust-itertools-0.10)
         ("rust-rand" ,rust-rand-0.8)
         ("rust-refinery" ,rust-refinery-0.5)
         ("rust-rusqlite" ,rust-rusqlite-0.24)
         ("rust-serde" ,rust-serde-1)
         ("rust-termion" ,rust-termion-1)
         ("rust-toml" ,rust-toml-0.5)
         ("rust-tui" ,rust-tui-0.9)
         ("rust-unicode-segmentation"
          ,rust-unicode-segmentation-1)
         ("rust-unicode-width" ,rust-unicode-width-0.1))))
    (home-page  ; and here
      "https://gitlab.com/ttyperacer/terminal-typeracer")
    (synopsis
      "A terminal typing game. Race to see the fastest time you can get!")
    (description
      "This package provides a terminal typing game.  Race to see the fastest time you can get!")
    (license license:gpl3)))
--8<---------------cut here---------------end--------------->8---

With the patch applied

--8<---------------cut here---------------start------------->8---
(define-public rust-typeracer-2
  (package
    (name "rust-typeracer")
    (version "2.0.7")
    (source
      (origin
        (method url-fetch)
        (uri (crate-uri "typeracer" version))
        ;; No newline this time.
        (file-name (string-append name "-" version ".tar.gz"))
        (sha256
          (base32 "1q1f6aslmqab8kqds6azsz7li0r5z7alqar17r1d675vsqfiidml"))))
    (build-system cargo-build-system)
    (arguments
      `(#:cargo-inputs
        (("rust-clap" ,rust-clap-2)
         ("rust-directories-next" ,rust-directories-next-2)
         ("rust-git2" ,rust-git2-0.13)
         ("rust-itertools" ,rust-itertools-0.10)
         ("rust-rand" ,rust-rand-0.8)
         ("rust-refinery" ,rust-refinery-0.5)
         ("rust-rusqlite" ,rust-rusqlite-0.24)
         ("rust-serde" ,rust-serde-1)
         ("rust-termion" ,rust-termion-1)
         ("rust-toml" ,rust-toml-0.5)
         ("rust-tui" ,rust-tui-0.9)
         ("rust-unicode-segmentation" ,rust-unicode-segmentation-1)
         ("rust-unicode-width" ,rust-unicode-width-0.1))))
    ;; Here too!
    (home-page "https://gitlab.com/ttyperacer/terminal-typeracer")
    (synopsis
      "A terminal typing game. Race to see the fastest time you can get!")
    (description
      "This package provides a terminal typing game.  Race to see the fastest time you can get!")
    (license license:gpl3)))
--8<---------------cut here---------------end--------------->8---

 guix/scripts/import.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


base-commit: 9540323458de87b0b8aa421e449a4fe27af7c393

Comments

Ludovic Courtès Sept. 14, 2021, 9:11 a.m. UTC | #1
Hi,

Xinglu Chen <public@yoctocell.xyz> skribis:

> Previously, the max column width for the pretty-printer was 50, which caused
> generated package definitions to include unnecessary newlines, e.g.,
>
>   (home-page
>     "https://gitlab.com/ttyperacer/terminal-typeracer")
>
> instead of
>
>   (home-page "https://gitlab.com/ttyperacer/terminal-typeracer")
>
> * guix/scripts/import.scm (guix-import): Set max expression width to 80 when
> pretty-printing.

Applied!

I wonder why we never realized before…  Thank you!

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index b369a362d0..73508bade2 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -3,6 +3,7 @@ 
 ;;; Copyright © 2014 David Thompson <davet@gnu.org>
 ;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
 ;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -117,7 +118,8 @@  Run IMPORTER with ARGS.\n"))
      (if (member importer importers)
          (let ((print (lambda (expr)
                         (pretty-print expr (newline-rewriting-port
-                                            (current-output-port))))))
+                                            (current-output-port))
+                                      #:max-expr-width 80))))
            (match (apply (resolve-importer importer) args)
              ((and expr (or ('package _ ...)
                             ('let _ ...)