[latex3-commits] [git/LaTeX3-latex3-latex2e] hook-args: Define the parameter token list for all hooks (bbe83a89)
PhelypeOleinik
phelype.oleinik at latex-project.org
Sat Mar 11 03:06:36 CET 2023
Repository : https://github.com/latex3/latex2e
On branch : hook-args
Link : https://github.com/latex3/latex2e/commit/bbe83a89534b188224a91316159a915760d945ba
>---------------------------------------------------------------
commit bbe83a89534b188224a91316159a915760d945ba
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date: Wed Mar 8 00:03:06 2023 -0300
Define the parameter token list for all hooks
not just for hooks that take arguments. This makes the state of things
a lot more predictable and the logic simpler.
>---------------------------------------------------------------
bbe83a89534b188224a91316159a915760d945ba
base/lthooks.dtx | 53 ++++++++++++++++++----------------
base/testfiles-lthooks/lthooks-033.lvt | 8 ++++-
base/testfiles-lthooks/lthooks-033.tlg | 38 +++++++-----------------
3 files changed, 45 insertions(+), 54 deletions(-)
diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index cf09b98a..28a6b0c5 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -2239,7 +2239,7 @@
% so that it can be identified. The |-| character is used because
% $\meta{reversed}1$ is $+1$ for normal hooks and $-1$ for reversed
% ones.
-
+%
% \item[{\cs[no-index]{g_@@_\meta{hook}_declared_tl}}] This token
% list serves as marker for the hook being officially declared. Its
% existence is tested to raise an error in case another declaration
@@ -2458,18 +2458,15 @@
% This token list stores the parameter text of the hook code
% (a simple run of parameters):
% \begin{macrocode}
- \int_compare:nNnT {#2} > { 0 }
+ \__kernel_cs_parm_from_arg_count:nnF
+ { \tl_const:cn { c_@@_#1_parameter_tl } } {#2}
{
- \__kernel_cs_parm_from_arg_count:nnF
- { \tl_const:cn { c_@@_#1_parameter_tl } } {#2}
- {
- \msg_error:nnnn { hooks } { too-many-args } {#1} {#2}
- \tl_const:cx { c_@@_#1_parameter_tl }
- { \exp_not:V \c_@@_nine_parameters_tl }
- }
- \@@_normalise_cs_args:nn { _toplevel } {#1}
- \@@_normalise_cs_args:nn { _next } {#1}
+ \msg_error:nnnn { hooks } { too-many-args } {#1} {#2}
+ \tl_const:cx { c_@@_#1_parameter_tl }
+ { \exp_not:V \c_@@_nine_parameters_tl }
}
+ \@@_normalise_cs_args:nn { _toplevel } {#1}
+ \@@_normalise_cs_args:nn { _next } {#1}
% \end{macrocode}
% This is only used by the actual code of the current hook, so
% declare it normally:
@@ -2572,13 +2569,14 @@
}
\cs_new_protected:Npn \@@_cs_gput_right:nnn #1 #2 #3
{
- % \tl_if_exist:cTF { c_@@_#2_parameter_tl }
- % {
\@@_code_gset_auxi:veen
{
c_@@_
\tl_if_exist:cTF { c_@@_#2_parameter_tl }
- { #2_parameter } { nine_parameters }
+ { \use_i:nn }
+ { \@@_if_declared:nTF {#2} { \use_i:nn } { \use_ii:nn } }
+ { #2_parameter }
+ { nine_parameters }
_tl
}
{
@@ -2595,8 +2593,6 @@
{#3}
}
{ @@#1~#2 }
- % }
- % { \@@_tl_gput_right:cn { @@#1~#2 } {#3} }
}
\cs_new_protected:Npn \@@_normalise_cs_args:nn #1 #2
{
@@ -3330,21 +3326,22 @@
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new_protected:Npn \@@_gput_code:nnn #1 #2
+\cs_new_protected:Npn \@@_gput_code:nnn #1
{
\@@_if_replacing_args:TF
{
- \bool_lazy_and:nnT
- { \@@_if_usable_p:n {#1} }
- { ! \tl_if_exist_p:c { c_@@_#1_parameter_tl } }
+ \tl_if_exist:cTF { c_@@_#1_parameter_tl }
+ { \tl_if_empty:cT { c_@@_#1_parameter_tl } { \use_ii:nn } }
+ { \@@_if_declared:nT {#1} { \use_ii:nn } }
+ \use_none:n
{
\msg_error:nnnn { hooks } { without-args }
{#1} { AddToHook }
+ \@@_replacing_args_false:
}
- \@@_gput_code_normal:nnn
}
- { \@@_gput_code_normal:nnn }
- {#1} {#2}
+ { }
+ \@@_gput_code_normal:nnn {#1}
}
\cs_new_protected:Npn \@@_gput_code_normal:nnn #1 #2
{
@@ -5460,15 +5457,19 @@
%
% \begin{macrocode}
\cs_new_protected:Npn \@@_gput_next_do:nn #1
- { \@@_gput_next_choose:nn }
+ { \@@_gput_next_choose:nn {#1} }
\cs_new_protected:Npn \@@_gput_next_choose:nn #1
{
\@@_if_replacing_args:TF
{
- \tl_if_exist:cF { c_@@_#1_parameter_tl }
+ \tl_if_exist:cTF { c_@@_#1_parameter_tl }
+ { \tl_if_empty:cT { c_@@_#1_parameter_tl } { \use_ii:nn } }
+ { \@@_if_declared:nT {#1} { \use_ii:nn } }
+ \use_none:n
{
\msg_error:nnnn { hooks } { without-args }
{#1} { AddToHookNext }
+ \@@_replacing_args_false:
}
}
{ }
@@ -5734,6 +5735,8 @@
\cs_new:Npn \hook_use_once:nw { \hook_use_once:n }
\cs_new_protected:Npn \@@_use_once:n #1
{
+ \tl_if_exist:cF { c_@@_#1_parameter_tl }
+ { \tl_const:cn { c_@@_#1_parameter_tl } { } }
\@@_preamble_hook:n {#1}
\@@_use_once_set:n {#1}
% \end{macrocode}
diff --git a/base/testfiles-lthooks/lthooks-033.lvt b/base/testfiles-lthooks/lthooks-033.lvt
index 80d78e03..d475c088 100644
--- a/base/testfiles-lthooks/lthooks-033.lvt
+++ b/base/testfiles-lthooks/lthooks-033.lvt
@@ -99,8 +99,14 @@
\AddToHookWithArguments{test-10}{\typeout{10-top-level(#1,#2)}}
\AddToHookWithArguments{test-10}[label]{\typeout{10-label(#1,#2)}}
\AddToHookNextWithArguments{test-10}{\typeout{10-next(#1,#2)}}
- \UseHook{test-10}{foo}{bar}
+ \UseHook{test-10}{foo}{bar}%
+ {3}{4}{5}{6}{7}{8}{9}
+ }
+
+%
+\TEST{No arguments}
+ {
\NewHook{no-args}
\AddToHook{no-args}{\typeout{no-top-level(#1,#2)}} % ok, adds ##1, ##2
\AddToHook{no-args}[label]{\typeout{no-label(#1,#2)}} % ok, adds ##1, ##2
diff --git a/base/testfiles-lthooks/lthooks-033.tlg b/base/testfiles-lthooks/lthooks-033.tlg
index f938f0dd..5680902d 100644
--- a/base/testfiles-lthooks/lthooks-033.tlg
+++ b/base/testfiles-lthooks/lthooks-033.tlg
@@ -156,32 +156,14 @@ For immediate help type H <return>.
...
l. ... }
You tried to declare a hook with 10 arguments, but a hook can only have up to
-nine. LaTeX will define this hook without arguments.
-! LaTeX hooks Error: Hook 'test-10' has no arguments.
-For immediate help type H <return>.
- ...
-l. ... }
-You tried to use \AddToHookWithArguments on a hook that takes no arguments.
-Check the usage of the hook or use \AddToHook instead.
-LaTeX will use \AddToHook.
-! LaTeX hooks Error: Hook 'test-10' has no arguments.
-For immediate help type H <return>.
- ...
-l. ... }
-You tried to use \AddToHookWithArguments on a hook that takes no arguments.
-Check the usage of the hook or use \AddToHook instead.
-LaTeX will use \AddToHook.
-! LaTeX hooks Error: Hook 'test-10' has no arguments.
-For immediate help type H <return>.
- ...
-l. ... }
-You tried to use \AddToHookNextWithArguments on a hook that takes no
-arguments.
-Check the usage of the hook or use \AddToHookNext instead.
-LaTeX will use \AddToHookNext.
-10-label(##1,##2)
-10-top-level(##1,##2)
-10-next(##1,##2)
+nine. LaTeX will define this hook with nine arguments.
+10-label(foo,bar)
+10-top-level(foo,bar)
+10-next(foo,bar)
+============================================================
+============================================================
+TEST 5: No arguments
+============================================================
! LaTeX hooks Error: Hook 'no-args' has no arguments.
For immediate help type H <return>.
...
@@ -212,7 +194,7 @@ no-next(##1,##2)
no-next(##1,##2)
============================================================
============================================================
-TEST 5: One-time hook with arguments
+TEST 6: One-time hook with arguments
============================================================
once(foo,bar)
! LaTeX hooks Error: You can't have arguments in used one-time hook
@@ -227,7 +209,7 @@ LaTeX will use \AddToHook.
twice(##1,##2)
============================================================
============================================================
-TEST 6: Add with arguments before hook is declared
+TEST 7: Add with arguments before hook is declared
============================================================
args(foo,bar)
more-args(foo,bar)
More information about the latex3-commits
mailing list.