Here's an implementation that satisfies your needs:

\documentclass{article}
\usepackage{environ,etoolbox}% http://ctan.org/pkg/{environ,etoolbox}
\makeatletter
\newcounter{orderenum}\newcounter{listcount}[orderenum]%\newcounter{listtotal}[orderenum]
\let\olditem\item% Store regular \item macro
\NewEnviron{orderenum}[1][\relax]{%
\stepcounter{orderenum}% New orderenum environment (also resets listcount)
\def\optarg{#1}% Store optional argument
\expandafter\ifx\optarg\relax% A normal list
\enumerate\BODY\endenumerate% Process environment
\else% A reordered list
\g@addto@macro{\BODY}{\item\relax\item}% Used to delimit the items; last item identified by \item\relax\item
\def\item##1\item{% Redefine \item to capture contents
\def\optarg{##1}%\show\optarg%
\expandafter\ifx\optarg\relax\else% Last item not reached
\stepcounter{listcount}% Next item being processed
\csgdef{orderenum@\theorderenum @\thelistcount}{##1}% Store item in control sequence
\expandafter\item% Recursively continue processing items
\fi
}
\BODY% Process environment (save items)
\renewcommand*{\do}[1]{\olditem \csname orderenum@\theorderenum @##1\endcsname}% Print each item in order
\enumerate\docsvlist{#1}\endenumerate% Process items
\fi%
}
\makeatother
\begin{document}
\begin{orderenum}
\item This is the second item.
\item This is the third item.
\item This is the first item.
\end{orderenum}
\begin{orderenum}[3,1,2]
\item This is the second item.
\item This is the third item.
\item This is the first item.
\end{orderenum}
\end{document}
The entire list is "processed" twice. The first time around, each \item
is stored in a number-based macro. The second time around, the items are called one by one, in the order that is defined by the comma-separated list in the optional argument to orderenum
.
The advantage with this approach is that you can use the regular \item
-interface (and you don't have to use (for example), \myitem{...}
to capture the items. Also, a test is done to ensure that no optional argument defaults to a regular list. Technically you can also specify a subset of the items in the list to be printed.
Update: For using amsthm
's proof
environment inside orderenum
, it is required to understand the proof
is actually set as a single-item list. As such, it uses \item
, which orderenum
redefines for capturing its contents. So, we need a strategy around it. Due to the nature of the definition of proof
, xpatch
provides a means to patch it. The following code should be used as replacement in the above example:
\usepackage{environ,xpatch}% http://ctan.org/pkg/{environ,xpatch}
\xpatchcmd{\proof}{\item}{\olditem}{}{}% Patch proof environment to use \olditem
Now one can successfully use, say
%...
\begin{orderenum}[3,1,2]
\item This is the second item.
\item This is the third item.
\begin{proof} some proof \end{proof}
\item This is the first item.
\begin{proof} another proof \end{proof}
\end{orderenum}
%...

Adding an update to your question to the ordered list is not difficult. Here's a MWE that includes your definition of exenumerate
from enumerating examples:

\documentclass{article}
\usepackage{environ,etoolbox}% http://ctan.org/pkg/{environ,etoolbox}
\makeatletter
\newcounter{myenumi}
\renewcommand{\themyenumi}{\textbf{Example \thesection.\arabic{myenumi}.}}
\newenvironment{exenumerate}{%
% stuff for beginning of environment goes here
\setlength{\parindent}{0pt}% don't indent paragraphs
\setcounter{myenumi}{0}% restart numbering
\bigskip% skip a line
\renewcommand{\olditem}{% new definition of item
\par %start a new line
\medskip
\refstepcounter{myenumi}% advance counter
\noindent \makebox[8em][l]{\themyenumi}% print counter to width of 3em, aligned to left
}% end of definition of item
}{% at end of environment
\par% start new paragraph
\bigskip% skip a line
\noindent% don't indent new paragraph
\ignorespacesafterend% ignore spaces after environment
}
\newcounter{orderenum}\newcounter{listcount}[orderenum]%\newcounter{listtotal}[orderenum]
\let\olditem\item% Store regular \item macro
\NewEnviron{orderenum}[1][\relax]{%
\stepcounter{orderenum}% New orderenum environment (also resets listcount)
\def\optarg{#1}% Store optional argument
\expandafter\ifx\optarg\relax% A normal list
\enumerate\BODY\endenumerate% Process environment
\else% A reordered list
\g@addto@macro{\BODY}{\item\relax\item}% Used to delimit the items; last item identified by \item\relax\item
\def\item##1\item{% Redefine \item to capture contents
\def\optarg{##1}%\show\optarg%
\expandafter\ifx\optarg\relax\else% Last item not reached
\stepcounter{listcount}% Next item being processed
\csgdef{orderenum@\theorderenum @\thelistcount}{##1}% Store item in control sequence
\expandafter\item% Recursively continue processing items
\fi
}
\BODY% Process environment (save items)
\renewcommand*{\do}[1]{\olditem \csname orderenum@\theorderenum @##1\endcsname}% Print each item in order
\exenumerate\docsvlist{#1}\endexenumerate% Process items
\fi%
}
\makeatother
\begin{document}
\begin{orderenum}
\item This is the second item.
\item This is the third item.
\item This is the first item.
\end{orderenum}
\begin{orderenum}[3,1,2]
\item This is the second item.
\item This is the third item.
\item This is the first item.
\end{orderenum}
\end{document}
\item[3] This is the third item
? You can do that already; but I would not call that 'automatic'! – jon Aug 15 '13 at 1:45