It's is well known that to ensure that a certain <counter> is automatically reset on subsequent slides of a same frame one has to use either \resetcounteronoverlays{<counter>} (for LaTeX counters) or \resetcountonoverlays{<counter>} (for TeX counters). However, this seems not to work for the lstnumber counter used for numbering lines in a lstlisting environment when the name key is used, as the following simple MWE shows:
\documentclass{beamer}
\usepackage{listings}
\lstset{numbers=left}
\resetcounteronoverlays{lstnumber}
\begin{document}
\begin{frame}[fragile]
\begin{onlyenv}<1>
\begin{lstlisting}[name=first]
test line in first listing
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<2>
\begin{lstlisting}[name=second]
test line in second listing
\end{lstlisting}
\end{onlyenv}
\end{frame}
\end{document}
The output:

If the name option is not used, the effect of \resetcounteronoverlays{lstnumber} is the expected and one gets the correct result.
How can the lstnumber be prevented from stepping when using the name key and beamer overlays?




4! Whenname=firstthe starting number is stored in the macro, not counter,\lstno@first. There is no standardbeamercommand to rest that. – Andrew Swann Mar 11 '14 at 16:00\lst@firstnumber? – Gonzalo Medina Mar 12 '14 at 12:34\lst@SetFirstNumberwhich uses\lstno@first– Andrew Swann Mar 12 '14 at 13:01