The comment-pln code on CTAN (link) defines the plain TeX macros \begincomment and \endcomment, that ignore everything typed in between. The entire code base is included below:
% Comment.tex
% Macro to allow block comments in TeX
%
% Usage: Text between \begincomment and \endcomment is ignored; i.e.
%
% text
% \begincomment
% this text is ignored
% \endcomment
% more text
%
% Notes: Do NOT nest.
% The \endcomment MUST appear at the end of a line.
% TeX processes each line of ignored text, so the macro
% is not particularly fast. Use sparingly. The main use
% is to cause TeX to pass over small blocks of text.
%
% J.C. Alexander, May, 1986
%
\edef\Saveatcatcode{\the\catcode`\@}
\catcode`\@=11
\def\newcodes@{\edef\S@veslashcatcode{\the\catcode`\\}
\edef\S@velbraccatcode{\the\catcode`\{}
\edef\S@verbraccatcode{\the\catcode`\}}
\edef\S@venumsgcatcode{\the\catcode`\#}
\edef\S@veperctcatcode{\the\catcode`\%}
\catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\#=12
\catcode`\%=12\relax}
\def\oldcodes@{\catcode`\\=\S@veslashcatcode
\catcode`\{=\S@velbraccatcode
\catcode`\}=\S@verbraccatcode
\catcode`\#=\S@venumsgcatcode
\catcode`\%=\S@veperctcatcode
\relax}
\def\begincomment{\newcodes@\endlinechar=10 \comment@}
{\lccode`\!=`\\
\lowercase{\gdef\comment@#1^^J{\comment@@#1!endcomment\comment@@@}%
\gdef\comment@@#1!endcomment{\futurelet\next\comment@@@}%
\gdef\comment@@@#1\comment@@@{\ifx\next\comment@@@\let
\next=\comment@\else\def\next{\oldcodes@\endlinechar=`\^^M\relax}%
\fi\next}}}
\catcode`\@=\Saveatcatcode
What is this black magic?
The first few lines I get: It gives a way to redefine the catcodes for \, {, }, #, and % to be "other" and reverting the change. Presumably this will cause them not do their usual voodoo when the comment is treated as comment.
(However: those are the 0, 1, 2, 6, and 14 characters; why is it $, _, and ^ can be omitted? )
I also think I sort of get the definition of \begincomment: It changes the catcodes, sets the endline character, and "calls the macro" \comment@ (which I assume due to the change of endline character actually eats up the commented portion as part of its processing).
My main questions are therefore: how exactly does this
\comment@work and how does it relate to the code in the group immediately after that? I have zero idea what those three\gdefs are doing.