texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...


From: Patrice Dumas
Subject: texinfo/tp texi2any.pl Texinfo/Common.pm Texinf...
Date: Thu, 24 Jan 2013 01:41:00 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        13/01/24 01:41:00

Modified files:
        tp             : texi2any.pl 
        tp/Texinfo     : Common.pm Structuring.pm 
        tp/Texinfo/Convert: Converter.pm Plaintext.pm 
Added files:
        tp/t           : indent_menus_descriptions.t 

Log message:
        New tree transformation, indent_menus_descriptions.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/texi2any.pl?cvsroot=texinfo&r1=1.162&r2=1.163
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Common.pm?cvsroot=texinfo&r1=1.172&r2=1.173
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.142&r2=1.143
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.99&r2=1.100
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.233&r2=1.234
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/indent_menus_descriptions.t?cvsroot=texinfo&rev=1.1

Patches:
Index: texi2any.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/texi2any.pl,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -b -r1.162 -r1.163
--- texi2any.pl 17 Jan 2013 00:13:51 -0000      1.162
+++ texi2any.pl 24 Jan 2013 01:40:59 -0000      1.163
@@ -1222,6 +1222,10 @@
   if ($tree_transformations{'complete_tree_nodes_menus'}) {
     Texinfo::Structuring::complete_tree_nodes_menus($parser, $tree);
   }
+  if ($tree_transformations{'indent_menus_descriptions'}) {
+    Texinfo::Convert::Plaintext::indent_menus_descriptions(undef, $parser);
+  }
+
   if ($tree_transformations{'regenerate_master_menu'}) {
     Texinfo::Structuring::regenerate_master_menu($parser);
   }

Index: Texinfo/Common.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Common.pm,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -b -r1.172 -r1.173
--- Texinfo/Common.pm   21 Jan 2013 00:42:57 -0000      1.172
+++ Texinfo/Common.pm   24 Jan 2013 01:40:59 -0000      1.173
@@ -253,7 +253,7 @@
   'TREE_TRANSFORMATIONS', 'BASEFILENAME_LENGTH',
   'TEXTCONTENT_COMMENT', 'XREF_USE_FLOAT_LABEL', 'XREF_USE_NODE_NAME_ARG',
   'MACRO_BODY_IGNORES_LEADING_SPACE', 'CHECK_HTMLXREF',
-  'TEXINFO_DTD_VERSION',
+  'TEXINFO_DTD_VERSION', 'TEXINFO_COLUMN_FOR_DESCRIPTION',
 );
 # Not strings. 
 # FIXME To be documented somewhere, but where?
@@ -329,7 +329,8 @@
 foreach my $valid_transformation ('simple_menus', 
     'fill_gaps_in_sectioning', 'move_index_entries_after_items',
     'insert_nodes_for_sectioning_commands',
-    'complete_tree_nodes_menus', 'regenerate_master_menu') {
+    'complete_tree_nodes_menus', 'regenerate_master_menu',
+    'indent_menus_descriptions') {
   $valid_tree_transformations{$valid_transformation} = 1;
 }
 

Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -b -r1.142 -r1.143
--- Texinfo/Structuring.pm      21 Jan 2013 21:00:18 -0000      1.142
+++ Texinfo/Structuring.pm      24 Jan 2013 01:40:59 -0000      1.143
@@ -2073,14 +2073,14 @@
 
   if ($self->{'info'} and $self->{'info'}->{'unassociated_menus'}) {
     foreach my $menu (@{$self->{'info'}->{'unassociated_menus'}}) {
-      menu_to_simple_menu ($menu);
+      menu_to_simple_menu($menu);
     }
   }
   if ($self->{'nodes'} and @{$self->{'nodes'}}) {
     foreach my $node (@{$self->{'nodes'}}) {
       if ($node->{'menus'}) {
         foreach my $menu (@{$node->{'menus'}}) {
-          menu_to_simple_menu ($menu);
+          menu_to_simple_menu($menu);
         }
       }
     }

Index: Texinfo/Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -b -r1.99 -r1.100
--- Texinfo/Convert/Converter.pm        23 Jan 2013 18:54:51 -0000      1.99
+++ Texinfo/Convert/Converter.pm        24 Jan 2013 01:40:59 -0000      1.100
@@ -100,6 +100,7 @@
   'DEBUG'                => 0,
   'TEST'                 => 0,
   'translated_commands'  => {'error' => 'address@hidden',},
+  'TEXINFO_COLUMN_FOR_DESCRIPTION' => 32, # same as emacs
 );
 
 # For translation of in document string.

Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.233
retrieving revision 1.234
diff -u -b -r1.233 -r1.234
--- Texinfo/Convert/Plaintext.pm        7 Jan 2013 21:42:15 -0000       1.233
+++ Texinfo/Convert/Plaintext.pm        24 Jan 2013 01:41:00 -0000      1.234
@@ -127,7 +127,7 @@
 #            of columns, actual indentation.  In general, it is better not 
 #            to have formatters in parallel, but it may happen.
 # count_context: holds the bytes count, the lines count and the location
