From 1cd4027cfdb82d43321c9c20f8bfad97cbd74413 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Fri, 7 Aug 2015 00:10:43 +0200 Subject: ui: Add package-description-string. Provide support for Texinfo's markup in package description. * guix/ui.scm (%text-width): New parameter. (texi->plain-text): New variable. (package->recutils): Use them. (package-description-string): New variable. * emacs/guix-main.scm (%package-param-alist): Use it. * gnu/packages/perl.scm (perl-devel-globaldestruction) (perl-devel-lexalias, perl-exporter-lite): Adapt to Texinfo's markup. * gnu/packages/python.scm (python2-empy): Likewise. --- guix/ui.scm | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'guix/ui.scm') diff --git a/guix/ui.scm b/guix/ui.scm index 2f757547cf..ca5b844a43 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2013 Mark H Weaver ;;; Copyright © 2013 Nikita Karetnikov ;;; Copyright © 2014, 2015 Alex Kost +;;; Copyright © 2015 Mathieu Lirzin ;;; Copyright © 2014 Deck Pickard ;;; ;;; This file is part of GNU Guix. @@ -45,6 +46,9 @@ (define-module (guix ui) #:use-module (ice-9 regex) #:autoload (system repl repl) (start-repl) #:autoload (system repl debug) (make-debug stack->vector) + #:use-module (texinfo) + #:use-module (texinfo plain-text) + #:use-module (texinfo string-utils) #:export (_ N_ P_ @@ -69,6 +73,7 @@ (define-module (guix ui) switch-symlinks config-directory fill-paragraph + package-description-string string->recutils package->recutils package-specification->name+version+output @@ -775,6 +780,28 @@ (define (maybe-break chr result) ;;; Packages. ;;; +(define %text-width + (make-parameter (or (and=> (getenv "WIDTH") string->number) + 80))) + +(set! (@@ (texinfo plain-text) wrap*) + ;; XXX: Monkey patch this private procedure to let 'package->recutils' + ;; parameterize the fill of description field correctly. + (lambda strings + (let ((indent (fluid-ref (@@ (texinfo plain-text) *indent*)))) + (fill-string (string-concatenate strings) + #:line-width (%text-width) #:initial-indent indent + #:subsequent-indent indent)))) + +(define (texi->plain-text str) + "Return a plain-text representation of texinfo fragment STR." + (stexi->plain-text (texi-fragment->stexi str))) + +(define (package-description-string package) + "Return a plain-text representation of PACKAGE description field." + (and=> (package-description package) + (compose texi->plain-text P_))) + (define (string->recutils str) "Return a version of STR where newlines have been replaced by newlines followed by \"+ \", which makes for a valid multi-line field value in the @@ -787,18 +814,9 @@ (define (string->recutils str) '() str))) -(define* (package->recutils p port - #:optional (width (or (and=> (getenv "WIDTH") - string->number) - 80))) +(define* (package->recutils p port #:optional (width (%text-width))) "Write to PORT a `recutils' record of package P, arranging to fit within WIDTH columns." - (define (description->recutils str) - (let ((str (P_ str))) - (string->recutils - (fill-paragraph str width - (string-length "description: "))))) - (define (dependencies->recutils packages) (let ((list (string-join (map package-full-name (sort packages package (package-synopsis p) P_) ""))) - (format port "description: ~a~%" - (and=> (package-description p) description->recutils)) - (newline port)) + (format port "~a~2%" + (string->recutils + (string-trim-right + (parameterize ((%text-width width)) + (texi->plain-text + (string-append "description: " + (or (and=> (package-description p) P_) + "")))) + #\newline)))) (define (string->generations str) "Return the list of generations matching a pattern in STR. This function -- cgit v1.2.3