[latex3-commits] [git/LaTeX3-latex3-latex2e] apdf161: Drop space-trimming in \hook_use(_once):n (97474cae)
PhelypeOleinik
phelype.oleinik at latex-project.org
Wed Sep 9 12:03:54 CEST 2020
Repository : https://github.com/latex3/latex2e
On branch : apdf161
Link : https://github.com/latex3/latex2e/commit/97474cae96f56f06f48cb4d26530188f649546f1
>---------------------------------------------------------------
commit 97474cae96f56f06f48cb4d26530188f649546f1
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date: Wed Sep 9 07:03:54 2020 -0300
Drop space-trimming in \hook_use(_once):n
>---------------------------------------------------------------
97474cae96f56f06f48cb4d26530188f649546f1
base/lthooks.dtx | 24 ++++++++++++++----------
base/testfiles-lthooks/lthooks-027.lvt | 8 ++++----
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 302bfdef..b62ad42f 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -3383,7 +3383,7 @@
%
% \begin{macro}{\hook_use:n}
% \begin{macro}[EXP]{\@@_use_initialized:n}
-% \begin{macro}{\@@_use:n,\@@_preamble_use:n,\@@_use_undefined:nw}
+% \begin{macro}{\@@_use_undefined:nw}
% \begin{macro}{\@@_preamble_hook:n}
% \cs{hook_use:n} as defined here is used in the preamble, where
% hooks aren't initialized by default. \cs{@@_use_initialized:n} is
@@ -3410,8 +3410,6 @@
% careful to avoid this.
% \begin{macrocode}
\cs_new_protected:Npn \hook_use:n #1
- { \tl_trim_spaces_apply:nN {#1} \@@_preamble_use:n }
-\cs_new_protected:Npn \@@_preamble_use:n #1
{
\tl_if_exist:cTF { g_@@_#1_code_tl }
{
@@ -3421,8 +3419,6 @@
{ \@@_use:wn #1 / \s_@@_mark {#1} }
}
\cs_new:Npn \@@_use_initialized:n #1
- { \tl_trim_spaces_apply:nN {#1} \@@_use:n }
-\cs_new:Npn \@@_use:n #1
{
\if_cs_exist:w g_@@_#1_code_tl \cs_end:
\cs:w g_@@_#1_code_tl \exp_after:wN \cs_end:
@@ -3484,23 +3480,31 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\hook_use_once:n,\@@_use_once:n}
+% \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.
+%
+% 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.
+%
+% \pho{Should this raise an error if the hook doesn't exist?}
% \begin{macrocode}
\cs_new_protected:Npn \hook_use_once:n #1
- { \@@_normalize_hook_args:Nn \@@_use_once:n {#1} }
-\cs_new_protected:Npn \@@_use_once:n #1
{
\tl_if_exist:cT { g_@@_#1_code_tl }
{
- \prop_gput:Nnn \g_@@_execute_immediately_prop {#1} { }
- \@@_use:n {#1}
+ \tl_set:Nn \l_@@_return_tl {#1}
+ \@@_normalize_hook_args:Nn \@@_use_once_store:n
+ { \l_@@_return_tl }
+ \hook_use:n {#1}
}
}
+\cs_new_protected:Npn \@@_use_once_store:n #1
+ { \prop_gput:Nnn \g_@@_execute_immediately_prop {#1} { } }
% \end{macrocode}
% \end{macro}
%
diff --git a/base/testfiles-lthooks/lthooks-027.lvt b/base/testfiles-lthooks/lthooks-027.lvt
index 2e2122cb..5824e2fc 100644
--- a/base/testfiles-lthooks/lthooks-027.lvt
+++ b/base/testfiles-lthooks/lthooks-027.lvt
@@ -28,7 +28,7 @@
\NewHook { -{hook}- }
\AddToHook { -{hook}- } {\message{aaa}}
\DeclareHookRule { A } { . } { after } { x }
- \UseOneTimeHook { -{hook}- }
+ \UseOneTimeHook {-{hook}-}
\AddToHook { -{hook}- } [ x ] {\message{bbb}}
\ShowHook { -{hook}- }
}
@@ -44,7 +44,7 @@
\NewHook { grüße }
\AddToHook { grüße } {\message{aaa}}
\DeclareHookRule { A } { . } { after } { x }
- \UseOneTimeHook { grüße }
+ \UseOneTimeHook {grüße}
\AddToHook { grüße } [ x ] {\message{bbb}}
\ShowHook { grüße }
}
@@ -56,7 +56,7 @@
\NewHook { \hookname }
\AddToHook { \hookname } {\message{aaa}}
\DeclareHookRule { A } { . } { after } { x }
- \UseOneTimeHook { \hookname }
+ \UseOneTimeHook {\hookname}
\AddToHook { \hookname } [ x ] {\message{bbb}}
\ShowHook { \hookname }
}
@@ -68,7 +68,7 @@
\NewHook { \hookname }
\AddToHook { \hookname } {\message{aaa}}
\DeclareHookRule { A } { . } { after } { x }
- \UseOneTimeHook { \hookname }
+ \UseOneTimeHook {\hookname}
\AddToHook { \hookname } [ x ] {\message{bbb}}
\ShowHook { \hookname }
}
More information about the latex3-commits
mailing list.