-#            of the commands that have their byte count or llines count
+#            of the commands that have their byte count or lines count
 #            recorded.  It is set for out of document formatting to avoid
 #            counting some converted text, but it is also set when it has
 #            to be modified afterwards, for aligned commands or multitable
@@ -457,7 +457,7 @@
   
   my $fh;
   if ($outfile ne '') {
-    $fh = $self->Texinfo::Common::open_out ($outfile);
+    $fh = $self->Texinfo::Common::open_out($outfile);
     if (!$fh) {
       $self->document_error(sprintf($self->__("Could not open %s for writing: 
%s"),
                                     $outfile, $!));
@@ -2591,15 +2591,15 @@
         print STDERR "     --> $result" if ($self->get_conf('DEBUG'));
       }
     } elsif ($root->{'type'} eq 'menu_entry') {
-      my $menu_entry_internal_node;
-      if ($root->{'extra'} and $root->{'extra'}->{'menu_entry_node'}
-          and defined($root->{'extra'}->{'menu_entry_node'}->{'normalized'})
-          and !$root->{'extra'}->{'menu_entry_node'}->{'manual_content'}
-          and $self->{'labels'}
-          and 
$self->{'labels'}->{$root->{'extra'}->{'menu_entry_node'}->{'normalized'}}) {
-        $menu_entry_internal_node 
-          = 
$self->{'labels'}->{$root->{'extra'}->{'menu_entry_node'}->{'normalized'}};
-      }
+      #my $menu_entry_internal_node;
+      #if ($root->{'extra'} and $root->{'extra'}->{'menu_entry_node'}
+      #    and defined($root->{'extra'}->{'menu_entry_node'}->{'normalized'})
+      #    and !$root->{'extra'}->{'menu_entry_node'}->{'manual_content'}
+      #    and $self->{'labels'}
+      #    and 
$self->{'labels'}->{$root->{'extra'}->{'menu_entry_node'}->{'normalized'}}) {
+      #  $menu_entry_internal_node 
+      #    = 
$self->{'labels'}->{$root->{'extra'}->{'menu_entry_node'}->{'normalized'}};
+      #}
       foreach my $arg (@{$root->{'args'}}) {
         if ($arg->{'type'} eq 'menu_entry_node') {
           $result .= $self->_convert({'type' => '_code',
@@ -2891,6 +2891,100 @@
   return $result;
 }
 
+sub indent_menu_descriptions($$)
+{
+  my $self = shift;
+  my $menu = shift;
+
+  foreach my $content (@{$menu->{'contents'}}) {
+    if ($content->{'type'} and $content->{'type'} eq 'menu_entry') {
+      my $result = '';
+      my $node_seen = 0;
+      foreach my $arg (@{$content->{'args'}}) {
+        if ($arg->{'type'} eq 'menu_entry_node') {
+          $result .= $self->_convert({'type' => '_code',
+                                      'contents' => $arg->{'contents'}});
+          $node_seen = 1;
+        } else {
+          # the separator appearing after the node is modified
+          if ($arg->{'type'} eq 'menu_entry_separator' and $node_seen) {
+            $arg->{'text'} =~ s/\s*$//;
+          }
+          $result .= $self->_convert($arg);
+          if ($arg->{'type'} eq 'menu_entry_separator' and $node_seen) {
+            my $length = Texinfo::Convert::Unicode::string_width($result);
+            my $description_indent 
+              = $self->get_conf('TEXINFO_COLUMN_FOR_DESCRIPTION');
+            if ($length >= $description_indent) {
+              $arg->{'text'} .= ' ';
+            } else {
+              $arg->{'text'} .= ' ' x ($description_indent - $length);
+            }
+            last;
+          } elsif ($arg->{'type'} eq 'menu_entry_description') {
+            # This should never happen, but this is a safeguard for 
+            # incorrect trees.
+            last;  
+          }
+        }
+      }
+      #print STDERR "$result";
+    }
+  }
+}
+
+sub indent_menus_descriptions($;$)
+{
+  my $self = shift;
+  my $parser = shift;
+
+  if (!defined($self)) {
+    # setup a converter for menu
+    if (!defined($parser)) {
+      return undef;
+    }
+    $self = Texinfo::Convert::Plaintext->converter({'parser' => $parser});
+  } elsif (!defined($parser)) {
+    if (!defined($self->{'parser'})) {
+      return undef;
+    }
+    $parser = $self->{'parser'};
+  }
+
+  # setup the converter as if it was in a menu
+  my $cmdname = 'menu';
+  push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0,
+                                     'locations' => []};
+  push @{$self->{'context'}}, $cmdname;
+  push @{$self->{'format_context'}},
+           { 'cmdname' => $cmdname,
+             'paragraph_count' => 0,
+             'indent_level' =>
+                 $self->{'format_context'}->[-1]->{'indent_level'},
+           };
+  my $preformatted = $self->new_formatter('unfilled');
+  push @{$self->{'formatters'}}, $preformatted;
+
+  if ($parser->{'info'} and $parser->{'info'}->{'unassociated_menus'}) {
+    foreach my $menu (@{$parser->{'info'}->{'unassociated_menus'}}) {
+      $self->indent_menu_descriptions($menu);
+    }
+  }
+  if ($parser->{'nodes'} and @{$parser->{'nodes'}}) {
+    foreach my $node (@{$parser->{'nodes'}}) {
+      if ($node->{'menus'}) {
+        foreach my $menu (@{$node->{'menus'}}) {
+          $self->indent_menu_descriptions($menu);
+        }
+      }
+    }
+  }
+  pop @{$self->{'formatters'}};
+  pop @{$self->{'context'}};
+  pop @{$self->{'format_context'}};
+  pop @{$self->{'count_context'}};
+}
+
 1;
 
 __END__

Index: t/indent_menus_descriptions.t
===================================================================
RCS file: t/indent_menus_descriptions.t
diff -N t/indent_menus_descriptions.t
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/indent_menus_descriptions.t       24 Jan 2013 01:41:00 -0000      1.1
@@ -0,0 +1,48 @@
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 2 };
+
+use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
+use lib 'maintain/lib/libintl-perl/lib/';
+use lib 'maintain/lib/Text-Unidecode/lib/';
+use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Convert::Plaintext;
+use Texinfo::Convert::Texinfo;
+
+ok(1);
+
+my $in = '
address@hidden
+Comment
+
+* a: (!unknown_m)b.   d
+* (!unknown_m)c  ::     d1
+* (!unknown_m)f ::
+* (!unknown_m)g ::    
+* label:   (!unknown_m)h  .
+* (!unknown_m)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiii::    d
address@hidden menu
+';
+
+my $reference = '
address@hidden
+Comment
+
+* a: (!unknown_m)b.             d
+* (!unknown_m)c  ::             d1
+* (!unknown_m)f ::              
+* (!unknown_m)g ::              
+* label:   (!unknown_m)h  .     
+* (!unknown_m)iiiiiiiiiiiiiiiiiiiiiiiiiiiiiii:: d
address@hidden menu
+';
+
+my $parser = Texinfo::Parser::parser();
+my $tree = $parser->parse_texi_text($in);
+Texinfo::Convert::Plaintext::indent_menus_descriptions(undef, $parser);
+my $out = Texinfo::Convert::Texinfo::convert($tree);
+
+is ($out, $reference, 'indent menu descriptions test');
+
+#print STDERR "$out\n";



reply via email to

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