[bug#77093,rust-team,10/18] scripts: import: Add two newlines for ‘--insert’ option.

Message ID 4e38cd180a457bcd8ca56b6a6ad58042cef81014.1742281797.git.hako@ultrarare.space
State New
Headers
Series New Rust packaging workflow based on lockfile importer. |

Commit Message

Hilton Chain March 18, 2025, 7:24 a.m. UTC
  For consistency with ‘insert-expression’.

* guix/scripts/import.scm (guix-import): Add two newlines when inserting.

Change-Id: I55b45ca137d175fdf6ee5c0bb2b6b1ca8385750d
---
 guix/scripts/import.scm | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Efraim Flashner March 18, 2025, 11:49 a.m. UTC | #1
Is this only relevant for packages crated with 'guix import cargo'? If
so we should probably just change the importer to add a newline to the
misbehaving importer.

On Tue, Mar 18, 2025 at 03:24:23PM +0800, Hilton Chain wrote:
> For consistency with ‘insert-expression’.
> 
> * guix/scripts/import.scm (guix-import): Add two newlines when inserting.
> 
> Change-Id: I55b45ca137d175fdf6ee5c0bb2b6b1ca8385750d
> ---
>  guix/scripts/import.scm | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
> index 4fad329cd3..58a84d0db7 100644
> --- a/guix/scripts/import.scm
> +++ b/guix/scripts/import.scm
> @@ -129,6 +129,7 @@ (define-command (guix-import . args)
>                        (let ((port (open-file file "a")))
>                          (pretty-print-with-comments port expr)
>                          (newline port)
> +                        (newline port)
>                          (close-port port)))))))))
>         (import-as-definitions importer args find-and-insert)))
>      ((importer args ...)
> -- 
> 2.48.1
> 
> 
> 
>
  
Hilton Chain March 18, 2025, 12:18 p.m. UTC | #2
On Tue, 18 Mar 2025 19:49:33 +0800,
Efraim Flashner wrote:
>
> [1  <text/plain; utf-8 (quoted-printable)>]
> Is this only relevant for packages crated with 'guix import cargo'? If
> so we should probably just change the importer to add a newline to the
> misbehaving importer.
>
> On Tue, Mar 18, 2025 at 03:24:23PM +0800, Hilton Chain wrote:
> > For consistency with ‘insert-expression’.
> >
> > * guix/scripts/import.scm (guix-import): Add two newlines when inserting.
> >
> > Change-Id: I55b45ca137d175fdf6ee5c0bb2b6b1ca8385750d
> > ---
> >  guix/scripts/import.scm | 1 +
> >  1 file changed, 1 insertion(+)

This is a general issue, adding one newline doesn't work well with appending
multiple definitions.  For appending n definitions, (n - 1) lines need manual
addition:
--8<---------------cut here---------------start------------->8---
a
b
c
--8<---------------cut here---------------end--------------->8---

By adding two newlines, only one line needs manual deletion:
--8<---------------cut here---------------start------------->8---
a

b

c

--8<---------------cut here---------------end--------------->8---
  

Patch

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 4fad329cd3..58a84d0db7 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -129,6 +129,7 @@  (define-command (guix-import . args)
                       (let ((port (open-file file "a")))
                         (pretty-print-with-comments port expr)
                         (newline port)
+                        (newline port)
                         (close-port port)))))))))
        (import-as-definitions importer args find-and-insert)))
     ((importer args ...)