l...@gnu.org (Ludovic Courtès) writes:

> One last thing (I swear!).
>
> AFAICS ‘stexi->plain-text’ already does paragraph filling, so the call
> above is redundant (and could break the rendering.)
>
> However, the width of the rendered text is fixed, unlike what
> ‘string->recutils’ did so far.  To work around that, we’ll have to
> monkey-patch the ‘wrap*’ procedure of (texinfo plain-text), along these
> lines:
>
>   (define %text-width
>     (make-parameter (or (and=> (getenv "WIDTH") string->number)
>                         80)))
>
>   (set! (@@ (texinfo plain-text) wrap*)
>         (lambda strings
>           ... #:line-width (%text-width) ...))
>
> and then in ‘package->recutils’, we need to ‘parameterize’ that.
>
> We need a similar hack for #:initial-indent, that would allow us to
> mimic the 3rd argument of ‘fill-paragraph’.

Thanks for noticing this problem.  Here is an updated patch.  

>From e691c2080929dd1390184ab4669de8b2695a237f Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <m...@openmailbox.org>
Date: Fri, 7 Aug 2015 00:10:43 +0200
Subject: [PATCH] ui: Add package-description-string.

Provide support for Texinfo's markup in package description.

* guix/ui.scm (%text-width, %initial-indent): New parameters.
  (package-description-string): New variable.
  (package->recutils): Use them.
* emacs/guix-main.scm (%package-param-alist): Use it.
* gnu/packages/databases.scm (perl-dbd-pg): Adapt to Texinfo's markup.
* gnu/packages/perl.scm (perl-devel-globaldestruction)
  (perl-devel-lexalias, perl-exporter-lite): Likewise.
* gnu/packages/python.scm (python2-empy): Likewise.
---
 emacs/guix-main.scm        |  2 +-
 gnu/packages/databases.scm |  2 +-
 gnu/packages/perl.scm      |  6 +++---
 gnu/packages/python.scm    |  2 +-
 guix/ui.scm                | 47 +++++++++++++++++++++++++++++++++-------------
 5 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index fe224fb..73173f2 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -281,7 +281,7 @@ Example:
     (license           . ,package-license-names)
     (source            . ,package-source-names)
     (synopsis          . ,package-synopsis)
-    (description       . ,package-description)
+    (description       . ,package-description-string)
     (home-url          . ,package-home-page)
     (outputs           . ,package-outputs)
     (non-unique        . ,(negate package-unique?))
diff --git a/gnu/packages/databases.scm b/gnu/packages/databases.scm
index cbac16e..1710d0e 100644
--- a/gnu/packages/databases.scm
+++ b/gnu/packages/databases.scm
@@ -578,7 +578,7 @@ columns, primary keys, unique constraints and relationships.")
        ("postgresql" ,postgresql)))
     (home-page "http://search.cpan.org/dist/DBD-Pg";)
     (synopsis "DBI PostgreSQL interface")
-    (description "")
+    (description #f)
     (license (package-license perl))))
 
 (define-public perl-dbd-sqlite
diff --git a/gnu/packages/perl.scm b/gnu/packages/perl.scm
index f784798..0236d05 100644
--- a/gnu/packages/perl.scm
+++ b/gnu/packages/perl.scm
@@ -1665,7 +1665,7 @@ particular command is available.")
     (home-page "http://search.cpan.org/dist/Devel-GlobalDestruction";)
     (synopsis "Provides equivalent of ${^GLOBAL_PHASE} eq 'DESTRUCT' for older perls")
     (description "Devel::GlobalDestruction provides a function returning the
-equivalent of \"${^GLOBAL_PHASE} eq 'DESTRUCT'\" for older perls.")
+equivalent of \"$@{^GLOBAL_PHASE@} eq 'DESTRUCT'\" for older perls.")
     (license (package-license perl))))
 
 (define-public perl-devel-lexalias
@@ -1909,7 +1909,7 @@ constructors, which speeds code up at runtime by a significant amount.  String
 eval is not without its issues however - it's difficult to control the scope
 it's used in (which determines which variables are in scope inside the eval),
 and it's easy to miss compilation errors, since eval catches them and sticks
-them in $@ instead.  This module attempts to solve these problems.  It
+them in $@@ instead.  This module attempts to solve these problems.  It
 provides an eval_closure function, which evals a string in a clean
 environment, other than a fixed list of specified variables.  Compilation
 errors are rethrown automatically.")
@@ -1953,7 +1953,7 @@ in your modules in a \"Java-esque\" manner.")
     (description
      "Exporter::Lite is an alternative to Exporter, intended to provide a
 lightweight subset of the most commonly-used functionality.  It supports
-import(), @EXPORT and @EXPORT_OK and not a whole lot else.")
+import(), @@EXPORT and @@EXPORT_OK and not a whole lot else.")
     (home-page (string-append "http://search.cpan.org/~neilb/";
                               "Exporter-Lite-" version))
     (license (package-license perl))))
diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index 940efec..07275d7 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -1171,7 +1171,7 @@ other Python program.")
      "EmPy is a system for embedding Python expressions and statements in
 template text; it takes an EmPy source file, processes it, and produces
 output.  This is accomplished via expansions, which are special signals to the
-EmPy system and are set off by a special prefix (by default the at sign, @).
+EmPy system and are set off by a special prefix (by default the at sign, @@).
 EmPy can expand arbitrary Python expressions and statements in this way, as
 well as a variety of special forms.  Textual data not explicitly delimited in
 this way is sent unaffected to the output, allowing Python to be used in
diff --git a/guix/ui.scm b/guix/ui.scm
index 8de8e3c..11465c5 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2013 Mark H Weaver <m...@netris.org>
 ;;; Copyright © 2013 Nikita Karetnikov <nik...@karetnikov.org>
 ;;; Copyright © 2014, 2015 Alex Kost <alez...@gmail.com>
+;;; Copyright © 2015 Mathieu Lirzin <m...@openmailbox.org>
 ;;; Copyright © 2014 Deck Pickard <deck.r.pick...@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -45,6 +46,9 @@
   #: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 @@
             switch-symlinks
             config-directory
             fill-paragraph
+            package-description-string
             string->recutils
             package->recutils
             package-specification->name+version+output
@@ -767,6 +772,29 @@ converted to a space; sequences of more than one line break are preserved."
 ;;; Packages.
 ;;;
 
+(define %text-width
+  (make-parameter (or (and=> (getenv "WIDTH") string->number)
+                      80)))
+
+(define %initial-indent
+  (make-parameter ""))
+
+(set! (@@ (texinfo plain-text) wrap*)
+      ;; Monkey patch this private procedure to let 'package->recutils'
+      ;; parameterize the fill of description field correctly.
+      (lambda strings
+        (fill-string (string-concatenate strings)
+                     #:line-width (%text-width)
+                     #:initial-indent (%initial-indent))))
+
+(define (package-description-string package)
+  "Return a plain-text representation of PACKAGE description field."
+  (and=> (package-description package)
+         (compose (cut string-trim-right <> #\newline)
+                  stexi->plain-text
+                  texi-fragment->stexi
+                  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
@@ -779,18 +807,9 @@ followed by \"+ \", which makes for a valid multi-line field value in the
                       '()
                       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<?)) " ")))
@@ -834,9 +853,11 @@ WIDTH columns."
                        (chr       chr))
                       (or (and=> (package-synopsis p) P_)
                           "")))
-  (format port "description: ~a~%"
-          (and=> (package-description p) description->recutils))
-  (newline port))
+  (format port "~a~2%"
+          (and=> (parameterize ((%text-width width)
+                                (%initial-indent "description: "))
+                   (package-description-string p))
+                 string->recutils)))
 
 (define (string->generations str)
   "Return the list of generations matching a pattern in STR.  This function
-- 
2.5.0

--
Mathieu Lirzin

Reply via email to