[latex3-commits] [git/LaTeX3-latex3-latex2e] gh606: Clean up hook after \UseOneTimeHook (1392d8a6)
PhelypeOleinik
phelype.oleinik at latex-project.org
Fri Sep 3 07:46:56 CEST 2021
Repository : https://github.com/latex3/latex2e
On branch : gh606
Link : https://github.com/latex3/latex2e/commit/1392d8a66ad2a802b04dc09cac08dbd2c18ece2d
>---------------------------------------------------------------
commit 1392d8a66ad2a802b04dc09cac08dbd2c18ece2d
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date: Fri Sep 3 02:46:56 2021 -0300
Clean up hook after \UseOneTimeHook
Fixes #606
>---------------------------------------------------------------
1392d8a66ad2a802b04dc09cac08dbd2c18ece2d
base/lthooks.dtx | 85 +++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 62 insertions(+), 23 deletions(-)
diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 11483c3d..42e80793 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -2071,13 +2071,6 @@
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\g_@@_execute_immediately_prop}
-% List of hooks that from no on should not longer receive code.
-% \begin{macrocode}
-\prop_new:N \g_@@_execute_immediately_prop
-% \end{macrocode}
-% \end{macro}
-%
% \begin{macro}{\g_@@_used_prop}
% All hooks that receive code (for use in debugging display).
% \begin{macrocode}
@@ -2118,6 +2111,13 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\@@_clean_to_scan:w}
+% Removes tokens until the next \cs{s_@@_mark}.
+% \begin{macrocode}
+\cs_new:Npn \@@_clean_to_scan:w #1 \s_@@_mark { }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\@@_tl_set:Nn,\@@_tl_set:Nx,
% \@@_tl_set:cn,\@@_tl_set:cx}
% Private copies of a few \pkg{expl3} functions. \pkg{l3debug} will
@@ -2976,7 +2976,7 @@
% \end{macrocode}
% First check if the hook was used as a one-time hook:
% \begin{macrocode}
- \prop_if_in:NnTF \g_@@_execute_immediately_prop {#1}
+ \@@_if_execute_immediately:nTF {#1}
{#3}
{
% \end{macrocode}
@@ -4800,28 +4800,66 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\hook_use_once:n}
-% For hooks that can and should be used only once we have a special
-% use command that remembers the hook name in
-% \cs{g_@@_execute_immediately_prop}. This has the effect that any
-% further code added to the hook is executed immediately rather
-% than stored in the hook.
+% \begin{macro}{\hook_use_once:n}
+% For hooks that can and should be used only once we have a special
+% use command that further inhibits the hook from getting more code
+% added to it. This has the effect that any
+% further code added to the hook is executed immediately rather
+% than stored in the hook.
%
-% The code needs some gymnastics to prevent space trimming from the
-% hook name, since \cs{hook_use:n} and \cs{hook_use_once:n} are
-% documented to not trim spaces.
+% The code needs some gymnastics to prevent space trimming from the
+% hook name, since \cs{hook_use:n} and \cs{hook_use_once:n} are
+% documented to not trim spaces.
%
% \begin{macrocode}
\cs_new_protected:Npn \hook_use_once:n #1
{
- \tl_if_exist:cT { @@~#1 }
+ \@@_if_execute_immediately:nF {#1}
{
- \@@_normalize_hook_args:Nn \@@_use_once_store:n { \use:n {#1} }
\hook_use:n {#1}
+ \@@_normalize_hook_args:Nn \@@_use_once_store:n { \use:n {#1} }
}
}
+% \end{macrocode}
+%
+% \begin{macro}{\@@_use_once_store:n}
+% \cs{@@_use_once_store:n} is used after the actual hook code is
+% executed so that we can clear it. Setting
+% \cs[no-index]{g_@@_\meta{hook}_reversed_tl} to |I| prevents further
+% code from being added to the hook.
+% \begin{macrocode}
\cs_new_protected:Npn \@@_use_once_store:n #1
- { \prop_gput:Nnn \g_@@_execute_immediately_prop {#1} { } }
+ {
+ \@@_tl_gclear:c { @@~#1 }
+ \@@_tl_gclear:c { @@_next~#1 }
+ \@@_tl_gclear:c { @@_toplevel~#1 }
+ \prop_gclear:c { g_@@_#1_code_prop }
+ \@@_tl_gset:cn { g_@@_#1_reversed_tl } { I }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[pTF]{\@@_if_execute_immediately:n}
+% To check if code being added should be executed immediately (that
+% is, if the hook is a one-time hook), we check if it's usable (it
+% can't be one-time if it was not already usable), then we check that
+% \cs[no-index]{g_@@_\meta{hook}_reversed_tl} is |I|. The gymnastics
+% around \cs{if:w} is there to allow the |reversed| token list to be
+% empty.
+% \begin{macrocode}
+\prg_new_conditional:Npnn \@@_if_execute_immediately:n #1 { F, TF }
+ {
+ \@@_if_usable:nTF {#1}
+ {
+ \exp_after:wN \@@_clean_to_scan:w
+ \if:w I \cs:w g_@@_#1_reversed_tl \cs_end:
+ \s_@@_mark \prg_return_true:
+ \else:
+ \s_@@_mark \prg_return_false:
+ \fi:
+ }
+ { \prg_return_false: }
+ }
% \end{macrocode}
% \end{macro}
%
@@ -4930,10 +4968,11 @@
% \begin{macrocode}
\prg_new_conditional:Npnn \@@_if_reversed:n #1 { p , T , F , TF }
{
- \if_int_compare:w \cs:w g_@@_#1_reversed_tl \cs_end: 1 < 0 \exp_stop_f:
- \prg_return_true:
+ \exp_after:wN \@@_clean_to_scan:w
+ \if:w - \cs:w g_@@_#1_reversed_tl \cs_end:
+ \s_@@_mark \prg_return_true:
\else:
- \prg_return_false:
+ \s_@@_mark \prg_return_false:
\fi:
}
% \end{macrocode}
More information about the latex3-commits
mailing list.