[latex3-commits] [git/LaTeX3-latex3-latex2e] apdf161: Rename code token list to "@@~<name>" (fixes apdf142) (4f6ec99a)

PhelypeOleinik phelype.oleinik at latex-project.org
Wed Sep 9 15:35:56 CEST 2020


Repository : https://github.com/latex3/latex2e
On branch  : apdf161
Link       : https://github.com/latex3/latex2e/commit/4f6ec99af66bb61fac8b5633b3314a04a13df0ce

>---------------------------------------------------------------

commit 4f6ec99af66bb61fac8b5633b3314a04a13df0ce
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Wed Sep 9 10:35:56 2020 -0300

    Rename code token list to "@@~<name>" (fixes apdf142)


>---------------------------------------------------------------

4f6ec99af66bb61fac8b5633b3314a04a13df0ce
 base/lthooks.dtx | 161 +++++++++++++++++++++++++++----------------------------
 1 file changed, 80 insertions(+), 81 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 3520ecd1..40480f1d 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -1639,7 +1639,7 @@
 %
 % \subsection{Providing new hooks}
 %
-% \begin{macro}{\g_@@_..._code_prop,\g_@@_..._code_tl,\g_@@_..._code_next_tl}
+% \begin{macro}{\g_@@_..._code_prop,\@@~...,\g_@@_..._code_next_tl}
 %
 %    Hooks have a \meta{name} and for each hook we have to provide a number of
 %    data structures. These are
@@ -1655,7 +1655,7 @@
 %    (reverse) sorted to ensure that two labels always point to the same
 %    token list.  For global rules, the \meta{name} is |??|.
 %
-%    \item[\cs{g_@@_\meta{name}_code_tl}] The code that is actually executed
+%    \item[\cs{@@~\meta{name}}] The code that is actually executed
 %    when the hook is called in the document is stored in this token
 %    list. It is constructed from the code chunks applying the
 %    information.
@@ -1704,7 +1704,7 @@
 %    This is only used by the actual code of the current hook, so
 %    declare it normally:
 %    \begin{macrocode}
