[latex3-commits] [git/LaTeX3-latex3-latex2e] lthooks-doc-updates: Don't complain about reversed/normal mismatch (c284e714)

PhelypeOleinik phelype.oleinik at latex-project.org
Fri Aug 6 06:25:43 CEST 2021


Repository : https://github.com/latex3/latex2e
On branch  : lthooks-doc-updates
Link       : https://github.com/latex3/latex2e/commit/c284e71472e1f3296d47e11453361eeed604c80e

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

commit c284e71472e1f3296d47e11453361eeed604c80e
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Fri Aug 6 01:25:43 2021 -0300

    Don't complain about reversed/normal mismatch
    
    Instead derive the hook ordering from the name of the generic hook


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

c284e71472e1f3296d47e11453361eeed604c80e
 base/lthooks.dtx                                   | 71 ++++++++++------------
 .../lthooks-029-deprecated-after.tlg               | 21 -------
 .../lthooks-029-deprecated-before.tlg              | 12 ----
 3 files changed, 33 insertions(+), 71 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 7fd8a7a4..b5a5954f 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -2591,27 +2591,45 @@
     \@@_if_disabled:nTF {#1}
       { \msg_warning:nnn { hooks } { activate-disabled } {#1} }
 %    \end{macrocode}
-%    Otherwise we check if it was already declared.
+%    Otherwise we check if the hook is not declared, and if it isn't,
+%    figure out if it's reversed or not, then declare it accordingly.
 %    \begin{macrocode}
       {
-        \@@_if_declared:nTF {#1}
+        \@@_if_declared:nF {#1}
           {
-%    \end{macrocode}
-%    Issue an error if we try to activate a hook that is reversed and
-%    the already existing one is not (or vice versa).
-% \fmiinline{should be possible to simplify here}            
-%    \begin{macrocode}
-            \str_if_eq:eeF { \tl_use:c { g_@@_#1_reversed_tl } } {#2}
-              { \msg_error:nnn { hooks } { activate-error } {#1} }
+            \tl_new:c { g_@@_#1_declared_tl }
+            \@@_make_usable:n {#1}
+            \@@_set_hook_ordering:n {#1}
           }
+      }
+  }
 %    \end{macrocode}
-%    If it wasn't declared, we declared as a normal or reversed hook
-%    as appropriate.
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_set_hook_ordering:n}
+% \begin{macro}{\@@_set_hook_ordering:wn}
+%   Sets the \cs[no-index]{g_@@_\meta{hook}_reversed_tl} token list for
+%   known generic hooks, by looking at the \meta{hook} name and matching
+%   with the known patterns.
 %    \begin{macrocode}
+\cs_new_protected:Npn \@@_set_hook_ordering:n #1
+  {
+    \tl_gset:cx { g_@@_#1_reversed_tl }
+      { \@@_set_hook_ordering:wn #1 / / / \scan_stop: }
+  }
+\cs_new:Npn \@@_set_hook_ordering:wn #1 / #2 / #3 / #4 \scan_stop:
+  {
+    \tl_if_empty:nF {#2}
+      {
+        \prop_if_in:NnT \c_@@_generics_prop {#1}
           {
-            \tl_new:c { g_@@_#1_declared_tl }
-            \@@_make_usable:n {#1}
-            \tl_gset:cn { g_@@_#1_reversed_tl } {#2}
+            \prop_if_in:NnTF \c_@@_generics_reversed_ii_prop {#2}
+              { - }
+              {
+                \prop_if_in:NnT \c_@@_generics_reversed_iii_prop {#3}
+                  { - }
+              }
           }
       }
   }
@@ -2619,7 +2637,6 @@
 % \end{macro}
 % \end{macro}
 %
-%
 %    \begin{macrocode}
 %<latexrelease>\EndIncludeInRelease
 %    \end{macrocode}
@@ -4769,26 +4786,6 @@
   }
 %    \end{macrocode}
 %
-% \fmiinline{that should be simplified now}
-%    \begin{macrocode}
-\msg_new:nnnn { hooks } { activate-error }
-  {
-    Hook~'#1'~ already~ declared~ as~ a~
-    \@@_if_reversed:nTF {#1} { reversed } { normal }~ hook!
-  }
-  {
-    You~ attempted~ to~ activate~ 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}
-%
-%
-%
-%
-%
 %
 %  \subsection{\LaTeXe{} package interface commands}
 %
@@ -5134,9 +5131,7 @@
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  \subsection{Deprecated that needs cleanup \ldots}
-%
-% \fmiinline{these should give a deprecation warning now}
+% \subsection{Deprecated that needs cleanup \ldots}
 %
 % \begin{macro}{%
 %     \hook_disable:n,
diff --git a/base/testfiles-lthooks/lthooks-029-deprecated-after.tlg b/base/testfiles-lthooks/lthooks-029-deprecated-after.tlg
index 7c282417..76c54317 100644
--- a/base/testfiles-lthooks/lthooks-029-deprecated-after.tlg
+++ b/base/testfiles-lthooks/lthooks-029-deprecated-after.tlg
@@ -72,25 +72,11 @@ l. ...\ShowHook{bbb}
 <recently read> }
 l. ...\ShowHook{ccc}
 ------------ provide an known reversed hook --------------
-! LaTeX hooks Error: Hook 'ccc' already declared as a reversed hook!
-For immediate help type H <return>.
- ...                                              
-l. ...\ActivateGenericHook{ccc}
-                               % \ProvideReversedHook
-You attempted to activate 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':
 > The hook is empty.
 <recently read> }
 l. ...\ShowHook{ccc}
 ------------ provide an known reversed hook with data --------------
-! LaTeX hooks Error: Hook 'ccc' already declared as a reversed hook!
-For immediate help type H <return>.
- ...                                              
-l. ...\ActivateGenericHook{ccc}
-                               % \ProvideReversedHook
-You attempted to activate 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:
 >     Z -> Z1
@@ -119,13 +105,6 @@ l. ...\ShowHook{ccc}
 <recently read> }
 l. ...\ShowHook{aaa}
 ------------ provide an normal hook on an existing reversed hook --------------
-! LaTeX hooks Error: Hook 'ccc' already declared as a reversed hook!
-For immediate help type H <return>.
- ...                                              
-l. ...\ActivateGenericHook{ccc}
-                               % \ProvideHook
-You attempted to activate 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:
 >     Z -> Z1
diff --git a/base/testfiles-lthooks/lthooks-029-deprecated-before.tlg b/base/testfiles-lthooks/lthooks-029-deprecated-before.tlg
index 3a8e3ce8..659553e6 100644
--- a/base/testfiles-lthooks/lthooks-029-deprecated-before.tlg
+++ b/base/testfiles-lthooks/lthooks-029-deprecated-before.tlg
@@ -119,12 +119,6 @@ LaTeX hooks Warning: Command \ProvideReversedHook is deprecated and will be
 (hooks)              removed in a future release.
 (hooks)              
 (hooks)              Use \ActivateGenericHook instead.
-! LaTeX hooks Error: Hook 'aaa' already declared as a normal hook!
-For immediate help type H <return>.
- ...                                              
-l. ...\ProvideReversedHook{aaa}
-You attempted to activate 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:
 >     X -> X1
@@ -143,12 +137,6 @@ LaTeX hooks Warning: Command \ProvideHook is deprecated and will be removed in
 (hooks)              a future release.
 (hooks)              
 (hooks)              Use \ActivateGenericHook instead.
-! LaTeX hooks Error: Hook 'ccc' already declared as a reversed hook!
-For immediate help type H <return>.
- ...                                              
-l. ...\ProvideHook{ccc}
-You attempted to activate 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:
 >     Z -> Z1





More information about the latex3-commits mailing list.