texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 15 Apr 2024 16:46:36 -0400 (EDT)

branch: master
commit 50ed56edb23ce5bae3de03dd6d872c7bade9ff3b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Apr 15 22:46:18 2024 +0200

    * tp/Texinfo/XS/structuring_transfo/transformations.c
    (reference_to_arg_internal): fix flag set for internal reference
    removal and set it only if an element was actually removed.
    
    * tp/Texinfo/XS/structuring_transfo/transformations.c
    (regenerate_master_menu): set the flag corresponding to modified
    internal references if needed.
    
    * tp/Texinfo/Transformations.pm (_reference_to_arg)
    (reference_to_arg_in_tree),
    tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
    (reference_to_arg_in_tree): add a document argument to
    reference_to_arg_in_tree and _reference_to_arg.  Remove removed
    reference command from document internal references.
    Update callers.
---
 ChangeLog                                          | 18 +++++++++++++++++
 tp/Texinfo/Transformations.pm                      | 23 ++++++++++++++++------
 .../XS/structuring_transfo/StructuringTransfoXS.xs | 15 ++++++++++----
 .../XS/structuring_transfo/transformations.c       | 11 ++++++++---
 tp/t/reference_to_text_in_tree.t                   |  2 +-
 5 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7a22acbbdc..08e5c11f75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2024-04-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/structuring_transfo/transformations.c
