# Skipping line numbers in lstlisting

Referring to Skip line numbers and resume from specific number I tried to skip several line numbers in my listings and continue with a specific number. But in my case there is a really bad side effect: each line after \Reactivatenumber{...} has the same number. Also new listings have the number defined in the previous \Reactivatenumber{...}

My Example:

\documentclass{article}
\usepackage{listings}

\lstset{numbers=left,numberblanklines=false,escapeinside=||}
\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\let\thelstnumber\relax%
}%
}

\newcommand*\Reactivatenumber[1]{%
\let\thelstnumber\origthelstnumber%
\setcounter{lstnumber}{\numexpr#1-1\relax}%
}%
}

\makeatother

\begin{document}
First listing:
\begin{lstlisting}[firstnumber=1]
var myFunc = function() {|\Suppressnumber|
//my function does many great things
//and it's only 10 lines long!|\Reactivatenumber{12}|
}

var oneMoreFunc = function() {
return myFunc;
}
\end{lstlisting}
One more listing:
\begin{lstlisting}[firstnumber=18]
var something = "bla";
console.log(something);
\end{lstlisting}
\end{document}


Result:

\newcommand*\Reactivatenumber[1]{%
\setcounter{lstnumber}{\numexpr#1-1\relax}
\let\thelstnumber\origthelstnumber%
\refstepcounter{lstnumber}
}%
}


Full code:

\documentclass{article}
\usepackage{listings}

\lstset{numbers=left,numberblanklines=false,escapeinside=||}
\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\let\thelstnumber\relax%
}%
}

\newcommand*\Reactivatenumber[1]{%
\setcounter{lstnumber}{\numexpr#1-1\relax}
\let\thelstnumber\origthelstnumber%
\refstepcounter{lstnumber}
}%
}

\makeatother

\begin{document}
First listing:
\begin{lstlisting}[firstnumber=1]
var myFunc = function() {|\Suppressnumber|
//my function does many great things
//and it's only 10 lines long!|\Reactivatenumber{12}|
}

var oneMoreFunc = function() {
return myFunc;
}

}

var oneMoreFunc = function() {
return myFunc;
}
\end{lstlisting}
One more listing:
\begin{lstlisting}[firstnumber=18]
var something = "bla";
console.log(something);

}

var oneMoreFunc = function() {
return myFunc;
}
\end{lstlisting}
\end{document}


A small addition to to the previous also correct answer. At the end of the line:

\refstepcounter{lstnumber}%


There should be a '%'. Omitting this will result in subsequent inline listings to be improperly formatted.

The reactivate command is then as follows:

\newcommand*\Reactivatenumber[1]{%
\setcounter{lstnumber}{\numexpr#1-1\relax}