texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp TODO Texinfo/Convert/Plaintext.pm t/...


From: Patrice Dumas
Subject: texinfo/tp TODO Texinfo/Convert/Plaintext.pm t/...
Date: Sun, 06 Feb 2011 19:49:59 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/02/06 19:49:59

Modified files:
        tp             : TODO 
        tp/Texinfo/Convert: Plaintext.pm 
        tp/t/results/indices: index_entry_before_node.pl 

Log message:
        For index entries,
        remove a 'lines' from $location if at the very end of a node
        since it will lead to the next node otherwise.
        
        Really use line count for lisoffloats.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/TODO?cvsroot=texinfo&r1=1.75&r2=1.76
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.72&r2=1.73
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/indices/index_entry_before_node.pl?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: TODO
===================================================================
RCS file: /sources/texinfo/texinfo/tp/TODO,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -b -r1.75 -r1.76
--- TODO        6 Feb 2011 16:43:19 -0000       1.75
+++ TODO        6 Feb 2011 19:49:58 -0000       1.76
@@ -44,9 +44,6 @@
 Test no empty line before and after a sectioning command.  With text, but
 also commands.
 
-in indices/index_entry_before_node, it would be better to have 4 lines
-associated to the index entry otherwise it goes to the next node.
-
 Following should be an error:
 @example
 @heading A heading

Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- Texinfo/Convert/Plaintext.pm        6 Feb 2011 16:43:20 -0000       1.72
+++ Texinfo/Convert/Plaintext.pm        6 Feb 2011 19:49:58 -0000       1.73
@@ -1681,13 +1681,13 @@
       $result = $self->_printindex($root);
       return $result;
     } elsif ($root->{'cmdname'} eq 'listoffloats') {
+      my $lines_count = 0;
       if ($root->{'extra'} and $root->{'extra'}->{'type'}
           and defined($root->{'extra'}->{'type'}->{'normalized'}) 
           and $self->{'floats'} 
           and $self->{'floats'}->{$root->{'extra'}->{'type'}->{'normalized'}}
           and 
@{$self->{'floats'}->{$root->{'extra'}->{'type'}->{'normalized'}}}) {
         push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0};
-        my $lines_count = 0;
         if (!$self->{'empty_lines_count'}) {
           $result .= "\n";
           $lines_count++;
@@ -1752,12 +1752,12 @@
         }
         $result .= "\n";
         $lines_count++;
-        $self->_add_lines_count($lines_count);
         $self->{'empty_lines_count'} = 1;
         pop @{$self->{'count_context'}};
       }
       $self->{'format_context'}->[-1]->{'paragraph_count'}++;
       $self->_add_text_count($result);
+      $self->_add_lines_count($lines_count);
       return $result;
     } elsif ($root->{'cmdname'} eq 'sp') {
       if ($root->{'extra'}->{'misc_args'}->[0]) {
@@ -1812,10 +1812,41 @@
   }
   if ($root->{'extra'} and $root->{'extra'}->{'index_entry'}) {
     my $location = $self->_add_location($root);
-    # FIXME: remove a 'lines' from $location if at the very end of a node
+    # remove a 'lines' from $location if at the very end of a node
     # since it will lead to the next node otherwise.
-    #if ($root->{'cmdname'} and $root->{'cmdname'} =~ /index/) {
-    #}
+    if ($root->{'cmdname'} and $root->{'cmdname'} =~ /index/) {
+      my $following_not_empty;
+      my @parents = @{$self->{'current_roots'}};
+      my @parent_contents = @{$self->{'current_contents'}};
+      while (@parents) {
+        my $parent = pop @parents;
+        my $parent_content = pop @parent_contents;
+        if ($parent->{'type'} and $parent->{'type'} eq 'paragraph') {
+          $following_not_empty = 1;
+          last;
+        }
+        foreach my $following_content (@$parent_content) {
+          unless (($following_content->{'type'} 
+                and ($following_content->{'type'} eq 'empty_line'
+                    or $ignored_types{$following_content->{'type'}}))
+              or ($following_content->{'cmdname'} 
+                  and ($following_content->{'cmdname'} eq 'c'  
+                       or $following_content->{'cmdname'} eq 'comment'))) {
+            $following_not_empty = 1;
+            last;
+          }
+        }
+        last if $following_not_empty;
+        if ($parent->{'cmdname'} and $root_commands{$parent->{'cmdname'}}) {
+          last;
+        }
+      }
+      if (! $following_not_empty) {
+        print STDERR "INDEX ENTRY $root->{'cmdname'} followed by empty lines\n"
+            if ($self->{'DEBUG'});
+        $location->{'lines'}--;
+      }
+    }
     $self->{'index_entries_line_location'}->{$root} = $location;
     print STDERR "INDEX ENTRY lines_count $location->{'lines'}, index_entry 
$location->{'index_entry'}\n" 
        if ($self->{'DEBUG'});
@@ -1928,6 +1959,7 @@
   if ($root->{'contents'}) {
     my @contents = @{$root->{'contents'}};
     push @{$self->{'current_contents'}}, address@hidden;
+    push @{$self->{'current_roots'}}, $root;
     while (@contents) {
       my $content = shift @contents;
       my $text = $self->_convert($content);
@@ -1936,6 +1968,7 @@
       $result .= $text;
     }
     pop @{$self->{'current_contents'}};
+    pop @{$self->{'current_roots'}};
   }
 
   # now closing. First, close types.

Index: t/results/indices/index_entry_before_node.pl
===================================================================
RCS file: 
/sources/texinfo/texinfo/tp/t/results/indices/index_entry_before_node.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/indices/index_entry_before_node.pl        6 Feb 2011 15:05:07 
-0000       1.1
+++ t/results/indices/index_entry_before_node.pl        6 Feb 2011 19:49:59 
-0000       1.2
@@ -684,7 +684,7 @@
 [index]
 * Menu:
 
-* lone entry:                            first.                 (line 5)
+* lone entry:                            first.                 (line 4)
 
 
 



reply via email to

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