When posting snippets of latex code that define or modify commands containing @, one commonly includes the \makeatletter...\makeatother wrapper that's necessary if pasting the snippet into an ordinary document. However, such pasting then has bad effects if it happens to occur somewhere that \makeatletter is already in effect. Is there a good way to "save the state of 'at'", execute some code, and then restore the original state, whatever it might have been?
(Yes, I know that \makeatletter/\makeatother are local to groups. However, certain code doesn't work the same way inside a group, e.g. macro definitions are local to the group by default, so it would be better to avoid having to enclose the whole snippet in a group.)

.styfile.) – jon Oct 21 '16 at 04:13\makeatletterand\makeatotheras ”snippet delimiters“ – egreg Oct 21 '16 at 07:42\makeatletterand\makeatotheractually did. – Mike Shulman Oct 21 '16 at 08:33