When \endlinechar is less than 1, how do we access its catcode? The following gives the error shown below:
! Bad character code (-1).
l.34 ...ndlinechar\string=\the\catcode\endlinechar
\relax%
? x
\endlinechar=\m@ne
\edef\restorecatcodes{%
\let\noexpand\restorecatcodes\relax%
\endlinechar\string=\the\endlinechar\relax%
\catcode\the\endlinechar\string=\the\catcode\the\endlinechar\relax%
\catcode\string`\noexpand`\string=\the\catcode\string``\relax%
\catcode\string`\noexpand=\string=\the\catcode\string`=\relax%
}%
EDIT
I have seen an approach by Michael Downes (in the pcatcode package). It looks like the following:
\begingroup%
\let\e\endlinechar\edef\p{\the\e}\e13\edef\n{\the\catcode\e}%
\xdef\restorecatcodes{%
\let\noexpand\restorecatcodes\relax%
\endlinechar=\p\relax\catcode\number\e=\n\relax%
\catcode\string`\noexpand`\string=\the\catcode\string``\relax%
\catcode\string`\noexpand=\string=\the\catcode\string`=\relax%
}%
\endgroup%
I think his assumption is that changing the charcode will not affect the catcode.


\nstores the category code of the character^^M, not of the\endlinecharwhen\begingroupis executed. – egreg Oct 28 '12 at 18:41\begingroup\let\e\endlinechar\iffalse\<line end> \fi\chardef\E\e\e13\chardef\n\catcode\e\catcode\e5\relax\relax. I guess we could use the comment sign for\iffalse\<line end>\fi. – Ahmed Musa Oct 29 '12 at 0:58