[latex3-commits] [git/LaTeX3-latex3-latex2e] apdf161: Use a prop to store one-time hooks (abe80a6a)

PhelypeOleinik phelype.oleinik at latex-project.org
Mon Sep 7 20:50:55 CEST 2020


Repository : https://github.com/latex3/latex2e
On branch  : apdf161
Link       : https://github.com/latex3/latex2e/commit/abe80a6aeb3a25970639b225748b42a6d1ad7fbe

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

commit abe80a6aeb3a25970639b225748b42a6d1ad7fbe
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Mon Sep 7 15:50:55 2020 -0300

    Use a prop to store one-time hooks


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

abe80a6aeb3a25970639b225748b42a6d1ad7fbe
 base/lthooks.dtx                       | 42 +++++++++++++++++-----------------
 base/testfiles-lthooks/lthooks-027.lvt | 23 +++++++++++++++++++
 base/testfiles-lthooks/lthooks-027.tlg | 30 ++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 21 deletions(-)

diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 6587a6dd..e1a2962f 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -1592,6 +1592,20 @@
 %    \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}
+\prop_new:N \g_@@_used_prop
+%    \end{macrocode}
+%  \end{macro}
+%
 % \begin{macro}{\g_@@_hook_curr_name_tl,\g_@@_name_stack_seq}
 %   Default label used for hook commands, and a stack to keep track of
 %   packages within packages.
@@ -1928,7 +1942,7 @@
 %    \end{macrocode}
 %    First check if the hook was used as a one-time hook:
 %    \begin{macrocode}
-    \clist_if_in:NnTF \g_@@_execute_immediately_clist {#1}
+    \prop_if_in:NnTF \g_@@_execute_immediately_prop {#1}
       {#3}
       {
 %    \end{macrocode}
@@ -2263,6 +2277,10 @@
 %   \cs{tl_gremove_once:Nx} is fairly efficient even for longer token
 %   lists, so we use a single global token list, rather than one for
 %   each hook.
+%
+%   A hand-crafted token list is used here because property lists don't
+%   hold repeated items, so multiple usages of \cs{@@_mark_removal:nn}
+%   would be cancelled by a single \cs{@@_unmark_removal:nn}.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_mark_removal:nn #1 #2
   {
@@ -2646,15 +2664,6 @@
 %  \end{macro}
 %
 %
-%  \begin{macro}{\g_@@_used_prop}
-%    All hooks that receive code (for use in debugging display).
-%    \begin{macrocode}
-\prop_new:N\g_@@_used_prop
-%    \end{macrocode}
-%  \end{macro}
-%
-%
-%
 % \begin{macro}[EXP]{\@@_tl_csname:n,\@@_seq_csname:n}
 %   It is faster to pass a single token and expand it when necessary
 %   than to pass a bunch of character tokens around.
@@ -2666,8 +2675,6 @@
 % \end{macro}
 %
 %
-%
-%
 %  \begin{macro}{\l_@@_labels_seq,\l_@@_labels_int,\l_@@_front_tl,
 %      \l_@@_rear_tl,\l_@@_label_0_tl}
 %
@@ -3417,7 +3424,7 @@
 %  \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_clist}. This has the effect that any
+%    \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{macrocode}
@@ -3425,7 +3432,7 @@
   {
     \tl_if_exist:cT { g_@@_#1_code_tl }
       {
-        \clist_gput_left:Nn \g_@@_execute_immediately_clist {#1}
+        \prop_gput:Nnn \g_@@_execute_immediately_prop {#1} { }
         \hook_use:n {#1}
       }
   }
@@ -3523,13 +3530,6 @@
 % \end{macro}
 %
 %
-%  \begin{macro}{\g_@@_execute_immediately_clist}
-%    List of hooks that from no on should not longer receive code.
-%    \begin{macrocode}
-\clist_new:N \g_@@_execute_immediately_clist
-%    \end{macrocode}
-%  \end{macro}
-%
 %  \subsection{Messages}
 %
 %    \begin{macrocode}
diff --git a/base/testfiles-lthooks/lthooks-027.lvt b/base/testfiles-lthooks/lthooks-027.lvt
index f89e12ce..2c0f1668 100644
--- a/base/testfiles-lthooks/lthooks-027.lvt
+++ b/base/testfiles-lthooks/lthooks-027.lvt
@@ -1,5 +1,12 @@
 \documentclass{article}
 \usepackage{expl3}
+
+\def\foo#1{bar}  % dummy which does something with its argument to 
+                 % generate part of the file name
+\begin{filecontents}[force]{my-\foo{english}.xxx}
+  \typeout{File: my-\foo{english}.xxx}
+\end{filecontents}
+
 \input{regression-test}
 \begin{document}
 \START
@@ -11,7 +18,23 @@
     \hook_gput_code:nnn { A } { . } { \message{aaa} }
     \hook_use_once:n { A }
     \hook_gput_code:nnn { A } { . } { \message{bbb} }
+    \hook_log:n { A }
   }
 \ExplSyntaxOff
 
+\TEST { Braces in hook names (expect 'aaa bbb'): }
+  {
+    \NewHook { -{hook}- }
+    \AddToHook { -{hook}- } {\message{aaa}}
+    \UseOneTimeHook { -{hook}- }
+    \AddToHook { -{hook}- } {\message{bbb}}
+    \ShowHook { -{hook}- }
+  }
+
+\TEST { Macro with argument (expect 'my-bar.xxx' and 'after'): }
+  {
+    \AddToHook{file/after/my-\foo{english}.xxx}{\typeout{File: after}}
+    \input{my-\foo{english}.xxx}
+  }
+
 \end{document}
diff --git a/base/testfiles-lthooks/lthooks-027.tlg b/base/testfiles-lthooks/lthooks-027.tlg
index 21792ddb..e7b6a7d6 100644
--- a/base/testfiles-lthooks/lthooks-027.tlg
+++ b/base/testfiles-lthooks/lthooks-027.tlg
@@ -4,5 +4,35 @@ Don't change this file in any respect.
 TEST 1: Using stuff once (expect 'aaa bbb'):
 ============================================================
 aaa bbb
+The hook 'A':
+ Code chunks:
+    . -> \message {aaa}
+ Extra code next invocation:
+    ---
+ Rules:
+    ---
+ Execution order:
+    .
+============================================================
+============================================================
+TEST 2:  Braces in hook names (expect 'aaa bbb'): 
+============================================================
+The hook '-{hook}-':
+ Code chunks:
+    top-level -> \message {aaa}\message {bbb}
+ Extra code next invocation:
+    ---
+ Rules:
+    ---
+ Execution order:
+    top-level
+============================================================
+============================================================
+TEST 3:  Macro with argument (expect 'my-bar.xxx' and 'after'): 
+============================================================
+(my-bar.xxx
+File: my-bar.xxx
+)
+File: after
 ============================================================
 (lthooks-027.aux)





More information about the latex3-commits mailing list.