diff --git a/module/texinfo/string-utils.scm b/module/texinfo/string-utils.scm index 767514952..22f969c04 100644 --- a/module/texinfo/string-utils.scm +++ b/module/texinfo/string-utils.scm @@ -1,6 +1,6 @@ ;;;; (texinfo string-utils) -- text filling and wrapping ;;;; -;;;; Copyright (C) 2009 Free Software Foundation, Inc. +;;;; Copyright (C) 2009, 2013 Free Software Foundation, Inc. ;;;; Copyright (C) 2003 Richard Todd ;;;; ;;;; This library is free software; you can redistribute it and/or @@ -262,6 +262,13 @@ the default value for @var{num} is 1. ;; did not find non-ws... only ws at end of the string... (reverse ans)))))) +(define (end-of-sentence? str) + "Return #t when STR likely denotes the end of sentence." + (let ((len (string-length str))) + (and (> len 1) + (eqv? #\. (string-ref str (- len 1))) + (not (eqv? #\. (string-ref str (- len 2))))))) + (define* (make-text-wrapper #:key (line-width 80) (expand-tabs? #t) @@ -352,7 +359,11 @@ returns a list of strings, where each element of the list is one line." length-left) (loop ans (cdr words) - (string-append line next-word) + (if (and collapse-whitespace? + (end-of-sentence? line)) + ;; Add an extra space after the period. + (string-append line " " next-word) + (string-append line next-word)) (+ count 1))) ;; ok, it didn't fit...is there already at least one word on the line? diff --git a/test-suite/tests/texinfo.serialize.test b/test-suite/tests/texinfo.serialize.test index 95e26b845..554390c0f 100644 --- a/test-suite/tests/texinfo.serialize.test +++ b/test-suite/tests/texinfo.serialize.test @@ -1,6 +1,6 @@ ;;;; texinfo.serialize.test -*- scheme -*- ;;;; -;;;; Copyright (C) 2010 Free Software Foundation, Inc. +;;;; Copyright (C) 2010, 2013 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -103,7 +103,7 @@ "@iftex This is only for tex. -Note. Foo. +Note. Foo. @end iftex diff --git a/test-suite/tests/texinfo.string-utils.test b/test-suite/tests/texinfo.string-utils.test index ad19df871..4f2e4c5e3 100644 --- a/test-suite/tests/texinfo.string-utils.test +++ b/test-suite/tests/texinfo.string-utils.test @@ -1,6 +1,6 @@ ;;;; texinfo.string-utils.test -*- scheme -*- ;;;; -;;;; Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc. +;;;; Copyright (C) 2003, 2009, 2010, 2013 Free Software Foundation, Inc. ;;;; ;;;; This program is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU General Public License as @@ -109,6 +109,13 @@ to using the function `set-language-environment'. variable should be set only with M-x customize, which is equivalent to using the function `set-language-environment'."))) + (with-test-prefix "two spaces after end of sentence" + (pass-if-equal "This is a sentence. There should be two spaces before." + (fill-string "This is a sentence. There should be two spaces before.")) + + (pass-if-equal "This is version 2.0..." + (fill-string "This is version 2.0..."))) + (with-test-prefix "test-no-word-break" (pass-if (equal? "thisisalongword blah