From 551e9f790c0206306aeb4e8415e8255f34fff590 Mon Sep 17 00:00:00 2001 From: PhelypeOleinik Date: Thu, 29 Apr 2021 23:20:13 -0300 Subject: [PATCH] Merge code for \hook_provide:n and \hook_provide_reversed:n --- base/lthooks.dtx | 89 +++++++++----------------- base/testfiles-lthooks/lthooks-029.tlg | 10 +-- 2 files changed, 37 insertions(+), 62 deletions(-) diff --git a/base/lthooks.dtx b/base/lthooks.dtx index f79494c15..e9aedd5af 100644 --- a/base/lthooks.dtx +++ b/base/lthooks.dtx @@ -2462,7 +2462,9 @@ % \end{macro} % \end{macro} % -% \begin{macro}{\hook_provide:n,\@@_provide:n} +% \begin{macro}{\hook_provide:n} +% \begin{macro}{\hook_provide_reversed:n} +% \begin{macro}{\@@_provide:n} % The \cs{hook_provide:n} declaration declares a new hook and expects % the hook \meta{name} as its argument, e.g., % \hook{begindocument}. @@ -2473,70 +2475,41 @@ % % \begin{macrocode} \cs_new_protected:Npn \hook_provide:n #1 - { \@@_normalize_hook_args:Nn \@@_provide:n {#1} } + { \@@_normalize_hook_args:Nn \@@_provide:nn {#1} { } } +\cs_new_protected:Npn \hook_provide_reversed:n #1 + { \@@_normalize_hook_args:Nn \@@_provide:nn {#1} { - } } % \end{macrocode} % % \begin{macrocode} -\cs_new_protected:Npn \@@_provide:n #1 +\cs_new_protected:Npn \@@_provide:nn #1 #2 { -% \end{macrocode} -% We check if the hook was already \emph{explicitly} declared with -% \cs{hook_new:n}, and if it already exists we complain, otherwise set -% the \enquote{created} flag for the hook so that it errors next time -% \cs{hook_new:n} is used. -% \begin{macrocode} \@@_if_disabled:nTF {#1} - { \__kernel_msg_warning:nnn { hooks } { provide-disabled } {#1} } - { \@@_if_declared:nTF {#1} - { - \@@_if_reversed:nT {#1} - { \__kernel_msg_error:nnnnn { hooks } { provide-error } - {#1} {normal} {reversed} } - } - { - \tl_new:c { g_@@_#1_declared_tl } - \@@_make_usable:n {#1} - } - } + { \__kernel_msg_warning:nnn { hooks } { provide-disabled } {#1} } + { + \@@_if_declared:nTF {#1} + { + \str_if_eq:eeF { \tl_use:c { g_@@_#1_reversed_tl } } {#2} + { \__kernel_msg_error:nnn { hooks } { provide-error } {#1} } + } + { + \tl_new:c { g_@@_#1_declared_tl } + \@@_make_usable:n {#1} + \tl_gset:cn { g_@@_#1_reversed_tl } {#2} + } + } } % \end{macrocode} % \end{macro} +% \end{macro} +% \end{macro} % -% -% -% \begin{macro}{\hook_provide_reversed:n,\@@_provide_reversed:n} -% -% Declare a new hook. The default ordering of code chunks is -% reversed, signaled by setting the token list to a minus sign. -% \begin{macrocode} -\cs_new_protected:Npn \hook_provide_reversed:n #1 - { \@@_normalize_hook_args:Nn \@@_provide_reversed:n {#1} } -\cs_new_protected:Npn \@@_provide_reversed:n #1 - { - \@@_if_disabled:nTF {#1} - { \__kernel_msg_warning:nnn { hooks } { provide-disabled } {#1} } - { \@@_if_declared:nTF {#1} - { - \@@_if_reversed:nF {#1} - { \__kernel_msg_error:nnnnn { hooks } { provide-error } - {#1} {reversed} {normal} } - } - { - \@@_provide:n {#1} - \tl_gset:cn { g_@@_#1_reversed_tl } { - } - } - } - } -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{\hook_provide_pair:nn} +% \begin{macro}{\hook_provide_pair:nn} % A shorthand for providing a normal and a (matching) reversed hook in one go. % \begin{macrocode} \cs_new_protected:Npn \hook_provide_pair:nn #1#2 { \hook_provide:n {#1} \hook_provide_reversed:n {#2} } % \end{macrocode} +% \end{macro} % % \begin{macrocode} %\EndIncludeInRelease @@ -2552,7 +2525,6 @@ % %\EndIncludeInRelease % \end{macrocode} -% \end{macro} % % % \subsection{Parsing a label} @@ -4678,19 +4650,22 @@ % \begin{macrocode} \__kernel_msg_new:nnn { hooks } { provide-disabled } { - Can't~ provide~ hook~ #1~ as~ it~ was~ disabled! + Can't~ provide~ hook~ #1~ because~ it~ is~ disabled! } % \end{macrocode} % % \begin{macrocode} \__kernel_msg_new:nnnn { hooks } { provide-error } { - Hook~ #1~ already~ declared~ as~ a~ #3~ hook! + Hook~ #1~ already~ declared~ as~ a~ + \@@_if_reversed:nTF {#1} { reversed } { normal }~ hook! } { - You~ attempted~ to~ provide~ the~ hook~ #1~ as~ #2~ hook,~ but~ it~ - was~ already~ previously~ declared~ as~ a~ #3~ hook.~ - A~ redeclaration~ is~ not~ possible. + You~ attempted~ to~ provide~ the~ hook~ #1~ as~ a~ + \@@_if_reversed:nTF {#1} { normal } { reversed }~ hook,~ but~ it~ + was~ already~ previously~ declared~ as~ a~ + \@@_if_reversed:nTF {#1} { reversed } { normal }~ hook.~ + A~ redeclaration~ is~ not~ possible. } % \end{macrocode} % diff --git a/base/testfiles-lthooks/lthooks-029.tlg b/base/testfiles-lthooks/lthooks-029.tlg index ee894436a..f02d4b4ad 100644 --- a/base/testfiles-lthooks/lthooks-029.tlg +++ b/base/testfiles-lthooks/lthooks-029.tlg @@ -91,11 +91,11 @@ l. ...\ShowHook{ccc} } l. ...\ShowHook{ccc} ------------ provide an reversed hook on an existing normal hook -------------- -! LaTeX3 Error: Hook aaa already declared as a normal hook! +! LaTeX3 Error: Hook `aaa' already declared as a normal hook! For immediate help type H . ... l. ...\ProvideReversedHook{aaa} -You attempted to provide the hook aaa as reversed hook, but it was already +You attempted to provide the hook `aaa' as a reversed hook, but it was already previously declared as a normal hook. A redeclaration is not possible. -> The hook 'aaa': > Code chunks: @@ -111,11 +111,11 @@ previously declared as a normal hook. A redeclaration is not possible. } l. ...\ShowHook{aaa} ------------ provide an normal hook on an existing reversed hook -------------- -! LaTeX3 Error: Hook ccc already declared as a reversed hook! +! LaTeX3 Error: Hook `ccc' already declared as a reversed hook! For immediate help type H . ... l. ...\ProvideHook{ccc} -You attempted to provide the hook ccc as normal hook, but it was already +You attempted to provide the hook `ccc' as a normal hook, but it was already previously declared as a reversed hook. A redeclaration is not possible. -> The hook 'ccc': > Code chunks: @@ -131,7 +131,7 @@ previously declared as a reversed hook. A redeclaration is not possible. } l. ...\ShowHook{ccc} ------------ provide hook that was disabled -------------- -LaTeX3 Warning: Can't provide hook ddd as it was disabled! +LaTeX3 Warning: Can't provide hook `ddd' because it is disabled! -> The hook 'ddd': > The hook is not declared. > The hook is disabled.