Skip to content

Commit

Permalink
Mass-replace <type>/<position>/<name> by <type>/<name>/<position>
Browse files Browse the repository at this point in the history
  • Loading branch information
PhelypeOleinik committed Aug 16, 2021
1 parent 022028f commit 7d81a91
Show file tree
Hide file tree
Showing 36 changed files with 580 additions and 579 deletions.
2 changes: 1 addition & 1 deletion base/doc/ltnews34.tex
Expand Up @@ -168,7 +168,7 @@ \subsection{Class, package, and include hook improvements}
files have been made one-time hooks. Beside being more efficient this
supports the following important use case
\begin{verbatim}
\AddToHook{package/after/varioref}
\AddToHook{package/varioref/after}
{ ... apply my customizations if the package
gets loaded (or was loaded already) ... }
\end{verbatim}
Expand Down
16 changes: 8 additions & 8 deletions base/ltclass.dtx
Expand Up @@ -2361,17 +2361,17 @@
% package otherwise, if it is \cs{@clsextension}, a class, so
% depending on that we execute different hooks. If the extension is
% neither, then it is another type of file without special hooks.
% \changes{v1.4e}{2021/07/23}{Make class/before/name a one-time hook}
% \changes{v1.4e}{2021/07/23}{Make package/before/name a one-time hook}
% \changes{v1.4e}{2021/07/23}{Make class/name/before a one-time hook}
% \changes{v1.4e}{2021/07/23}{Make package/name/before a one-time hook}
% \begin{macrocode}
%-----------------------------------------
\ifx\@currext\@pkgextension
\UseHook{package/before}%
\UseOneTimeHook{package/before/\@currname}%
\UseOneTimeHook{package/\@currname/before}%
\else
\ifx\@currext\@clsextension
\UseHook{class/before}%
\UseOneTimeHook{class/before/\@currname}%
\UseOneTimeHook{class/\@currname/before}%
\fi
\fi
% \end{macrocode}
Expand Down Expand Up @@ -2430,16 +2430,16 @@
% \end{macrocode}
% And same procedure, James, when we are finished loading, except
% that the hook order is now reversed.
% \changes{v1.4e}{2021/07/23}{Make class/after/name a one-time hook}
% \changes{v1.4e}{2021/07/23}{Make package/after/name a one-time hook}
% \changes{v1.4e}{2021/07/23}{Make class/name/after a one-time hook}
% \changes{v1.4e}{2021/07/23}{Make package/name/after a one-time hook}
% \begin{macrocode}
%-----------------------------------------
\ifx\@currext\@pkgextension
\UseOneTimeHook{package/after/\@currname}%
\UseOneTimeHook{package/\@currname/after}%
\UseHook{package/after}%
\else
\ifx\@currext\@clsextension
\UseOneTimeHook{class/after/\@currname}%
\UseOneTimeHook{class/\@currname/after}%
\UseHook{class/after}%
\fi
\fi}%
Expand Down
56 changes: 28 additions & 28 deletions base/ltfilehook.dtx
Expand Up @@ -115,20 +115,20 @@
% \cs{usepackage}, etc. They are not called for files read using
% internal low-level methods, such as \cs{@input} or \cs{openin}.
%
% \begin{variable}{file/before,file/before/...,
% file/after/...,file/after,
% \begin{variable}{file/before,file/.../before,
% file/.../after,file/after,
% }
% These are:
% \begin{description}
% \item[\texttt{file/before}, \texttt{file/before/\meta{file-name}}]
% \item[\texttt{file/before}, \texttt{file/\meta{file-name}/before}]
%
% These hooks are executed in that order just before the file is
% loaded for reading. The code of the first hook is used
% with every file, while the second is executed only for the
% file with matching \meta{file-name} allowing you to specify
% code that only applies to one file.
%
% \item[\texttt{file/after/\meta{file-name}}, \texttt{file/after}]
% \item[\texttt{file/\meta{file-name}/after}, \texttt{file/after}]
%
% These hooks are after the file with name \meta{file-name} has
% been fully consumed. The order is swapped (the specific one
Expand All @@ -149,9 +149,9 @@
% \begin{tabbing}
% mm\=mm\=mm\=mm\=\kill
% \>\cs{UseHook}\marg{\hook{file/before}} \\
% \>\cs{UseHook}\marg{\hook{file/before/\meta{file name}}} \\
% \>\cs{UseHook}\marg{\hook{file/\meta{file name}/before}} \\
% \>\> \meta{file contents} \\
% \>\cs{UseHook}\marg{\hook{file/after/\meta{file name}}} \\
% \>\cs{UseHook}\marg{\hook{file/\meta{file name}/after}} \\
% \>\cs{UseHook}\marg{\hook{file/after}}
% \end{tabbing}
%
Expand All @@ -172,8 +172,8 @@
%
% When a file is input, the \meta{file name} is available in
% \cs{CurrentFile}, which is then used when accessing the
% \hook{file/before/\meta{file name}} and
% \hook{file/after/\meta{file name}}.
% \hook{file/\meta{file name}/before} and
% \hook{file/\meta{file name}/after}.
%
% \begin{variable}{\CurrentFile}
% The name of the file about to be read (or just finished) is
Expand Down Expand Up @@ -216,26 +216,26 @@
% \cs{RequirePackage}, \cs{LoadPackageWithOptions}, etc.) offer the
% hooks from section~\ref{sec:general-file-hooks} when they are
% used to load a package or class file, e.g.,
% \texttt{file/after/array.sty} would be called after the
% \texttt{file/array.sty/after} would be called after the
% \pkg{array} package got loaded. But as packages and classes form as special group
% of files, there are some additional hooks available that only
% apply when a package or class is loaded.
%
%
% \begin{variable}{
% package/before,package/after,
% package/before/...,package/after/...,
% package/.../before,package/.../after,
% class/before,class/after,
% class/before/...,class/after/...,
% class/.../before,class/.../after,
% }
% These are:
% \begin{description}
% \item[\texttt{package/before}, \texttt{package/after}]
%
% These hooks are called for each package being loaded.
%
% \item[\texttt{package/before/\meta{name}},
% \texttt{package/after/\meta{name}}]
% \item[\texttt{package/\meta{name}/before},
% \texttt{package/\meta{name}/after}]
%
% These hooks are additionally called if the package name is
% \meta{name} (without extension).
Expand All @@ -244,7 +244,7 @@
%
% These hooks are called for each class being loaded.
%
% \item[\texttt{class/before/\meta{name}}, \texttt{class/after/\meta{name}}]
% \item[\texttt{class/\meta{name}/before}, \texttt{class/\meta{name}/after}]
%
% These hooks are additionally called if the class name is
% \meta{name} (without extension).
Expand All @@ -258,15 +258,15 @@
% \begin{tabbing}
% mm\=mm\=mm\=mm\=\kill
% \>\cs{UseHook}\marg{\hook{package/before}} \\
% \>\cs{UseHook}\marg{\hook{package/before/\meta{package name}}} \\[5pt]
% \>\cs{UseHook}\marg{\hook{package/\meta{package name}/before}} \\[5pt]
% \>\>\cs{UseHook}\marg{\hook{file/before}} \\
% \>\>\cs{UseHook}\marg{\hook{file/before/\meta{package name}.sty}} \\
% \>\>\cs{UseHook}\marg{\hook{file/\meta{package name}.sty/before}} \\
% \>\>\> \meta{package contents} \\
% \>\>\cs{UseHook}\marg{\hook{file/after/\meta{package name}.sty}} \\
% \>\>\cs{UseHook}\marg{\hook{file/\meta{package name}.sty/after}} \\
% \>\>\cs{UseHook}\marg{\hook{file/after}} \\[5pt]
% \>\>\emph{code from \cs{AtEndOfPackage} if
% used inside the package} \\[5pt]
% \>\cs{UseHook}\marg{\hook{package/after/\meta{package name}}} \\
% \>\cs{UseHook}\marg{\hook{package/\meta{package name}/after}} \\
% \>\cs{UseHook}\marg{\hook{package/after}}
% \end{tabbing}
% and similar for class file loading, except that \texttt{package/}
Expand All @@ -281,7 +281,7 @@
% one-time hooks, the other as normal hooks. This allows for the
% following use case
%\begin{verbatim}
% \AddToHook{package/after/varioref}
% \AddToHook{package/varioref/after}
% { ... apply my customizations if the package gets
% loaded (or was loaded already) ... }
%\end{verbatim}
Expand Down Expand Up @@ -315,14 +315,14 @@
% is \enquote{\texttt{No file \meta{filename}.tex}}).
%
%
% \begin{variable}{include/before,include/before/...,
% include/end,include/end/...,
% include/after,include/after/...,
% \begin{variable}{include/before,include/.../before,
% include/end,include/.../end,
% include/after,include/.../after,
% }
% These are:
% \begin{description}
%
% \item[\texttt{include/before}, \texttt{include/before/\meta{name}}]
% \item[\texttt{include/before}, \texttt{include/\meta{name}/before}]
%
% These hooks are executed (in that order) after the initial
% \cs{clearpage} and after \texttt{.aux} file is changed to use
Expand All @@ -332,14 +332,14 @@
% file.
%
%
% \item[\texttt{include/end/\meta{name}}, \texttt{include/end}]
% \item[\texttt{include/\meta{name}/end}, \texttt{include/end}]
%
% These hooks are executed (in that order) after \LaTeX{} has
% stopped reading from the \cs{include} file, but before it has
% issued a \cs{clearpage} to output any deferred floats.
%
%
% \item[\texttt{include/after/\meta{name}}, \texttt{include/after}]
% \item[\texttt{include/\meta{name}/after}, \texttt{include/after}]
%
% These hooks are executed (in that order) after \LaTeX{} has
% issued the \cs{clearpage} but before is has switched back
Expand Down Expand Up @@ -782,7 +782,7 @@
% can't rely on that still being true after the file has been
% processed. Thus for using the name in the file hooks we need to
% preserve the name and then restore it for the
% \texttt{file/after/...} hook.
% \texttt{file/.../after} hook.
%
% The hook always refers to the file requested by the user. The hook
% is \emph{always} loaded for \cs{CurrentFile} which usually is the
Expand Down Expand Up @@ -836,14 +836,14 @@
% The current file name is available in \cs{CurrentFile} so we use
% that in the specific hook.
% \begin{macrocode}
\UseHook{file/before/\CurrentFile}%
\UseHook{file/\CurrentFile/before}%
\@@input #1% <- trailing space comes from \@filef@und
}%
% \end{macrocode}
% And here, \cs{CurrentFile} is restored
% (by \cs{@expl@@@filehook@file@pop@assign@@nnnn}) so we can use it once more.
% \begin{macrocode}
\UseHook{file/after/\CurrentFile}%
\UseHook{file/\CurrentFile/after}%
\UseHook{file/after}}
\def\unqu@tefilef@und"#1" \@nil{#1}
%<latexrelease>\EndIncludeInRelease
Expand Down
12 changes: 6 additions & 6 deletions base/ltfiles.dtx
Expand Up @@ -850,18 +850,18 @@
% \end{macrocode}
% Execute the \texttt{before} hooks just after we switched the
% \texttt{.aux} file \ldots
% \changes{v1.2n}{2021/07/23}{Make include/before/name a one-time hook}
% \changes{v1.2n}{2021/07/23}{Make include/name/before a one-time hook}
% \begin{macrocode}
\UseHook{include/before}%
\UseOneTimeHook{include/before/#1}%
\UseOneTimeHook{include/#1/before}%
%-----------------------------------------
\@input@{#1.tex}%
%-----------------------------------------
% \end{macrocode}
% \ldots{} then \texttt{end} hooks \ldots
% \changes{v1.2n}{2021/07/23}{Make include/end/name a one-time hook}
% \changes{v1.2n}{2021/07/23}{Make include/name/end a one-time hook}
% \begin{macrocode}
\UseOneTimeHook{include/end/#1}%
\UseOneTimeHook{include/#1/end}%
\UseHook{include/end}%
%-----------------------------------------
\clearpage
Expand All @@ -871,9 +871,9 @@
% followed by another \cs{clearpage} just in case new material got
% added (after all we need to be in well defined state after the
% \cs{include}).
% \changes{v1.2n}{2021/07/23}{Make include/after/name a one-time hook}
% \changes{v1.2n}{2021/07/23}{Make include/name/after a one-time hook}
% \begin{macrocode}
\UseOneTimeHook{include/after/#1}%
\UseOneTimeHook{include/#1/after}%
\UseHook{include/after}%
\clearpage
%-----------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions base/lthooks.dtx
Expand Up @@ -501,15 +501,15 @@
% \AddToHook {./hook}[.]{code} % Same as \AddToHook{./hook}{code}
% \AddToHook {./hook}[./sub]{code}
% \DeclareHookRule{begindocument}{.}{before}{babel}
% \AddToHook {file/after/foo.tex}{code}
% \AddToHook {file/foo.tex/after}{code}
% \end{verbatim}
% are equivalent to:
% \begin{verbatim}
% \NewHook {mypackage/hook}
% \AddToHook {mypackage/hook}[mypackage]{code}
% \AddToHook {mypackage/hook}[mypackage/sub]{code}
% \DeclareHookRule{begindocument}{mypackage}{before}{babel}
% \AddToHook {file/after/foo.tex}{code} % unchanged
% \AddToHook {file/foo.tex/after}{code} % unchanged
% \end{verbatim}
%
% The \meta{default label} is automatically set equal to the name of the
Expand Down Expand Up @@ -3030,10 +3030,11 @@
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}[pTF]{\@@_if_file_hook:w}
% \cs{@@_if_file_hook:wTF} checks if the argument is a valid
% file-specific hook (not, for example, |file/before|, but
% |file/before/foo.tex|). If it is a file-specific hook, then it
% |file/foo.tex/before|). If it is a file-specific hook, then it
% executes the \meta{true} branch, otherwise \meta{false}.
%
% A file-specific hook is \hook{file/\meta{position}/\meta{name}}.
Expand Down Expand Up @@ -3073,7 +3074,7 @@
% implementation just replaces two consecutive slashes (|//|) by a
% single one, to cope with simple cases where the user did something
% like \verb|\def\input@path{{./mypath/}}|, in which case a hook would
% have to be \verb|\AddToHook{file/after/./mypath//file.tex}|.
% have to be \verb|\AddToHook{file/./mypath//file.tex/after}|.
% \begin{macrocode}
\cs_new:Npn \@@_file_hook_normalize:n #1
{ \@@_strip_double_slash:n {#1} }
Expand All @@ -3082,8 +3083,8 @@
% \end{macrocode}
% This function is always called after testing if the argument is a
% file hook with \cs{@@_if_file_hook:wTF}, so we can assume it has
% three parts (it is either \verb|file/before/...| or
% \verb|file/after/...|), so we use \verb|#1/#2/#3 //| instead of just
% three parts (it is either \verb|file/.../before| or
% \verb|file/.../after|), so we use \verb|#1/#2/#3 //| instead of just
% \verb|#1 //| to prevent losing a slash if the file name is empty.
% \changes{v1.0h}{2021/01/07}{Assume hook name has at least three
% nonempty parts (gh/464)}
Expand Down
8 changes: 4 additions & 4 deletions base/testfiles-lthooks/filehook-004.lvt
Expand Up @@ -15,12 +15,12 @@
\START

\AddToHook{file/before}[A]{\typeout{A}}
\AddToHook{file/before/\jobname-foo}[B]{\typeout{B}}
\AddToHook{file/before/\jobname-foo.tex}[C]{\typeout{C}}
\AddToHook{file/\jobname-foo/before}[B]{\typeout{B}}
\AddToHook{file/\jobname-foo.tex/before}[C]{\typeout{C}}

\AddToHook{file/after}[A]{\typeout{A}}
\AddToHook{file/after/\jobname-foo}[B]{\typeout{B}}
\AddToHook{file/after/\jobname-foo.tex}[C]{\typeout{C}}
\AddToHook{file/\jobname-foo/after}[B]{\typeout{B}}
\AddToHook{file/\jobname-foo.tex/after}[C]{\typeout{C}}

\input{\jobname-foo.tex}

Expand Down

0 comments on commit 7d81a91

Please sign in to comment.