ui: Fix handling of periods by fill-paragraph.

Fixes <http://bugs.gnu.org/17468>.

* guix/ui.scm (fill-paragraph): Two spaces after period and no spaces before newline.
* tests/ui.scm: New test case.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Cyrill Schenkel 2014-07-27 00:53:16 +02:00 committed by Ludovic Courtès
parent ebc32b3110
commit 3a09e1d2e8
2 changed files with 20 additions and 10 deletions

View File

@ -393,15 +393,17 @@ converted to a space; sequences of more than one line break are preserved."
((#\newline) ((#\newline)
`(,column ,(+ 1 newlines) ,chars)) `(,column ,(+ 1 newlines) ,chars))
(else (else
(let ((chars (case newlines (let* ((spaces (if (and (pair? chars) (eqv? (car chars) #\.)) 2 1))
((0) chars) (chars (case newlines
((1) (cons #\space chars)) ((0) chars)
(else ((1)
(append (make-list newlines #\newline) chars)))) (append (make-list spaces #\space) chars))
(column (case newlines (else
((0) column) (append (make-list newlines #\newline) chars))))
((1) (+ 1 column)) (column (case newlines
(else 0)))) ((0) column)
((1) (+ spaces column))
(else 0))))
(let ((chars (cons chr chars)) (let ((chars (cons chr chars))
(column (+ 1 column))) (column (+ 1 column)))
(if (> column width) (if (> column width)
@ -414,7 +416,10 @@ converted to a space; sequences of more than one line break are preserved."
0 0
,(if (null? after) ,(if (null? after)
before before
(append before (cons #\newline (cdr after))))) (append before
(cons #\newline
(drop-while (cut eqv? #\space <>)
after)))))
`(,column 0 ,chars))) ; unbreakable `(,column 0 ,chars))) ; unbreakable
`(,column 0 ,chars))))))))) `(,column 0 ,chars)))))))))

View File

@ -67,6 +67,11 @@ interface, and powerful string processing.")
10) 10)
#\newline)) #\newline))
(test-equal "fill-paragraph, two spaces after period"
"First line. Second line"
(fill-paragraph "First line.
Second line" 24))
(test-equal "package-specification->name+version+output" (test-equal "package-specification->name+version+output"
'(("guile" #f "out") '(("guile" #f "out")
("guile" "2.0.9" "out") ("guile" "2.0.9" "out")