mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-13 06:36:37 -05:00
scripts/import: Use pretty printer from (guix scripts style).
* guix/scripts/import.scm (guix-import): Use pretty-print-with-comments. (newline-rewriting-port): Remove procedure.
This commit is contained in:
parent
f383838a09
commit
371a83b764
1 changed files with 3 additions and 36 deletions
|
@ -2,7 +2,7 @@
|
||||||
;;; Copyright © 2012, 2013, 2014, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
;;; Copyright © 2012, 2013, 2014, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
||||||
;;; Copyright © 2014 David Thompson <davet@gnu.org>
|
;;; Copyright © 2014 David Thompson <davet@gnu.org>
|
||||||
;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
|
;;; Copyright © 2018 Kyle Meyer <kyle@kyleam.com>
|
||||||
;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
|
;;; Copyright © 2019, 2022 Ricardo Wurmus <rekado@elephly.net>
|
||||||
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
|
;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
|
||||||
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
|
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
|
||||||
;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
|
;;; Copyright © 2022 Philip McGrath <philip@philipmcgrath.com>
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
(define-module (guix scripts import)
|
(define-module (guix scripts import)
|
||||||
#:use-module (guix ui)
|
#:use-module (guix ui)
|
||||||
#:use-module (guix scripts)
|
#:use-module (guix scripts)
|
||||||
|
#:use-module (guix scripts style)
|
||||||
#:use-module (guix utils)
|
#:use-module (guix utils)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (srfi srfi-11)
|
#:use-module (srfi srfi-11)
|
||||||
|
@ -32,41 +33,9 @@ (define-module (guix scripts import)
|
||||||
#:use-module (srfi srfi-37)
|
#:use-module (srfi srfi-37)
|
||||||
#:use-module (ice-9 format)
|
#:use-module (ice-9 format)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 pretty-print)
|
|
||||||
#:export (%standard-import-options
|
#:export (%standard-import-options
|
||||||
guix-import))
|
guix-import))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
|
||||||
;;; Helper.
|
|
||||||
;;;
|
|
||||||
|
|
||||||
(define (newline-rewriting-port output)
|
|
||||||
"Return an output port that rewrites strings containing the \\n escape
|
|
||||||
to an actual newline. This works around the behavior of `pretty-print'
|
|
||||||
and `write', which output these as \\n instead of actual newlines,
|
|
||||||
whereas we want the `description' field to contain actual newlines
|
|
||||||
rather than \\n."
|
|
||||||
(define (write-string str)
|
|
||||||
(let loop ((chars (string->list str)))
|
|
||||||
(match chars
|
|
||||||
(()
|
|
||||||
#t)
|
|
||||||
((#\\ #\n rest ...)
|
|
||||||
(newline output)
|
|
||||||
(loop rest))
|
|
||||||
((chr rest ...)
|
|
||||||
(write-char chr output)
|
|
||||||
(loop rest)))))
|
|
||||||
|
|
||||||
(make-soft-port (vector (cut write-char <>)
|
|
||||||
write-string
|
|
||||||
(lambda _ #t) ; flush
|
|
||||||
#f
|
|
||||||
(lambda _ #t) ; close
|
|
||||||
#f)
|
|
||||||
"w"))
|
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Command line options.
|
;;; Command line options.
|
||||||
|
@ -119,9 +88,7 @@ (define-command (guix-import . args)
|
||||||
((importer args ...)
|
((importer args ...)
|
||||||
(if (member importer importers)
|
(if (member importer importers)
|
||||||
(let ((print (lambda (expr)
|
(let ((print (lambda (expr)
|
||||||
(pretty-print expr (newline-rewriting-port
|
(pretty-print-with-comments (current-output-port) expr))))
|
||||||
(current-output-port))
|
|
||||||
#:max-expr-width 80))))
|
|
||||||
(match (apply (resolve-importer importer) args)
|
(match (apply (resolve-importer importer) args)
|
||||||
((and expr (or ('package _ ...)
|
((and expr (or ('package _ ...)
|
||||||
('let _ ...)
|
('let _ ...)
|
||||||
|
|
Loading…
Reference in a new issue