[latex3-commits] [git/LaTeX3-latex3-latex2e] lthooks2: Avoid clash when '<hook>' and '<hook>_next' are defined (f97e4ab9)

PhelypeOleinik tex.phelype at gmail.com
Sun Aug 23 16:10:34 CEST 2020


Repository : https://github.com/latex3/latex2e
On branch  : lthooks2
Link       : https://github.com/latex3/latex2e/commit/f97e4ab9b0bb9667c8e3ed38a52cb62e9b88b3d2

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

commit f97e4ab9b0bb9667c8e3ed38a52cb62e9b88b3d2
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Sun Aug 23 11:10:34 2020 -0300

    Avoid clash when '<hook>' and '<hook>_next' are defined


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

f97e4ab9b0bb9667c8e3ed38a52cb62e9b88b3d2
 base/lthooks.dtx                       | 28 ++++++++++++++------------
 base/testfiles-lthooks/lthooks-011.lvt | 11 +++++++++++
 base/testfiles-lthooks/lthooks-011.tlg | 36 ++++++++++++++++++++++------------
 3 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 873a5713..949859cd 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -1623,7 +1623,7 @@
 %
 % \subsection{Providing new hooks}
 %
-% \begin{macro}{\g_@@_..._code_prop,\g_@@_..._code_tl,\g_@@_..._next_code_tl}
+% \begin{macro}{\g_@@_..._code_prop,\g_@@_..._code_tl,\g_@@_..._code_next_tl}
 %
 %    Hooks have a \meta{name} and for each hook we have to provide a number of
 %    data structures. These are
@@ -1650,10 +1650,14 @@
 %    $\meta{reversed}1$ is $+1$ for normal hooks and $-1$ for reversed
 %    ones.
 %
-%    \item[\cs{g_@@_\meta{name}_next_code_tl}] Finally there is extra code
+%    \item[\cs{g_@@_\meta{name}_code_next_tl}] Finally there is extra code
 %    (normally empty) that is used on the next invocation of the hook
 %    (and then deleted). This can be used to define some special
-%    behavior for a single occasion from within the document.
+%    behavior for a single occasion from within the document.  This token
+%    list is called |code_next| rather than |next_code| because otherwise
+%    a hook called \meta{name}|_next| would have its code-token list
+%    named \cs[no-index]{g_@@_\meta{name}_code_next_tl}, which would
+%    clash with the next code-token list of a hook called \meta{name}.
 %
 %    \end{description}
 %  \end{macro}
