texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Do not copy spaces exactly for @w


From: Gavin D. Smith
Subject: branch master updated: Do not copy spaces exactly for @w
Date: Sun, 11 Dec 2022 15:48:30 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 0ba1412538 Do not copy spaces exactly for @w
0ba1412538 is described below

commit 0ba1412538979ff97916ef33825154e2bb5a290f
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Dec 11 20:37:25 2022 +0000

    Do not copy spaces exactly for @w
    
    * tp/Texinfo/XS/xspara.c (xspara_add_text) <protect_spaces>
    * tp/Texinfo/Convert/ParagraphNonXS.pm (add_text) <protect_spaces>:
    Change the meaning of this flag to match what @w does in
    texinfo.tex, which simply uses an \hbox for the content, but does
    not protect the spaces.  Do not use exactly the same spaces that
    were given in the input.  Accumulate spaces onto the end of the
    current word so that all spaces and words will be stuck together
    while in the mode and output together in the same line.
    * tp/t/paragraph.t: Manually update reference test results.
    
    The 'protect_spaces' flag is probably now misnamed.
---
 ChangeLog                                          | 16 ++++++
 tp/Texinfo/Convert/ParagraphNonXS.pm               | 62 ++++++++++++----------
 tp/Texinfo/XS/xspara.c                             | 34 ++++++------
 tp/t/paragraph.t                                   | 18 +++----
 .../converters_tests/spaces_in_empty_node_names.pl |  4 +-
 .../converters_tests/spaces_in_node_names.pl       | 10 ++--
 tp/t/results/coverage_braces/test_w.pl             | 12 ++---
 tp/t/results/misc_commands/test_allowcodebreaks.pl |  2 +-
 .../plaintext_tests/protect_spaces_on_line.pl      |  4 +-
 9 files changed, 92 insertions(+), 70 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9e03f73e25..64e5beac79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2022-12-11  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Do not copy spaces exactly for @w
+
+       * tp/Texinfo/XS/xspara.c (xspara_add_text) <protect_spaces>
+       * tp/Texinfo/Convert/ParagraphNonXS.pm (add_text) <protect_spaces>:
+       Change the meaning of this flag to match what @w does in
+       texinfo.tex, which simply uses an \hbox for the content, but does
+       not protect the spaces.  Do not use exactly the same spaces that
+       were given in the input.  Accumulate spaces onto the end of the
+       current word so that all spaces and words will be stuck together
+       while in the mode and output together in the same line.
+       * tp/t/paragraph.t: Manually update reference test results.
+
+       The 'protect_spaces' flag is probably now misnamed.
+
 2022-12-11  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): add multitable
diff --git a/tp/Texinfo/Convert/ParagraphNonXS.pm 
b/tp/Texinfo/Convert/ParagraphNonXS.pm
index e99aacf7e1..49e18a10f2 100644
--- a/tp/Texinfo/Convert/ParagraphNonXS.pm
+++ b/tp/Texinfo/Convert/ParagraphNonXS.pm
@@ -336,35 +336,41 @@ sub add_text($$)
         } else {
           $paragraph->{'space'} .= $spaces;
         }
