commit 70cdf3c3b997031c0f9ad15586cc5ede030c0112
parent 0619b1c8567fd27c6617da93821c3e5b3a04bf7b
Author: robert <robertrussell.72001@gmail.com>
Date: Fri, 14 Jan 2022 10:49:24 -0800
Optimize \defer
\defer is now a no-op when not in a group. Previously, it would define a
macro that would never be used.
Also, remove the usage warning in the \defer doc comment. The situation
that it said doesn't work appears to actually work. The implementation
of \defer has evolved somewhat since the first time I wrote it (before
it became part of r3tex), so perhaps the old implementation was
inferior in this regard.
Diffstat:
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/util.tex b/util.tex
@@ -123,14 +123,14 @@
\def\regnum#1{\ea\@regnum\meaning#1\relax\@END\relax}
% \defer defers execution of the given tokens until after the current group
-% (like \aftergroup, but with multiple tokens). Note: a defer can not contain
-% more than 1 "child" defer. E.g., \defer{A\defer{B\defer{C}}} is ok, but not
-% \defer{A\defer{B}\defer{C}}.
+% (like \aftergroup, but with multiple tokens).
\newcount\defernext \defernext=0
\def\defer#1{%
- \gcsdef{defer:\the\defernext}{#1}%
- \ea\aftergroup\begcs defer:\the\defernext\endcs
- \incr\defernext
+ \ifnum\currentgrouplevel>0
+ \gcsdef{defer:\the\defernext}{#1}%
+ \ea\aftergroup\begcs defer:\the\defernext\endcs
+ \incr\defernext
+ \fi
}
% \deferasn defers execution of the given tokens until after the next