+       (reference_to_arg_internal): fix flag set for internal reference
+       removal and set it only if an element was actually removed.
+
+       * tp/Texinfo/XS/structuring_transfo/transformations.c
+       (regenerate_master_menu): set the flag corresponding to modified
+       internal references if needed.
+
+       * tp/Texinfo/Transformations.pm (_reference_to_arg)
+       (reference_to_arg_in_tree),
+       tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+       (reference_to_arg_in_tree): add a document argument to
+       reference_to_arg_in_tree and _reference_to_arg.  Remove removed
+       reference command from document internal references.
+       Update callers.
+
 2024-04-15  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm (remove_from_array): add a simple function to
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index c4f106b549..ad540d1d77 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -232,11 +232,18 @@ sub _reference_to_arg($$$)
 {
   my $type = shift;
   my $current = shift;
+  my $document = shift;
 
-  # FIXME remove from internal references list?
   if ($current->{'cmdname'} and
       $Texinfo::Commands::ref_commands{$current->{'cmdname'}}
       and $current->{'args'}) {
+
+    # remove from internal references
+    if ($document) {
+      my $internal_references = $document->internal_references_information();
+      Texinfo::Common::remove_from_array($internal_references, $current);
+    }
+
     my @args_try_order;
     if ($current->{'cmdname'} eq 'inforef'
         or $current->{'cmdname'} eq 'link') {
@@ -268,11 +275,13 @@ sub _reference_to_arg($$$)
   }
 }
 
-sub reference_to_arg_in_tree($)
+sub reference_to_arg_in_tree($;$)
 {
   my $tree = shift;
+  my $document = shift;
 
-  return Texinfo::ManipulateTree::modify_tree($tree, \&_reference_to_arg);
+  return Texinfo::ManipulateTree::modify_tree($tree, \&_reference_to_arg,
+                                              $document);
 }
 
 # prepare and add a new node as a possible cross reference targets
@@ -325,7 +334,7 @@ sub _new_node($$;$)
   # in menu entry with label
   $node_tree
     = Texinfo::ManipulateTree::protect_node_after_label_in_tree($node_tree);
-  $node_tree = reference_to_arg_in_tree($node_tree);
+  $node_tree = reference_to_arg_in_tree($node_tree, $document);
 
   my $empty_node = 0;
   if (!$node_tree->{'contents'}
@@ -1036,14 +1045,16 @@ defined they are used for error reporting in case an 
hash character could not
 be protected because it appeared in a raw formatted environment (C<@tex>,
 C<@html>...).
 
-=item $modified_tree = reference_to_arg_in_tree($tree)
+=item $modified_tree = reference_to_arg_in_tree($tree, $document)
 X<C<reference_to_arg_in_tree>>
 
 Modify I<$tree> by converting reference @-commands to simple text using one of
 the arguments.  This transformation can be used, for example, to remove
 reference @-command from constructed node names trees, as node names cannot
 contain reference @-command while there could be some in the tree used in input
-for the node name tree.
+for the node name tree.  The I<$document> argument is optional.  If given,
+the converted reference @-command is removed from the I<$document> internal
+references list.
 
 A I<$modified_tree> is not systematically returned, if the I<$tree> in argument
 is not replaced, undef may also be returned.
diff --git a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs 
b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
index d34a981c83..c04df2545e 100644
--- a/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
+++ b/tp/Texinfo/XS/structuring_transfo/StructuringTransfoXS.xs
@@ -145,13 +145,20 @@ move_index_entries_after_items_in_tree (SV *tree_in)
 # argument could be modified.  Here, tree_in is always a container
 # that is not modified, so there is no need to return a tree.
 void
-reference_to_arg_in_tree (SV *tree_in)
+reference_to_arg_in_tree (SV *tree_in, SV *document_in=0)
     PREINIT:
+        DOCUMENT *tree_document = 0;
         DOCUMENT *document = 0;
      CODE:
-        document = get_sv_tree_document (tree_in, "reference_to_arg_in_tree");
-        if (document)
-          reference_to_arg_in_tree (document->tree, document);
+        tree_document
+          = get_sv_tree_document (tree_in, "reference_to_arg_in_tree");
+        /* in general will be the same as tree_document, in case it is not,
+           perhaps if the tree_in is a subtree of document_in tree,
+           find independently */
+        if (document_in)
+           document = get_sv_document_document (document_in, 0);
+        if (tree_document)
+          reference_to_arg_in_tree (tree_document->tree, document);
 
 void
 associate_internal_references (SV *document_in)
diff --git a/tp/Texinfo/XS/structuring_transfo/transformations.c 
b/tp/Texinfo/XS/structuring_transfo/transformations.c
index f89d4923a7..def1df8b48 100644
--- a/tp/Texinfo/XS/structuring_transfo/transformations.c
+++ b/tp/Texinfo/XS/structuring_transfo/transformations.c
@@ -886,8 +886,10 @@ reference_to_arg_internal (const char *type,
       if (document && document->internal_references
           && document->internal_references->number > 0)
         {
-          remove_element_from_list (document->internal_references, e);
-          document->modified_information |= F_DOCM_labels_list;
+          const ELEMENT *removed_internal_ref =
+              remove_element_from_list (document->internal_references, e);
+          if (removed_internal_ref)
+            document->modified_information |= F_DOCM_internal_references;
         }
       if (document)
         document->modified_information |= F_DOCM_tree;
@@ -1191,7 +1193,10 @@ regenerate_master_menu (DOCUMENT *document, int 
use_sections)
                                 remove_element_from_list (
                                         document->internal_references,
                                                         entry_content);
-                              if (!removed_internal_ref)
+                              if (removed_internal_ref)
+                                document->modified_information
+                                            |= F_DOCM_internal_references;
+                              else
                                 {
                                   char *removed_internal_texi
                                      = convert_to_texinfo (entry_content);
diff --git a/tp/t/reference_to_text_in_tree.t b/tp/t/reference_to_text_in_tree.t
index 7c637d1598..3d5f62b486 100644
--- a/tp/t/reference_to_text_in_tree.t
+++ b/tp/t/reference_to_text_in_tree.t
@@ -24,7 +24,7 @@ sub run_test($$$)
   my $document = $parser->parse_texi_piece($in);
   my $tree = $document->tree();
 
-  Texinfo::Transformations::reference_to_arg_in_tree($tree);
+  Texinfo::Transformations::reference_to_arg_in_tree($tree, $document);
   # rebuild tree
   $tree = $document->tree();
 



reply via email to

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