-      } elsif ($protect_spaces_flag) {
-        $paragraph->{'word'} .= $spaces;
-        $paragraph->{'last_char'} = substr($spaces, -1);
-        $paragraph->{'word_counter'} += length($spaces);
-        $paragraph->{'word'} =~ s/\n/ /g;
-
-        # The $paragraph->{'counter'} != 0 is here to avoid having an
-        # additional line output when the text is longer than the max.
-        if ($paragraph->{'counter'} != 0 and 
-            $paragraph->{'counter'} + $paragraph->{'word_counter'} + 
-               length($paragraph->{'space'}) > $paragraph->{'max'}) {
-          $result .= _cut_line($paragraph);
-        }
       } else {
-        my $pending_word = $paragraph->{'word'};
-        $result .= _add_pending_word($paragraph);
-        if ($paragraph->{'counter'} != 0
-            or (defined $pending_word)) {
-          if ($paragraph->{'end_sentence'} 
-              and $paragraph->{'end_sentence'} > 0
-              and !$paragraph->{'frenchspacing'}) {
-            $paragraph->{'space'} = '  ';
-          } else {
-            # Only save the first space
-            if (length($paragraph->{'space'}) < 1) {
-              if ($spaces =~ /\n/) {
-                $paragraph->{'space'} = ' ';
-              } else {
-                $paragraph->{'space'} .= substr ($spaces, 0, 1);
+        my $at_end_sentence = 0;
+        $at_end_sentence = 1 if ($paragraph->{'end_sentence'} 
+                                   and $paragraph->{'end_sentence'} > 0
+                                   and !$paragraph->{'frenchspacing'});
+        if ($protect_spaces_flag) {
+          if (substr($paragraph->{'word'}, -1) ne ' ') {
+            my $new_spaces = $at_end_sentence ? '  ' : ' ';
+            $paragraph->{'word'} .= $new_spaces;
+            $paragraph->{'last_char'} = ' ';
+            $paragraph->{'word_counter'} += length($new_spaces);
+
+            # The $paragraph->{'counter'} != 0 is here to avoid having an
+            # additional line output when the text is longer than the max.
+            if ($paragraph->{'counter'} != 0 and 
+                $paragraph->{'counter'} + $paragraph->{'word_counter'} + 
+                   length($paragraph->{'space'}) > $paragraph->{'max'}) {
+              $result .= _cut_line($paragraph);
+            }
+          }
+        } else {
+          my $pending_word = $paragraph->{'word'};
+          $result .= _add_pending_word($paragraph);
+          if ($paragraph->{'counter'} != 0
+              or (defined $pending_word)) {
+            if ($at_end_sentence) {
+              $paragraph->{'space'} = '  ';
+            } else {
+              # Only save the first space
+              if (length($paragraph->{'space'}) < 1) {
+                if ($spaces =~ /\n/) {
+                  $paragraph->{'space'} = ' ';
+                } else {
+                  $paragraph->{'space'} .= substr ($spaces, 0, 1);
+                }
               }
             }
           }
diff --git a/tp/Texinfo/XS/xspara.c b/tp/Texinfo/XS/xspara.c
index db618e8b39..48151b1573 100644
--- a/tp/Texinfo/XS/xspara.c
+++ b/tp/Texinfo/XS/xspara.c
@@ -859,27 +859,27 @@ xspara_add_text (char *text)
           else if (state.protect_spaces)
             {
               /* Append the spaces to the pending word. */
-              text_append_n (&state.word, p, char_len);
-              state.word_counter++;
-
-              if (strchr (state.word.text, '\n'))
+              if (state.word.end == 0
+                  || state.word.text[state.word.end - 1] != ' ')
                 {
-                  /* Replace any '\n' with a ' '. Note that state.word_counter 
-                     will still be correct after this. */
-                  char *ptr = state.word.text;
-                  while (*ptr)
+                  if (state.end_sentence == 1 && !state.french_spacing)
                     {
-                      if (*ptr == '\n')
-                        *ptr = ' ';
-                      ptr++;
+                      text_append_n (&state.word, "  ", 2);
+                      state.word_counter += 2;
                     }
-                }
+                  else
+                    {
+                      text_append_n (&state.word, " ", 1);
+                      state.word_counter += 1;
+                    }
+                  state.last_letter = ' ';
 
-              if (state.counter != 0
-                  && state.counter + state.word_counter + state.space_counter
-                     > state.max)
-                {
-                  xspara__cut_line (&result);
+                  if (state.counter != 0
+                      && state.counter + state.word_counter
+                          + state.space_counter > state.max)
+                    {
+                      xspara__cut_line (&result);
+                    }
                 }
             }
           else /* protect_spaces off */
diff --git a/tp/t/paragraph.t b/tp/t/paragraph.t
index 82737b8b91..c89f17184c 100644
--- a/tp/t/paragraph.t
+++ b/tp/t/paragraph.t
@@ -232,7 +232,7 @@ $result .= add_text($para, "In w:\n");
 set_space_protection($para, 1,1);
 $result .= add_text($para, "Out of code -- out-of-code.   
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
 $result .= Texinfo::Convert::Paragraph::end($para);
-is ($result, "In w: Out of code -- out-of-code.   
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\n", 'space 
protection after end sentence');
+is ($result, "In w: Out of code -- out-of-code.  
ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\n", 'space 
protection after end sentence');
 
 $para = Texinfo::Convert::Paragraph->new();
 $result = '';
@@ -371,7 +371,7 @@ $result .= add_text($para, "a");
 $result .= add_text($para, '  ');
 set_space_protection($para, 0,0);
 $result .= add_text($para, "c ");
-is ($result, "aa.)    bb  eee    .)_ aa  . gg.  a  c\n", "protected spaces 
many inputs");
+is ($result, "aa.)  bb eee .)_  aa .  gg.  a c\n", "protected spaces many 
inputs");
 Texinfo::Convert::Paragraph::end($para);
 
 $para = Texinfo::Convert::Paragraph->new({'max' => 10});
@@ -404,7 +404,7 @@ $result .= add_text($para,  "ccc dddd");
 set_space_protection($para, 0,0);
 $result .= add_text($para,  "gg.\n");
 $result .= Texinfo::Convert::Paragraph::end($para);
-is ($result, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbb 
bbbbb bbb b b b b b b b b b bb . ccc ddddgg.\n", 'long text followed by text 
protected'); 
+is ($result, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbb 
bbbbb bbb b b b b b b b b b bb .  ccc ddddgg.\n", 'long text followed by text 
protected'); 
 
 $para = Texinfo::Convert::Paragraph->new();
 $result = '';
@@ -413,7 +413,7 @@ set_space_protection($para, 1,1);
 $result .= add_text($para, '  f  f');
 set_space_protection($para, 0,0);
 $result .= add_text($para, "ggg\n");
-is ($result, 'aa  f  fggg', 'protected space within words');
+is ($result, 'aa f fggg', 'protected space within words');
 Texinfo::Convert::Paragraph::end($para);
 
 $para = Texinfo::Convert::Paragraph->new();
@@ -423,7 +423,7 @@ set_space_protection($para, 1,1);
 $result .= add_text($para, '  f  f ');
 set_space_protection($para, 0,0);
 $result .= add_text($para, "ggg\n");
-is ($result, 'aa  f  f ggg', 'protected space and space within words');
+is ($result, 'aa f f ggg', 'protected space and space within words');
 Texinfo::Convert::Paragraph::end($para);
 
 $para = Texinfo::Convert::Paragraph->new();
@@ -433,7 +433,7 @@ set_space_protection($para, 1,1);
 $result .= add_text($para, '  f  f ');
 set_space_protection($para, 0,0);
 $result .= add_text($para, "ggg\n");
-is ($result, 'aa   f  f ggg', 'text space protected space and space within 
words');
+is ($result, 'aa  f f ggg', 'text space protected space and space within 
words');
 Texinfo::Convert::Paragraph::end($para);
 
 $para = Texinfo::Convert::Paragraph->new();
@@ -443,7 +443,7 @@ set_space_protection($para, 1,1);
 $result .= add_text($para, '  f  f ');
 set_space_protection($para, 0,0);
 $result .= add_text($para, " ggg\n");
-is ($result, 'aa   f  f  ggg', 'text space protected space and space after');
+is ($result, 'aa  f f  ggg', 'text space protected space and space after');
 Texinfo::Convert::Paragraph::end($para);
 
 $para = Texinfo::Convert::Paragraph->new();
@@ -649,7 +649,7 @@ $result .= add_text($line, 'then');
 $result .= add_text($line, 'fff     g');
 set_space_protection($line, 0,0);
 $result .= Texinfo::Convert::Paragraph::end($line);
-is ($result, " aa.) thenfff     g", 'line space_protection and spaces');
+is ($result, " aa.)  thenfff g", 'line space_protection and spaces');
 
 $line = _new_line_formatter();
 $result = '';
@@ -678,7 +678,7 @@ $result .= add_text($line, "protected. B");
 set_space_protection($line, 0,0);
 $result .= add_text($line, "  after");
 $result .= Texinfo::Convert::Paragraph::end($line);
-is ($result, "protected. B after", 'line 2 spaces after end space protection');
+is ($result, "protected.  B after", 'line 2 spaces after end space 
protection');
 
 $line = _new_line_formatter();
 $result = '';
diff --git a/tp/t/results/converters_tests/spaces_in_empty_node_names.pl 
b/tp/t/results/converters_tests/spaces_in_empty_node_names.pl
index 1e8ad1184c..75887950ed 100644
--- a/tp/t/results/converters_tests/spaces_in_empty_node_names.pl
+++ b/tp/t/results/converters_tests/spaces_in_empty_node_names.pl
@@ -785,7 +785,7 @@ 
$result_converted{'plaintext'}->{'spaces_in_empty_node_names'} = '*note   ::
 
    *note   ::
 
-   *note   ::
+   *note  ::
 ';
 
 
@@ -885,7 +885,7 @@ File: ,  Node: Top,  Up: (dir)
 
    *note   ::
 
-   *note   ::
+   *note  ::
 
 
 Tag Table:
diff --git a/tp/t/results/converters_tests/spaces_in_node_names.pl 
b/tp/t/results/converters_tests/spaces_in_node_names.pl
index 5c8516e6e0..0aba70557c 100644
--- a/tp/t/results/converters_tests/spaces_in_node_names.pl
+++ b/tp/t/results/converters_tests/spaces_in_node_names.pl
@@ -878,7 +878,7 @@ $result_converted{'plaintext'}->{'spaces_in_node_names'} = 
'*note a  ::
 
    *note b  ::
 
-   *note c  ::
+   *note c ::
 ';
 
 
@@ -984,23 +984,23 @@ File: ,  Node: Top,  Next: a  ,  Up: (dir)
 File: ,  Node: a  ,  Next: b  ,  Prev: Top,  Up: Top
 
 
-File: ,  Node: b  ,  Next: c  ,  Prev: a  ,  Up: Top
+File: ,  Node: b  ,  Next: c ,  Prev: a  ,  Up: Top
 
 
-File: ,  Node: c  ,  Prev: b  ,  Up: Top
+File: ,  Node: c ,  Prev: b  ,  Up: Top
 
 *note a  ::
 
    *note b  ::
 
-   *note c  ::
+   *note c ::
 
 
 Tag Table:
 Node: Top27
 Node: a  106
 Node: b  162
-Node: c  218
+Node: c 217
 
 End Tag Table
 
diff --git a/tp/t/results/coverage_braces/test_w.pl 
b/tp/t/results/coverage_braces/test_w.pl
index d113fe2cc1..6d2da830af 100644
--- a/tp/t/results/coverage_braces/test_w.pl
+++ b/tp/t/results/coverage_braces/test_w.pl
@@ -680,26 +680,26 @@ $result_floats{'test_w'} = {};
 
 
 
-$result_converted{'plaintext'}->{'test_w'} = 
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbb bbbbb bbb b b 
b b b b b b b bb . ccc dddd.
+$result_converted{'plaintext'}->{'test_w'} = 
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbb bbbbb bbb b b 
b b b b b b b bb .  ccc dddd.
 
    a a a a a a a a a a a a a a a a a a a a a a a a a a a a
 b a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
 
    
 
-    a rr      ggg.
+    a rr ggg.
 
    AAbbb.
 
    FFdnnn.
 
-   aa  f  fggg.
+   aa f fggg.
 
-   aa2  f  f ggg2.
+   aa2 f f ggg2.
 
-   aa3   f  f ggg3.
+   aa3  f f ggg3.
 
-   aa4   f  f  ggg4.
+   aa4  f f  ggg4.
 
    aa5  ggg5.
 
diff --git a/tp/t/results/misc_commands/test_allowcodebreaks.pl 
b/tp/t/results/misc_commands/test_allowcodebreaks.pl
index 42586815e2..ed6992651b 100644
--- a/tp/t/results/misc_commands/test_allowcodebreaks.pl
+++ b/tp/t/results/misc_commands/test_allowcodebreaks.pl
@@ -2061,7 +2061,7 @@ ddd’ ‘9aaa-bbb rrr_vv’ ‘fff-- --- minus−b aa-ttéff_gg 
aar-oman anc-ho
      in-example
 
    In w:
-Out of code — out-of-code. ‘1aaa’ ‘2aaa-’ ‘-3bbb’ ‘4aaa-bbb’  ‘ 5aaa-bb’ 
‘6aaa-bb ’ ‘ccc 7aaa-bbb’ ‘ccc 8aaa-bbb ddd’ ‘9aaa-bbb rrr_vv’ ‘fff-- --- 
minus−b aa-ttéff_gg aar-oman  anc-hor
+Out of code — out-of-code.  ‘1aaa’ ‘2aaa-’ ‘-3bbb’ ‘4aaa-bbb’ ‘ 5aaa-bb’ 
‘6aaa-bb ’ ‘ccc 7aaa-bbb’ ‘ccc 8aaa-bbb ddd’ ‘9aaa-bbb rrr_vv’ ‘fff-- --- 
minus−b aa-ttéff_gg aar-oman anc-hor
 ’ 
 
      in-example
diff --git a/tp/t/results/plaintext_tests/protect_spaces_on_line.pl 
b/tp/t/results/plaintext_tests/protect_spaces_on_line.pl
index 9a0b3c9b49..27d456dd1b 100644
--- a/tp/t/results/plaintext_tests/protect_spaces_on_line.pl
+++ b/tp/t/results/plaintext_tests/protect_spaces_on_line.pl
@@ -213,9 +213,9 @@ $result_floats{'protect_spaces_on_line'} = {};
 
 
 
-$result_converted{'plaintext'}->{'protect_spaces_on_line'} = 'Before samp.  
‘a’.  after samp, w in   w. after dot afterw
+$result_converted{'plaintext'}->{'protect_spaces_on_line'} = 'Before samp.  
‘a’.  after samp, w in w.  after dot afterw
 
-before samp.  ‘a’.  after samp, w in   w. after dot afterw
+before samp.  ‘a’.  after samp, w in w.  after dot afterw
 ';
 
 1;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]