summaryrefslogtreecommitdiff
path: root/macros/generic/advice/advice.edtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/generic/advice/advice.edtx')
-rw-r--r--macros/generic/advice/advice.edtx73
1 files changed, 53 insertions, 20 deletions
diff --git a/macros/generic/advice/advice.edtx b/macros/generic/advice/advice.edtx
index 415d9da79b..9fad4ef993 100644
--- a/macros/generic/advice/advice.edtx
+++ b/macros/generic/advice/advice.edtx
@@ -29,14 +29,14 @@
% \relax
%
%<*main>
-%<latex>\ProvidesPackage{advice}[2024/01/02 v1.1.0 Extend commands and environments]
+%<latex>\ProvidesPackage{advice}[2024/03/15 v1.1.1 Extend commands and environments]
%<context>%D \module[
%<context>%D file=t-advice.tex,
-%<context>%D version=1.1.0,
+%<context>%D version=1.1.1,
%<context>%D title=Advice,
%<context>%D subtitle=Extend commands and environments,
%<context>%D author=Saso Zivanovic,
-%<context>%D date=2024-01-02,
+%<context>%D date=2024-03-15,
%<context>%D copyright=Saso Zivanovic,
%<context>%D license=LPPL,
%<context>%D ]
@@ -203,7 +203,7 @@
% commands, as assigned by |\advice@setup@init@command|.
run conditions/.default=\AdviceRuntrue,
bailout handler/.default=\relax,
- outer handler/.default=\advice@default@outer@handler,
+ outer handler/.default=\AdviceCollector,
collector/.default=\advice@CollectArgumentsRaw,
collector options/.value required,
raw collector options/.value required,
@@ -324,7 +324,7 @@
\def\advice@setup@init@common{%
\def\AdviceRunConditions{\AdviceRuntrue}%
\def\AdviceBailoutHandler{\relax}%
- \def\AdviceOuterHandler{\advice@default@outer@handler}%
+ \def\AdviceOuterHandler{\AdviceCollector}%
\def\AdviceCollector{\advice@CollectArgumentsRaw}%
\def\AdviceCollectorOptions{}%
\def\AdviceInnerHandler{\advice@error@noinnerhandler}%
@@ -497,7 +497,7 @@
\ifcsname advice@o#1//\string#2\endcsname
\expandonce{\csname advice@o#1//\string#2\expandafter\endcsname\expandafter}%
\else
- \expandafter\noexpand\expandafter#2%
+ \unexpanded\expandafter{\expandafter#2\expandafter}%
\fi
}
% \end{macro}
@@ -764,14 +764,6 @@
\newif\ifAdviceRun
% \end{macro}
%
-% \begin{macro}{\advice@default@outer@handler}
-% The default outer handler merely executes the argument collector. Note
-% that it works for both commands and environments.
-\def\advice@default@outer@handler{%
- \AdviceCollector
-}
-% \end{macro}
-%
% \begin{macro}{\advice@CollectArgumentsRaw}
% This is the default collector, which will collect the argument using
% CollArgs' command |\CollectArgumentsRaw|. It will provide that command
@@ -1081,24 +1073,65 @@
\noexpand\advice@trace{\space\space\space\space
Raw options:
\detokenize\expandafter{\AdviceRawCollectorOptions}}%
+ % Collargs' |return| complicates tracing of the received argument. We put
+ % the code for remembering its value among the raw collector options. The
+ % default is 0; it is needed when we're using a collector other that
+ % |\CollectArguments|, the assumption being that external collectors will
+ % always return the collected arguments braced.
+ \unexpanded{%
+ \gdef\advice@collargs@return{0}%
+ \appto\AdviceRawCollectorOptions{\advice@remember@collargs@return}%
+ }%
\expandonce\AdviceCollector
}%
- % The tracing inner handler must grab the provided argument, if it's to show
- % what it is.
- \edef\advice@inner@handler@trace##1{%
+ \edef\advice@inner@handler@trace@do{%
\noexpand\advice@trace{\space\space
Executing inner handler:
\detokenize\expandafter{\AdviceInnerHandler}}%
+ % When this macro is executed, the received arguments are waiting for us in
+ % |\toks0|.
\noexpand\advice@trace{\space\space\space\space
- Received arguments:
- \noexpand\detokenize{##1}}%
+ Received arguments\noexpand\advice@inner@handler@trace@printcollargsreturn:
+ \noexpand\detokenize\noexpand\expandafter{\unexpanded{\the\toks0}}}%
\noexpand\advice@trace{\space\space\space\space
Options:
\detokenize\expandafter{\AdviceOptions}}%
- \expandonce{\AdviceInnerHandler}{##1}%
+ \expandonce{\AdviceInnerHandler}%
}%
\def\AdviceInnerHandler{\advice@inner@handler@trace}%
}
+\def\advice@remember@collargs@return{%
+ \global\let\advice@collargs@return\collargsReturn
+}
+% This is the entry point into the tracing inner handler. It will either get
+% the received arguments as a braced argument (when Collargs' |return=0|), or
+% from |\collargsArgs| otherwise. We don't simply always inspect
+% |\collargsArgs| because foreign argument collectors will not use this token
+% register; the assumption is that they will always return the collected
+% arguments braced.
+\def\advice@inner@handler@trace{%
+ \ifnum\advice@collargs@return=0
+ \expandafter\advice@inner@handler@trace@i
+ \else
+ \expandafter\advice@inner@handler@trace@ii
+ \fi
+}
+\def\advice@inner@handler@trace@i#1{%
+ \toks0={#1}%
+ \advice@inner@handler@trace@do{#1}%
+}
+\def\advice@inner@handler@trace@ii{%
+ \expandafter\toks\expandafter0\expandafter{\the\collargsArgs}%
+ \advice@inner@handler@trace@do
+}
+\def\advice@inner@handler@trace@printcollargsreturn{%
+ \ifnum\advice@collargs@return=0
+ \else
+ \space(collargs return=%
+ \ifcase\advice@collargs@return braced\or plain\or no\fi
+ )%
+ \fi
+}
% \end{macro}
%<plain>\resetatcatcode
%<context>\stopmodule