You can make a dummy \def inside \detectmodifiers which will be affected by any of the mentioned modifiers if its at the beginning of the macro. Then you can test for the modifiers to build the if-switches. You can use \meaning on a dummy macro which contains the \outer, \long and \protected modifiers as string which can be extracted and turned into macros again using \scantokens.
One challenge would be \global: you need to make the assignment in a group and check if it is still the same after the group.
You should use the if-tree you have but rather define a macro \themodifiers which is then put in front of \def:
\def\themodifiers{\protected\global} ... \themodifiers\def....
Here some proof-of-concept code. I remembered that the "modifiers" are called prefixes, so I changed the macro names. The prefixes are stored in the \theprefixes macro which can be used in front of \def. The \global prefix however is special and can't be read like this. I tried to define the \dummy macro inside a group and use \global\let\gdummy\dummy so that I can test if both are still the same after the end of the group. The problem is: a \begingroup or { isn't allowed before the \def\dummy :-(
You should change the names of some macros to prevent name clashes.
\documentclass{article}
\makeatletter
\def\macroother{macro}
\@onelevel@sanitize\macroother
\makeatother
\expandafter
\def\expandafter\returnprefixes\expandafter#\expandafter1\macroother#2\relax{%
\scantokens{\def\theprefixes{#1}}%
}
\def\detectprefixes{%
\def\dummy{}%
\expandafter\returnprefixes\meaning\dummy\relax
}
\def\otherdef{%
\detectprefixes
% other code
\theprefixes\def
}
\global\long\outer\protected\otherdef\mymacro{mystuff}
\show\mymacro
\begin{document}
\end{document}
\otherdefwas preceded by a\globaletc. modifier. So when the user is writing\global\otherdef\macro{<code>}it can pass the\globalto the underlying\defwhile having some code before that. – Martin Scharrer Apr 12 '11 at 18:31\def' comes from. The TeX modifiers all allow expansion, so it is possible to have things lit\def\example{\let\a\b}and have\global\examplework correctly. – Joseph Wright Jul 19 '11 at 16:02\globalto a particular group (so that{\let\foo=a {\localizeglobal {\global\let\foo=b}\show\foo }\show\foo}givesbfor the first show andafor the second show.). So I want to be able to play around with defining other macros before a given\defis run. (Though I may end up deciding that the easiest solution is to parse the arguments to\def(or\otherdef), execute\deffirst, and then use\letas I need to.) – Jason Gross Dec 31 '11 at 12:58