@@ -1737,7 +1741,7 @@
     \@@_if_exist:nF {#1}
       {
         \prop_new:c { g_@@_#1_code_prop }
-        \tl_new:c { g_@@_#1_next_code_tl }
+        \tl_new:c { g_@@_#1_code_next_tl }
       }
   }
 %    \end{macrocode}
@@ -2591,7 +2595,7 @@
     {
       \prop_if_empty:cTF {g_@@_#1_code_prop}
         { \tl_gset:co {g_@@_#1_code_tl}
-                      {\cs:w g_@@_#1_next_code_tl \cs_end: } }
+                      {\cs:w g_@@_#1_code_next_tl \cs_end: } }
         {
 %    \end{macrocode}
 %    By default the algorithm sorts the code chunks and then saves the
@@ -2615,7 +2619,7 @@
 %    \begin{macrocode}
           \prop_set_eq:Nc \l_@@_work_prop { g_@@_#1_code_prop }
           \@@_initialize_single:cccn
-            { g_@@_#1_code_tl } { g_@@_#1_next_code_tl }
+            { g_@@_#1_code_tl } { g_@@_#1_code_next_tl }
             { g_@@_#1_labels_clist } {#1}
 %    \end{macrocode}
 %    For debug display we want to keep track of those hooks that
@@ -3130,14 +3134,14 @@
 %    \begin{macrocode}
         \iow_term:x{~Extra~ code~ next~ invocation:}
         \iow_term:x{\@spaces
-          \tl_if_empty:cTF { g_@@_#1_next_code_tl }
+          \tl_if_empty:cTF { g_@@_#1_code_next_tl }
              {---}
 %    \end{macrocode}
 %    If the token list is not empty we want to display it but without
 %    the first tokens (the code to clear itself) so we call a helper
 %    command to  get rid of them.
 %    \begin{macrocode}
-             {->~  \exp_args:Nv \@@_log_next_code:n {g_@@_#1_next_code_tl} } }
+             {->~  \exp_args:Nv \@@_log_next_code:n {g_@@_#1_code_next_tl} } }
 %    \end{macrocode}
 %
 %   Loop through the rules in a hook and for every rule found, print it.
@@ -3282,7 +3286,7 @@
 \cs_new_protected:Npn \@@_gput_next_do:nn #1
   {
     \exp_args:Nc \@@_gput_next_do:Nnn
-      { g_@@_#1_next_code_tl } {#1}
+      { g_@@_#1_code_next_tl } {#1}
   }
 %    \end{macrocode}
 %   First check if the ``next code'' token list is empty:  if so we need
@@ -3300,7 +3304,7 @@
     \tl_if_empty:cT { g_@@_#2_code_tl }
       { \@@_update_hook_code:n {#2} }
     \tl_if_empty:NT #1
-      { \tl_gset:Nn #1 { \tl_gclear:c { g_@@_#2_next_code_tl } } }
+      { \tl_gset:Nn #1 { \tl_gclear:c { g_@@_#2_code_next_tl } } }
     \tl_gput_right:Nn #1
   }
 %    \end{macrocode}
@@ -3443,7 +3447,7 @@
 %   Test if a hook is empty (that is, no code was added to that hook).
 %   A hook being empty means that \emph{both} its
 %   \cs[no-index]{g_@@_\meta{hook}_code_prop} and its
-%   \cs[no-index]{g_@@_\meta{hook}_next_code_tl} are empty.
+%   \cs[no-index]{g_@@_\meta{hook}_code_next_tl} are empty.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \hook_if_empty:n #1 { p , T , F , TF }
   {
@@ -3451,7 +3455,7 @@
       {
         \bool_lazy_and:nnTF
             { \prop_if_empty_p:c { g_@@_#1_code_prop } }
-            { \tl_if_empty_p:c { g_@@_#1_next_code_tl } }
+            { \tl_if_empty_p:c { g_@@_#1_code_next_tl } }
           { \prg_return_true: }
           { \prg_return_false: }
       }
diff --git a/base/testfiles-lthooks/lthooks-011.lvt b/base/testfiles-lthooks/lthooks-011.lvt
index 9477dcc7..97147195 100644
--- a/base/testfiles-lthooks/lthooks-011.lvt
+++ b/base/testfiles-lthooks/lthooks-011.lvt
@@ -13,7 +13,18 @@
 
 \ExplSyntaxOn
 
+% Ensure that unfortunately-named hooks don't wreck our code
+% in previous versions this would clash with the code_next_tl
+% of the hook above (the token list was named next_code_tl).
+
+% This would raise a 'hook already defined' error
 \hook_new:n{xxx}
+\hook_new:n{xxx_next}
+
+% This would raise a lower-level 'cs already defined' error
+\hook_new:n{yyy_next}
+\hook_new:n{yyy}
+
 
 % Ensure that unfortunately-named labels don't wreck our code
 
diff --git a/base/testfiles-lthooks/lthooks-011.tlg b/base/testfiles-lthooks/lthooks-011.tlg
index 22b07caa..ed8ccb8d 100644
--- a/base/testfiles-lthooks/lthooks-011.tlg
+++ b/base/testfiles-lthooks/lthooks-011.tlg
@@ -42,10 +42,13 @@ Code labels for sorting:
 Data structure for label rules:
  front = 0 -> 
 Handled code for front
+Update code for hook 'xxx_next' on input line ...:
+Update code for hook 'yyy_next' on input line ...:
+Update code for hook 'yyy' on input line ...:
 All initialized (non-empty) hooks:
- enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_next_code_tl  
- shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_next_code_tl  
- xxx -> foo\g__hook_xxx_next_code_tl  
+ enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_code_next_tl  
+ shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_code_next_tl  
+ xxx -> foo\g__hook_xxx_code_next_tl  
 **** Add to hook xxx (rear) on input line ... <- bar
 Update code for hook 'begindocument' on input line ...:
 Update code for hook 'begindocument/before' on input line ...:
@@ -90,10 +93,13 @@ Data structure for label rules:
  rear = 0 -> 
 Handled code for front
 Handled code for rear
+Update code for hook 'xxx_next' on input line ...:
+Update code for hook 'yyy_next' on input line ...:
+Update code for hook 'yyy' on input line ...:
 All initialized (non-empty) hooks:
- enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_next_code_tl  
- shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_next_code_tl  
- xxx -> foobar\g__hook_xxx_next_code_tl  
+ enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_code_next_tl  
+ shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_code_next_tl  
+ xxx -> foobar\g__hook_xxx_code_next_tl  
 **** Add to hook xxx (labels) on input line ... <- baz
 Update code for hook 'begindocument' on input line ...:
 Update code for hook 'begindocument/before' on input line ...:
@@ -140,10 +146,13 @@ Data structure for label rules:
 Handled code for front
 Handled code for rear
 Handled code for labels
+Update code for hook 'xxx_next' on input line ...:
+Update code for hook 'yyy_next' on input line ...:
+Update code for hook 'yyy' on input line ...:
 All initialized (non-empty) hooks:
- enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_next_code_tl  
- shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_next_code_tl  
- xxx -> foobarbaz\g__hook_xxx_next_code_tl  
+ enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_code_next_tl  
+ shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_code_next_tl  
+ xxx -> foobarbaz\g__hook_xxx_code_next_tl  
 **** Add to hook xxx (return) on input line ... <- boom
 Update code for hook 'begindocument' on input line ...:
 Update code for hook 'begindocument/before' on input line ...:
@@ -192,7 +201,10 @@ Handled code for front
 Handled code for rear
 Handled code for labels
 Handled code for return
+Update code for hook 'xxx_next' on input line ...:
+Update code for hook 'yyy_next' on input line ...:
+Update code for hook 'yyy' on input line ...:
 All initialized (non-empty) hooks:
- enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_next_code_tl  
- shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_next_code_tl  
- xxx -> foobarbazboom\g__hook_xxx_next_code_tl  
+ enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \g__hook_enddocument/info_code_next_tl  
+ shipout/firstpage -> \bool_lazy_and:nnT {\cs_if_exist_p:N \g__kernel_backend_header_bool }{\g__kernel_backend_header_bool }{\__kernel_backend_literal:n {header=l3backend-dvips.pro}}\g__hook_shipout/firstpage_code_next_tl  
+ xxx -> foobarbazboom\g__hook_xxx_code_next_tl  





More information about the latex3-commits mailing list.