-       \tl_new:c { g_@@_#1_code_tl }
+       \tl_new:c { @@~#1 }
 %    \end{macrocode}
 %    Now ensure that the base data structure for the hook exists:
 %    \begin{macrocode}
@@ -1925,24 +1925,23 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[EXP]{\@@_make_name:n}
+% \begin{macro}[EXP]{\@@_make_name:n,\@@_make_name:w}
 %   Provides a standard sanitisation of a hook's name.
 %   It uses \cs{cs:w} to build a control sequence out of the hook name,
 %   then uses \cs{cs_to_str:N} to get the string representation of that,
 %   without the escape character.  \cs{cs:w}-based expansion is used
 %   instead of |e|-based because Unicode characters don't behave well
-%   inside \cs{expanded}.  The macro adds the \cs{@@-|} prefix to the
-%   hook name to avoid leaving \enquote{public} control sequences
-%   defined (as \cs{relax}) in TeX's memory.
+%   inside \cs{expanded}.  The macro adds the \cs{@@~} prefix to the
+%   hook name to reuse the hook's code token list to build the csname
+%   and avoid leaving \enquote{public} control sequences defined
+%   (as~\cs{relax}) in TeX's memory.
 %    \begin{macrocode}
 \cs_new:Npn \@@_make_name:n #1
   {
-    \exp_after:wN \@@_hook_name_clean:w
-      \exp:w \exp_end_continue_f:w
-      \exp_after:wN \cs_to_str:N \cs:w @@-| #1 \cs_end:
+    \exp_after:wN \exp_after:wN \exp_after:wN \@@_make_name:w
+    \exp_after:wN \token_to_str:N \cs:w g@@ ~ #1 \cs_end:
   }
-\exp_last_unbraced:NNo
-\cs_new:Npn \@@_hook_name_clean:w \tl_to_str:n { @@-| } { }
+\cs_new:Npn \@@_make_name:w #1#2 ~ { }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -2393,7 +2392,7 @@
 %
 % \begin{macro}{
 %     \g_@@_??_code_prop,
-%     \g_@@_??_code_tl,
+%     \@@~??,
 %     \g_@@_??_reversed_tl,
 %   }
 %
@@ -2408,11 +2407,11 @@
 %    lot things should be fast, so this is not done with \texttt{c}
 %    expansion in the code later on.
 %
-%    \cs{g_@@_??_code_tl} isn't used, but it has to be defined to trick
+%    \cs{@@~??} isn't used, but it has to be defined to trick
 %    the code into thinking that \verb=??= is actually a hook.
 %    \begin{macrocode}
 \prop_new:c {g_@@_??_code_prop}
-\prop_new:c {g_@@_??_code_tl}
+\prop_new:c {@@~??}
 %    \end{macrocode}
 %
 %    Default rules are always given in normal ordering (never in
@@ -2631,7 +2630,7 @@
      { \iow_term:x{^^JAll~ initialized~ (non-empty)~ hooks:}
        \prop_map_inline:Nn \g_@@_used_prop
            { \iow_term:x{^^J~ ##1~ ->~
-               \exp_not:v {g_@@_##1_code_tl}~ }
+               \exp_not:v {@@~##1}~ }
            }
      }
 %    \end{macrocode}
@@ -2670,7 +2669,7 @@
 %    If there aren't any code
 %    chunks for the current hook, there is no point in even starting
 %    the sorting routine so we make a quick test for that and in that
-%    case just update \cs{g_@@_\meta{hook}_code_tl} to hold the next
+%    case just update \cs{@@~\meta{hook}} to hold the next
 %    code. If there are code chunks we call
 %    \cs{@@_initialize_single:NNNn} and pass to it ready made csnames
 %    as they are needed several times inside. This way we save a bit
@@ -2679,7 +2678,7 @@
     \hook_if_exist:nT {#1}
       {
         \prop_if_empty:cTF {g_@@_#1_code_prop}
-          { \tl_gset:co {g_@@_#1_code_tl}
+          { \tl_gset:co {@@~#1}
                         {\cs:w g_@@_#1_code_next_tl \cs_end: } }
           {
 %    \end{macrocode}
@@ -2704,7 +2703,7 @@
 %    \begin{macrocode}
             \prop_set_eq:Nc \l_@@_work_prop { g_@@_#1_code_prop }
             \@@_initialize_single:cccn
-              { g_@@_#1_code_tl } { g_@@_#1_code_next_tl }
+              { @@~#1 } { g_@@_#1_code_next_tl }
               { g_@@_#1_labels_clist } {#1}
 %    \end{macrocode}
 %    For debug display we want to keep track of those hooks that
@@ -2796,13 +2795,13 @@
 %    \end{macrocode}
 %    Step T1: Initialize the data structure \ldots
 %    \begin{macrocode}
-  \seq_clear:N \l_@@_labels_seq
-  \int_zero:N  \l_@@_labels_int
+    \seq_clear:N \l_@@_labels_seq
+    \int_zero:N  \l_@@_labels_int
 %    \end{macrocode}
 %
 %    Store the name of the hook:
 %    \begin{macrocode}
-  \tl_set:Nn \l_@@_cur_hook_tl {#4}
+    \tl_set:Nn \l_@@_cur_hook_tl {#4}
 %    \end{macrocode}
 %    
 %    We loop over the property list holding the code and record all
@@ -2812,13 +2811,13 @@
 %    to ensure that labels named |front|, |rear|, |labels|, or |return|
 %    don't interact with our code.
 %    \begin{macrocode}
-  \prop_map_inline:Nn \l_@@_work_prop
-     {
-       \int_incr:N \l_@@_labels_int
-       \seq_put_right:Nn \l_@@_labels_seq {##1}
-       \tl_set:cn { \@@_tl_csname:n {##1} }{0}
-       \seq_clear_new:c { \@@_seq_csname:n {##1} }
-     }
+    \prop_map_inline:Nn \l_@@_work_prop
+       {
+         \int_incr:N \l_@@_labels_int
+         \seq_put_right:Nn \l_@@_labels_seq {##1}
+         \tl_set:cn { \@@_tl_csname:n {##1} }{0}
+         \seq_clear_new:c { \@@_seq_csname:n {##1} }
+       }
 %    \end{macrocode}
 %    Steps T2 and T3: Sort the relevant rules into the data structure\ldots
 %    
@@ -2834,30 +2833,30 @@
 %    \cs{@@_apply_label_pair:nnn}, which takes the properly-ordered pair
 %    of labels as argument.
 %    \begin{macrocode}
-  \prop_map_inline:Nn \l_@@_work_prop
-    {
-      \prop_map_inline:Nn \l_@@_work_prop
-        {
-          \@@_if_label_case:nnnnn {##1} {####1}
-            { \prop_map_break: }
-            { \@@_apply_label_pair:nnn {##1} {####1} }
-            { \@@_apply_label_pair:nnn {####1} {##1} }
-                {#4}
-        }
-    }
+    \prop_map_inline:Nn \l_@@_work_prop
+      {
+        \prop_map_inline:Nn \l_@@_work_prop
+          {
+            \@@_if_label_case:nnnnn {##1} {####1}
+              { \prop_map_break: }
+              { \@@_apply_label_pair:nnn {##1} {####1} }
+              { \@@_apply_label_pair:nnn {####1} {##1} }
+                  {#4}
+          }
+      }
 %    \end{macrocode}
 %    Take a breath and take a look at the data structures that have
 %    been set up:
 %    \begin{macrocode}
-  \@@_debug:n { \@@_debug_label_data:N \l_@@_work_prop }
+    \@@_debug:n { \@@_debug_label_data:N \l_@@_work_prop }
 %    \end{macrocode}
 %    
 %
 %    Step T4:
 %    \begin{macrocode}
-  \tl_set:Nn \l_@@_rear_tl { 0 }
-  \tl_set:cn { \@@_tl_csname:n { 0 } } { 0 }
-  \seq_map_inline:Nn \l_@@_labels_seq
+    \tl_set:Nn \l_@@_rear_tl { 0 }
+    \tl_set:cn { \@@_tl_csname:n { 0 } } { 0 }
+    \seq_map_inline:Nn \l_@@_labels_seq
       {
         \int_compare:nNnT { \cs:w \@@_tl_csname:n {##1} \cs_end: } = 0
             {
@@ -2865,61 +2864,61 @@
               \tl_set:Nn \l_@@_rear_tl {##1}
             }
       }
-  \tl_set_eq:Nc \l_@@_front_tl { \@@_tl_csname:n { 0 } }
+    \tl_set_eq:Nc \l_@@_front_tl { \@@_tl_csname:n { 0 } }
 %    \end{macrocode}
 %    
 %    \begin{macrocode}
-  \tl_gclear:N #1
-  \clist_gclear:N #3
+    \tl_gclear:N #1
+    \clist_gclear:N #3
 %    \end{macrocode}
 %
 %    The whole loop combines steps T5--T7:
 %    \begin{macrocode}
-  \bool_while_do:nn { ! \str_if_eq_p:Vn \l_@@_front_tl { 0 } }
-       {
+    \bool_while_do:nn { ! \str_if_eq_p:Vn \l_@@_front_tl { 0 } }
+      {
 %    \end{macrocode}
 %    This part is step T5:
 %    \begin{macrocode}
-         \int_decr:N \l_@@_labels_int
-         \prop_get:NVN \l_@@_work_prop \l_@@_front_tl \l_@@_return_tl
-         \@@_tl_gput:NV #1 \l_@@_return_tl
+        \int_decr:N \l_@@_labels_int
+        \prop_get:NVN \l_@@_work_prop \l_@@_front_tl \l_@@_return_tl
+        \@@_tl_gput:NV #1 \l_@@_return_tl
 %    \end{macrocode}
 %    
 %    \begin{macrocode}
-         \@@_clist_gput:NV #3 \l_@@_front_tl
-         \@@_debug:n{ \iow_term:x{Handled~ code~ for~ \l_@@_front_tl} }
+        \@@_clist_gput:NV #3 \l_@@_front_tl
+        \@@_debug:n{ \iow_term:x{Handled~ code~ for~ \l_@@_front_tl} }
 %    \end{macrocode}
 %
 %    This is step T6 except that we don't use a pointer $P$ to move
 %    through the successors, but instead use \verb=##1= of the mapping
 %    function.
 %    \begin{macrocode}
-         \seq_map_inline:cn { \@@_seq_csname:n { \l_@@_front_tl } }
-             {
-               \tl_set:cx { \@@_tl_csname:n {##1} }
-                          { \int_eval:n
-                              { \cs:w \@@_tl_csname:n {##1} \cs_end: - 1 }
-                          }
-               \int_compare:nNnT
-                   { \cs:w \@@_tl_csname:n {##1} \cs_end: } = 0
-                   {
-                     \tl_set:cn { \@@_tl_csname:n { \l_@@_rear_tl } } {##1}
-                     \tl_set:Nn \l_@@_rear_tl            {##1}
-                   }
-             }
+        \seq_map_inline:cn { \@@_seq_csname:n { \l_@@_front_tl } }
+          {
+            \tl_set:cx { \@@_tl_csname:n {##1} }
+                       { \int_eval:n
+                           { \cs:w \@@_tl_csname:n {##1} \cs_end: - 1 }
+                       }
+            \int_compare:nNnT
+                { \cs:w \@@_tl_csname:n {##1} \cs_end: } = 0
+                {
+                  \tl_set:cn { \@@_tl_csname:n { \l_@@_rear_tl } } {##1}
+                  \tl_set:Nn \l_@@_rear_tl            {##1}
+                }
+          }
 %    \end{macrocode}
 %    and step T7:
 %    \begin{macrocode}
-          \tl_set_eq:Nc \l_@@_front_tl
-                        { \@@_tl_csname:n { \l_@@_front_tl } }
+        \tl_set_eq:Nc \l_@@_front_tl
+                      { \@@_tl_csname:n { \l_@@_front_tl } }
 %    \end{macrocode}
 %
 %    This is step T8: If we haven't moved the code for all labels
 %    (i.e., if \cs{l_@@_labels_int} is still greater than zero) we
 %    have a loop and our partial order can't be flattened out.
 %    \begin{macrocode}
-       }
-  \int_compare:nNnF \l_@@_labels_int = 0
+      }
+    \int_compare:nNnF \l_@@_labels_int = 0
       {
         \iow_term:x{====================}
         \iow_term:x{Error:~ label~ rules~ are~ incompatible:}
@@ -3365,7 +3364,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_gput_next_do:Nnn #1 #2
   {
-    \tl_if_empty:cT { g_@@_#2_code_tl }
+    \tl_if_empty:cT { @@~#2 }
       { \@@_update_hook_code:n {#2} }
     \tl_if_empty:NT #1
       { \tl_gset:Nn #1 { \tl_gclear:c { g_@@_#2_code_next_tl } } }
@@ -3407,20 +3406,20 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \hook_use:n #1
   {
-    \tl_if_exist:cTF { g_@@_#1_code_tl }
+    \tl_if_exist:cTF { @@~#1 }
       {
         \@@_preamble_hook:n {#1}
-        \cs:w g_@@_#1_code_tl \cs_end:
+        \cs:w @@~#1 \cs_end:
       }
       { \@@_use:wn #1 / \s_@@_mark {#1} }
   }
 \cs_new:Npn \@@_use_initialized:n #1
   {
-    \if_cs_exist:w g_@@_#1_code_tl \cs_end:
+    \if_cs_exist:w @@~#1 \cs_end:
     \else:
       \@@_use_undefined:w
     \fi:
-    \cs:w g_@@_ \use:n {#1} _code_tl \cs_end:
+    \cs:w @@~ \use:n {#1}  \cs_end:
   }
 \cs_new:Npn \@@_use_undefined:w #1 #2 \use:n #3 #4 \cs_end:
   {
@@ -3466,10 +3465,10 @@
   }
 \cs_new_protected:Npn \@@_if_exist_use:n #1
   {
-    \tl_if_exist:cT { g_@@_#1_code_tl }
+    \tl_if_exist:cT { @@~#1 }
       {
         \@@_preamble_hook:n {#1}
-        \cs:w g_@@_#1_code_tl \cs_end:
+        \cs:w @@~#1 \cs_end:
       }
   }
 %    \end{macrocode}
@@ -3491,7 +3490,7 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \hook_use_once:n #1
   {
-    \tl_if_exist:cT { g_@@_#1_code_tl }
+    \tl_if_exist:cT { @@~#1 }
       {
         \tl_set:Nn \l_@@_return_tl {#1}
         \@@_normalize_hook_args:Nn \@@_use_once_store:n
@@ -3550,7 +3549,7 @@
 % \begin{macro}[pTF]{\hook_if_exist:n}
 %   A canonical way to test if a hook exists.  A hook exists if the
 %   token list that stores the sorted code for that hook,
-%   \cs[no-index]{g_@@_\meta{hook}_code_tl}, exists.  The property list
+%   \cs[no-index]{@@~\meta{hook}}, exists.  The property list
 %   \cs[no-index]{g_@@_\meta{hook}_code_prop} cannot be used here
 %   because often it is necessary to add code to a hook without knowing
 %   if such hook was already declared, or even if it will ever be
@@ -3558,7 +3557,7 @@
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \hook_if_exist:n #1 { p , T , F , TF }
   {
-    \tl_if_exist:cTF { g_@@_#1_code_tl }
+    \tl_if_exist:cTF { @@~#1 }
       { \prg_return_true: }
       { \prg_return_false: }
   }





More information about the latex3-commits mailing list.