texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/Converter.pm (converter_glob


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Converter.pm (converter_global_commands), tp/Texinfo/Convert/HTML.pm (output): handle the global unique commands similarly with the global multiple commands. remove now unused converter_global_commands(). Modify _set_global_multiple_commands such that it only set to the first, last or initial configuration values (replacing _unset_global_multiple_commands). Rename 'conf_default' as 'converter_init_conf' and add 'output_init_conf' for converters that modify the initia [...]
Date: Wed, 01 Sep 2021 19:26:36 -0400

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

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 53017db  * tp/Texinfo/Convert/Converter.pm 
(converter_global_commands), tp/Texinfo/Convert/HTML.pm (output): handle the 
global unique commands similarly with the global multiple commands.  remove now 
unused converter_global_commands(). Modify _set_global_multiple_commands such 
that it only set to the first, last or initial configuration values (replacing 
_unset_global_multiple_commands).  Rename 'conf_default' as 
'converter_init_conf' and add 'output_init_conf' for converters tha [...]
53017db is described below

commit 53017db90aa98149d9749e0922ddd1359e831fa4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Sep 2 01:26:27 2021 +0200

    * tp/Texinfo/Convert/Converter.pm (converter_global_commands),
    tp/Texinfo/Convert/HTML.pm (output):
    handle the global unique commands similarly with the global
    multiple commands.  remove now unused converter_global_commands().
    Modify _set_global_multiple_commands such that it only set to the
    first, last or initial configuration values (replacing
    _unset_global_multiple_commands).  Rename 'conf_default'
    as 'converter_init_conf' and add 'output_init_conf' for
    converters that modify the initial configuration per output,
    currently HTML.
    * tp/Texinfo/Common.pm (%document_settable_at_commands):
    add as a merge of %document_settable_multiple_at_commands and
    %document_settable_unique_at_commands.
---
 ChangeLog                                          |  16 +++
 tp/TODO                                            |  19 ++-
 tp/Texinfo/Common.pm                               |   6 +-
 tp/Texinfo/Convert/Converter.pm                    | 144 ++++++++++-----------
 tp/Texinfo/Convert/DocBook.pm                      |   5 -
 tp/Texinfo/Convert/HTML.pm                         |  10 +-
 tp/Texinfo/Convert/Info.pm                         |   4 +-
 tp/Texinfo/Convert/LaTeX.pm                        |   5 -
 tp/Texinfo/Convert/Plaintext.pm                    |   5 -
 .../no_titlepage_and_setchapternewpage_odd.tex     |   2 +-
 .../res_latex/two_setchapternewpage_odd_on.tex     |   2 +-
 11 files changed, 114 insertions(+), 104 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 581a784..82f6158 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2021-09-02  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/Converter.pm (converter_global_commands),
+       tp/Texinfo/Convert/HTML.pm (output):
+       handle the global unique commands similarly with the global
+       multiple commands.  remove now unused converter_global_commands().
+       Modify _set_global_multiple_commands such that it only set to the
+       first, last or initial configuration values (replacing
+       _unset_global_multiple_commands).  Rename 'conf_default'
+       as 'converter_init_conf' and add 'output_init_conf' for
+       converters that modify the initial configuration per output,
+       currently HTML.
+       * tp/Texinfo/Common.pm (%document_settable_at_commands):
+       add as a merge of %document_settable_multiple_at_commands and
+       %document_settable_unique_at_commands.
+
 2021-09-01  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm (%document_settable_at_commands)
diff --git a/tp/TODO b/tp/TODO
index c28d19f..a244e7b 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -32,13 +32,19 @@ nytprofhtml --open
 # firefox nytprof/index.html
 
 
-Documentation of tree in ParserNonXS.pm
-=======================================
+Documentation
+=============
+
+Tree documentation in ParserNonXS.pm
 
 replaced, elided, elided_block types.
 'extra'->'file' in replaced @include.
 
 
+For converter writers,
+'output_init_conf' and 'converter_init_conf'.
+
+
 Delayed bugs
 ============
 
@@ -245,10 +251,11 @@ DocBook
 Interrogations and remarks
 ==========================
 
-Instead of _set_global_multiple_commands and _unset_global_multiple_commands
-have a better granularity and do something per command, with the possibility
-to really revert everything, including things that are not set by set_conf.
-(There is a FIXME in the code).
+Instead of _set_global_multiple_commands have a better granularity and
+do something per command, with the possibility to really revert everything,
+including things that are not set by set_conf (There is a comment in the
+code above _set_global_multiple_commands)?  Not clear that it is really
+interesting, there is no clear use case for now.
 
 Should more Converter ignore the last new line (with type 
 last_raw_newline) of a raw block format?
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 9a2bcf7..db390a1 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -325,9 +325,11 @@ my @variable_other_settables = (
   'CSS_FILES', 'CSS_REFS', 'EXPANDED_FORMATS', 'INCLUDE_DIRECTORIES',
 );
 
+our %document_settable_at_commands = (%document_settable_multiple_at_commands,
+   %document_settable_unique_at_commands);
+
 my %valid_options;
-foreach my $var (keys(%document_settable_multiple_at_commands),
-         keys(%document_settable_unique_at_commands),
+foreach my $var (keys(%document_settable_at_commands),
          @command_line_settables, @variable_string_settables,
          @variable_other_settables) {
   $valid_options{$var} = 1;
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index f9e6712..54273f7 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -75,6 +75,7 @@ our %all_converters_defaults = (
   'fillcolumn'           => 72,
   'expanded_formats'     => undef,
   'structuring'          => undef,
+  # only HTML
   'IMAGE_LINK_PREFIX'    => undef,
   'NUMBER_SECTIONS'      => 1,
   'NUMBER_FOOTNOTES'     => 1,
@@ -112,11 +113,6 @@ sub converter_initialize($)
 {
 }
 
-sub converter_global_commands($)
-{
-  return ('documentlanguage', 'documentencoding');
-}
-
 sub output_internal_links($)
 {
   my $self = shift;
@@ -141,10 +137,9 @@ sub _informative_command_value($$)
   return undef;
 }
 
-# FIXME documentencoding handling is not reverted by resetting
-# a value with set_conf, so _unset_global_multiple_commands won't
-# reverse what _set_global_multiple_commands did through 
-# _informative_command.
+# REMARK documentencoding handling is not reverted by resetting
+# a value with set_conf, as the encodings are set using other
+# informations (possibly based on @documentencoding) in converter.
 sub _informative_command($$)
 {
   my $self = shift;
@@ -153,8 +148,6 @@ sub _informative_command($$)
   my $cmdname = $root->{'cmdname'};
   $cmdname = 'shortcontents' if ($cmdname eq 'summarycontents');
 
-  return if ($self->{'set'}->{$cmdname});
-
   my $value = $self->_informative_command_value($root);
   if (defined($value)) {
     $self->set_conf($cmdname, $value);
@@ -193,7 +186,7 @@ sub converter(;$)
       $converter->{$key} = $defaults{$key};
     }
   }
-  $converter->{'conf_default'} = \%defaults;
+  $converter->{'converter_init_conf'} = \%defaults;
   if (defined($conf)) {
     if ($conf->{'parser'}) {
       $converter->{'parser'} = $conf->{'parser'};
@@ -206,15 +199,6 @@ sub converter(;$)
 
       $converter->{'floats'} = $floats if ($floats);
       $converter->{'labels'} = $labels if ($labels);
-      foreach my $global_command ($converter->converter_global_commands()) {
-        if (defined($converter->{'extra'}->{$global_command})) {
-          my $root = $converter->{'extra'}->{$global_command};
-          # always set unique commands
-          if (ref($root) ne 'ARRAY') {
-            $converter->_informative_command($root);
-          }
-        }
-      }
       delete $conf->{'parser'};
     }
     foreach my $key (keys(%$conf)) {
@@ -270,48 +254,73 @@ sub output_files_information($)
   return $self->{'output_files'};
 }
 
-sub _set_global_multiple_commands($;$)
+# $MULTIPLE_COMMANDS_INDEX is 0, 1 or -1.
+# 0 means setting to the values before the document commands
+# (default and command-line).
+# 1 means setting to the first value for the command in the document
+# -1 means setting to the last value for the command in the document.
+#
+# For unique command, the last may be considered to be the same as the first.
+#
+# If a value was given in converter input, it is never reset by documents
+# @-commands values.
+#
+# Notice that the only effect is to use set_conf (directly or through
+# _informative_command), @-commands side effects or settings using other
+# customization is not set/reset.
+sub _set_global_multiple_commands($$)
 {
   my $self = shift;
   my $multiple_commands_index = shift;
-  $multiple_commands_index = 0 if (!defined($multiple_commands_index));
 
-  foreach my $global_command ($self->converter_global_commands()) {
-    if (defined($self->{'extra'}->{$global_command})
-        and ref($self->{'extra'}->{$global_command}) eq 'ARRAY') {
-      my $root = 
$self->{'extra'}->{$global_command}->[$multiple_commands_index];
-      if ($self->get_conf('DEBUG')) {
-        print STDERR "SET_global_multiple_commands($multiple_commands_index) 
$global_command\n";
-      }
-      $self->_informative_command($root);
-    }
+  my $init_conf;
+  if (defined($self->{'output_init_conf'})) {
+    # use in priority the initial configuration per output
+    $init_conf = $self->{'output_init_conf'};
+  } else {
+    $init_conf = $self->{'converter_init_conf'};
   }
-}
 
-# Notice that set_conf is used, which means that it is not possible to
-# customize what is done for those commands.  For documentencoding, for
-# example the values are not reset correctly, see the FIXME above.
-sub _unset_global_multiple_commands($)
-{
-  my $self = shift;
-
-  foreach my $global_command ($self->converter_global_commands()) {
-    if (defined($self->{'extra'}->{$global_command})
-        and ref($self->{'extra'}->{$global_command}) eq 'ARRAY') {
-      if (exists($self->{'conf_default'}->{$global_command})) {
-        if ($self->get_conf('DEBUG')) {
-          my $default = 'UNDEF';
-          $default = $self->{'conf_default'}->{$global_command} 
-            if (defined($self->{'conf_default'}->{$global_command}));
-          my $set = 0;
-          $set = 1 if ($self->{'set'}->{$global_command});
-          print STDERR "UNSET_global_multiple_commands $global_command ($set): 
$default\n";
-        }
-        if (Texinfo::Common::valid_option($global_command)) {
-          $self->set_conf($global_command, 
$self->{'conf_default'}->{$global_command});
-        } else {
-          $self->{$global_command} = 
$self->{'conf_default'}->{$global_command};
+  # gather the defaults
+  my $commands_init = {};
+  foreach my $global_command 
(keys(%Texinfo::Common::document_settable_at_commands)) {
+    if (defined($init_conf->{$global_command})) {
+      $commands_init->{$global_command} = $init_conf->{$global_command};
+    } elsif 
(defined($Texinfo::Common::document_settable_at_commands{$global_command})) {
+      $commands_init->{$global_command} =
+            $Texinfo::Common::document_settable_at_commands{$global_command};
+    }
+  }
+  if ($multiple_commands_index == 0) {
+    foreach my $global_command (keys(%{$commands_init})) {
+      # for commands not appearing in the document, this should set the
+      # same value, the converter initialization value
+      $self->set_conf($global_command, $commands_init->{$global_command});
+    }
+  } else {
+    foreach my $global_command (keys(%$commands_init)) {
+      my $root;
+      if (defined($self->{'extra'}->{$global_command})
+          and ref($self->{'extra'}->{$global_command}) eq 'ARRAY') {
+        # used when $multiple_commands_index == 1
+        my $index_in_global_commands = 0;
+        if ($multiple_commands_index < 0) {
+          $index_in_global_commands = -1;
         }
+        $root = 
$self->{'extra'}->{$global_command}->[$index_in_global_commands];
+      } elsif (defined($self->{'extra'}->{$global_command})) {
+        # unique command, first and last are the same
+        $root = $self->{'extra'}->{$global_command};
+      }
+      if ($self->get_conf('DEBUG')) {
+        print STDERR "SET_global_multiple_commands($multiple_commands_index) 
$global_command\n";
+      }
+      if (defined($root)) {
+        $self->_informative_command($root);
+      } else {
+        # commands not appearing in the document, this should set the
+        # same value, the converter initialization value
+        $self->set_conf($global_command, $commands_init->{$global_command});
       }
     }
   }
@@ -429,7 +438,6 @@ sub _set_outfile($$$)
       my $dir = File::Spec->canonpath($self->get_conf('SUBDIR'));
       $outfile = File::Spec->catfile($dir, $outfile);
     }
-    #$self->set_conf('OUTFILE', $outfile);
   } else {
     $document_name = $self->get_conf('OUTFILE');
     $document_name =~ s/\.[^\.]*$//;
@@ -1566,9 +1574,6 @@ Texinfo::Convert::Converter - Parent class for Texinfo 
tree converters
     my $self = shift;
     $self->{'document_context'} = [{}];
   }
-  sub converter_global_commands($) {
-    return ('documentlanguage', documentencoding', 'paragraphindent');
-  }
 
   sub convert($$) {
     ...
@@ -1592,10 +1597,10 @@ Texinfo::Convert::Converter is a super class that can 
be used to
 simplify converters initialization.  The class also provide some 
 useful methods.
 
-In turn, the converter should define some methods.  Three are 
-optional, C<converter_defaults>, C<converter_initialize> and 
-C<converter_global_commands> and used for initialization, to 
-give C<Texinfo::Convert::Converter> some informations.
+In turn, the converter should define some methods.  Two are
+optional, C<converter_defaults>, C<converter_initialize> and
+used for initialization, to give C<Texinfo::Convert::Converter>
+some informations.
 
 The C<convert_tree> method is more or less mandatory and should 
 convert portions of Texinfo tree.  The C<output> and C<convert> 
@@ -1642,7 +1647,7 @@ also initialized as a L<Texinfo::Report>.
 
 =back
 
-To help with these initializations, the modules can define three methods:
+To help with these initializations, the modules can define two methods:
 
 =over
 
@@ -1651,15 +1656,10 @@ To help with these initializations, the modules can 
define three methods:
 The converter can provide a defaults hash for configuration options.
 The I<$options> hash reference holds options for the converter.
 
-=item @global_commands = $converter->converter_global_commands()
-
-The list returned is the list of Texinfo global commands (like 
-C<@paragraphindent>, C<@documentlanguage>...) that are relevant for the
-converter.
-
 =item converter_initialize
 
-This method is called at the end of the converter initialization.
+This method is called at the end of the Texinfo::Convert::Converter
+converter initialization.
 
 =back
 
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index 14ab6a0..f30b908 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -192,11 +192,6 @@ my %docbook_global_commands = (
   'documentlanguage' => 1,
 );
 
-sub converter_global_commands($)
-{
-  return keys(%docbook_global_commands);
-}
-
 my %default_args_code_style 
   = %Texinfo::Convert::Converter::default_args_code_style;
 my %regular_font_style_commands = 
%Texinfo::Common::regular_font_style_commands;
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 9e67f26..6947f73 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -1284,11 +1284,6 @@ foreach my $misc_command(@informative_global_commands,
   $kept_misc_commands{$misc_command} = 1;
 }
 
-sub converter_global_commands($)
-{
-  return @informative_global_commands;
-}
-
 foreach my $misc_command (keys(%misc_commands)) {
   $default_commands_conversion{$misc_command} = undef
     unless ($kept_misc_commands{$misc_command});
@@ -7350,6 +7345,11 @@ sub output($$)
   }
   $self->set_conf('EXTERNAL_CROSSREF_SPLIT', $self->get_conf('SPLIT'));
 
+  # the configuration has potentially been modified for
+  # this output file especially.  Set a corresponding initial
+  # configuration.
+  $self->{'output_init_conf'} = { %{$self->{'conf'}} };
+
   my $setup_status = $self->run_stage_handlers($root, 'setup');
   return undef unless($setup_status);
 
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index acddf4a..0340a63 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -318,7 +318,7 @@ sub _info_header($)
 {
   my $self = shift;
 
-  $self->_set_global_multiple_commands();
+  $self->_set_global_multiple_commands(1);
   my $paragraph = Texinfo::Convert::Paragraph->new();
   my $result = add_text($paragraph, "This is ");
   # This ensures that spaces in file are kept.
@@ -366,7 +366,7 @@ sub _info_header($)
     }
     $self->{'ignored_commands'}->{'direntry'} = 1;
   }
-  $self->_unset_global_multiple_commands();
+  $self->_set_global_multiple_commands(0);
   return $result;
 }
 
diff --git a/tp/Texinfo/Convert/LaTeX.pm b/tp/Texinfo/Convert/LaTeX.pm
index 2d3ef7e..29697c1 100644
--- a/tp/Texinfo/Convert/LaTeX.pm
+++ b/tp/Texinfo/Convert/LaTeX.pm
@@ -689,11 +689,6 @@ sub converter_defaults($$)
   return %defaults;
 }
 
-sub converter_global_commands($)
-{
-  return @informative_global_commands;
-}
-
 sub converter_initialize($)
 {
   my $self = shift;
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 6d99b82..30c7504 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -376,11 +376,6 @@ sub converter_defaults($$)
   return %defaults;
 }
 
-sub converter_global_commands($)
-{
-  return @informative_global_commands;
-}
-
 sub converter_initialize($)
 {
   my $self = shift;
diff --git 
a/tp/t/results/latex_tests/no_titlepage_and_setchapternewpage_odd/res_latex/no_titlepage_and_setchapternewpage_odd.tex
 
b/tp/t/results/latex_tests/no_titlepage_and_setchapternewpage_odd/res_latex/no_titlepage_and_setchapternewpage_odd.tex
index a4376ce..656c447 100644
--- 
a/tp/t/results/latex_tests/no_titlepage_and_setchapternewpage_odd/res_latex/no_titlepage_and_setchapternewpage_odd.tex
+++ 
b/tp/t/results/latex_tests/no_titlepage_and_setchapternewpage_odd/res_latex/no_titlepage_and_setchapternewpage_odd.tex
@@ -89,7 +89,7 @@ roundcorner=10pt}
 \makeatletter
 
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{\GNUTexinfoplaceholder{setchapternewpage
 placeholder}\clearpage}{}{}
 \makeatother
-\GNUTexinfosetdoubleheader{No Title}%
+\GNUTexinfosetsingleheader{}%
 
 \makeatletter
 \patchcmd{\chapter}{\GNUTexinfoplaceholder{setchapternewpage 
placeholder}\clearpage}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}
diff --git 
a/tp/t/results/latex_tests/two_setchapternewpage_odd_on/res_latex/two_setchapternewpage_odd_on.tex
 
b/tp/t/results/latex_tests/two_setchapternewpage_odd_on/res_latex/two_setchapternewpage_odd_on.tex
index f100c89..d298b4f 100644
--- 
a/tp/t/results/latex_tests/two_setchapternewpage_odd_on/res_latex/two_setchapternewpage_odd_on.tex
+++ 
b/tp/t/results/latex_tests/two_setchapternewpage_odd_on/res_latex/two_setchapternewpage_odd_on.tex
@@ -89,7 +89,7 @@ roundcorner=10pt}
 \makeatletter
 
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{\GNUTexinfoplaceholder{setchapternewpage
 placeholder}\clearpage}{}{}
 \makeatother
-\GNUTexinfosetdoubleheader{No Title}%
+\GNUTexinfosetsingleheader{}%
 
 \makeatletter
 \patchcmd{\chapter}{\GNUTexinfoplaceholder{setchapternewpage 
placeholder}\clearpage}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}



reply via email to

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