[latex3-commits] [git/LaTeX3-latex3-latex2e] hotfix/gh441: Set the order of the chunk only after the hook is declared (33d4132b)

PhelypeOleinik phelype.oleinik at latex-project.org
Fri Dec 11 03:48:31 CET 2020


Repository : https://github.com/latex3/latex2e
On branch  : hotfix/gh441
Link       : https://github.com/latex3/latex2e/commit/33d4132be8fcc46145f14bec37bf42e683090205

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

commit 33d4132be8fcc46145f14bec37bf42e683090205
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Thu Dec 10 23:48:31 2020 -0300

    Set the order of the chunk only after the hook is declared


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

33d4132be8fcc46145f14bec37bf42e683090205
 base/lthooks.dtx                       | 40 ++++++++++++++++++++++++++++++----
 base/testfiles-lthooks/lthooks-013.tlg |  8 +++----
 2 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index abb8b190..4bcc3e13 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -1886,6 +1886,17 @@
 %
 %    \begin{macrocode}
         \@@_include_legacy_code_chunk:n {#1}
+%    \end{macrocode}
+%    Then finally, if the |top-level| chunk is not empty (that is, code
+%    was added before the hook was declared), remove the braces around
+%    the code chunks that were added for reversing (see definition of
+%    \cs{@@_hook_gput_code_do:nnn}).
+%    \begin{macrocode}
+        \tl_if_empty:cF { @@_toplevel~#1 }
+          {
+            \tl_set:cx { @@_toplevel~#1 }
+              { \tl_map_function:cN { @@_toplevel~#1 } \exp_not:n }
+          }
      }
   }
 %    \end{macrocode}
@@ -1923,6 +1934,12 @@
   { \@@_normalize_hook_args:Nn \@@_new_reversed:n {#1} }
 \cs_new_protected:Npn \@@_new_reversed:n #1
   {
+%    \end{macrocode}
+%    If there was already code in the |top-level| chunk, then reverse it
+%    (see definition of \cs{@@_hook_gput_code_do:nnn}).
+%    \begin{macrocode}
+    \tl_if_empty:cF { @@_toplevel~#1 }
+      { \tl_reverse:c { @@_toplevel~#1 } }
     \@@_new:n {#1}
 %    \end{macrocode}
 %    If the hook already exists the above will generate an error
@@ -2228,10 +2245,25 @@
     \str_if_eq:nnTF {#2} { top-level }
       {
         \debug_suspend:
-        \@@_if_reversed:nTF {#1}
-          { \tl_gput_left:cn }
-          { \tl_gput_right:cn }
-              { @@_toplevel~#1 } {#3}
+%    \end{macrocode}
+%    If the hook exists, its order (if it's reversed or not) is already
+%    set, so we can just use the correct
+%    \cs[no-index]{\tl_gput_\meta{side}:cn}.  Otherwise, add the code
+%    chunk with an extra pair of braces so it can be easily revesed
+%    later if needed.
+%    \begin{macrocode}
+        \hook_if_exist:nTF {#1}
+          {
+            \@@_if_reversed:nTF {#1}
+              { \tl_gput_left:cn }
+              { \tl_gput_right:cn }
+                  { @@_toplevel~#1 } {#3}
+          }
+          {
+            \@@_declare:n {#1}
+            \tl_gput_right:cn
+              { @@_toplevel~#1 } { {#3} }
+          }
         \debug_resume:
       }
       {
diff --git a/base/testfiles-lthooks/lthooks-013.tlg b/base/testfiles-lthooks/lthooks-013.tlg
index 03e9a9bc..5e48f7e5 100644
--- a/base/testfiles-lthooks/lthooks-013.tlg
+++ b/base/testfiles-lthooks/lthooks-013.tlg
@@ -126,10 +126,10 @@ Update code for hook 'file/bar' on input line ...:
 All initialized (non-empty) hooks:
  enddocument/info -> \@dofilelist \@enddocument at kernel@warnings \__hook_toplevel enddocument/info \__hook_next enddocument/info  
  shipout/firstpage -> \__kernel_backend_literal:n {header=l3backend-dvips.pro}\__hook_toplevel shipout/firstpage \__hook_next shipout/firstpage  
- file/after/biditools.sty -> \FirstAidNeededT {biditools}{sty}{....-..-.. v... Programming tools for bidi package}{ \def \firstaid at bidi@document at patch \endgroup ##1\begingroup ##2\firstaid at bidi@document at patch {\unexpanded {##1##2}}\edef \document {\expandafter \firstaid at bidi@document at patch \document \firstaid at bidi@document at patch }\AddToHook {enddocument/info}{\let \bidi at AfterEndDocumentCheckLabelsRerun \@firstofone \bidi at afterenddocumentchecklabelsrerunhook }} \__hook_toplevel file/after/biditools.sty \__hook_next file/after/biditools.sty  
- file/after/dinbrief.cls -> \FirstAidNeededT {dinbrief}{cls}{....-..-.. LaTeX2e class}{\AddToHook {env/document/begin}{\begingroup }}\__hook_toplevel file/after/dinbrief.cls \__hook_next file/after/dinbrief.cls  
- file/after/pgfpages.sty -> \cs_gset_eq:NN \shipout \pgfpages at originalshipout \cs_set_eq:NN \pgfpages at originalshipout \tex_shipout:D \cs_set_eq:NN \tex_shipout:D \pgfpages at interceptshipout \__hook_toplevel file/after/pgfpages.sty \__hook_next file/after/pgfpages.sty  
- file/after/pgfmorepages.sty -> \cs_gset_eq:NN \shipout \pgfpages at originalshipout \cs_set_eq:NN \pgfpages at originalshipout \tex_shipout:D \cs_set_eq:NN \tex_shipout:D \pgfpages at interceptshipout \__hook_toplevel file/after/pgfmorepages.sty \__hook_next file/after/pgfmorepages.sty  
+ file/after/biditools.sty -> \__hook_toplevel file/after/biditools.sty \FirstAidNeededT {biditools}{sty}{....-..-.. v... Programming tools for bidi package}{ \def \firstaid at bidi@document at patch \endgroup ##1\begingroup ##2\firstaid at bidi@document at patch {\unexpanded {##1##2}}\edef \document {\expandafter \firstaid at bidi@document at patch \document \firstaid at bidi@document at patch }\AddToHook {enddocument/info}{\let \bidi at AfterEndDocumentCheckLabelsRerun \@firstofone \bidi at afterenddocumentchecklabelsrerunhook }} \__hook_next file/after/biditools.sty  
+ file/after/dinbrief.cls -> \__hook_toplevel file/after/dinbrief.cls \FirstAidNeededT {dinbrief}{cls}{....-..-.. LaTeX2e class}{\AddToHook {env/document/begin}{\begingroup }}\__hook_next file/after/dinbrief.cls  
+ file/after/pgfpages.sty -> \__hook_toplevel file/after/pgfpages.sty \cs_gset_eq:NN \shipout \pgfpages at originalshipout \cs_set_eq:NN \pgfpages at originalshipout \tex_shipout:D \cs_set_eq:NN \tex_shipout:D \pgfpages at interceptshipout \__hook_next file/after/pgfpages.sty  
+ file/after/pgfmorepages.sty -> \__hook_toplevel file/after/pgfmorepages.sty \cs_gset_eq:NN \shipout \pgfpages at originalshipout \cs_set_eq:NN \pgfpages at originalshipout \tex_shipout:D \cs_set_eq:NN \tex_shipout:D \pgfpages at interceptshipout \__hook_next file/after/pgfmorepages.sty  
  env/itemize/begin -> \typeout {env itemize first}\__hook_toplevel env/itemize/begin \__hook_next env/itemize/begin  
 No file lthooks-013.aux.
 LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line ....





More information about the latex3-commits mailing list.