Skipping line numbers in lstlisting
Change your definition to
\newcommand*\Reactivatenumber[1]{%
\setcounter{lstnumber}{\numexpr#1-1\relax}
\lst@AddToHook{OnNewLine}{%
\let\thelstnumber\origthelstnumber%
\refstepcounter{lstnumber}
}%
}
Full code:
\documentclass{article}
\usepackage{listings}
\lstset{numbers=left,numberblanklines=false,escapeinside=||}
\let\origthelstnumber\thelstnumber
\makeatletter
\newcommand*\Suppressnumber{%
\lst@AddToHook{OnNewLine}{%
\let\thelstnumber\relax%
\advance\c@lstnumber-\@ne\relax%
}%
}
\newcommand*\Reactivatenumber[1]{%
\setcounter{lstnumber}{\numexpr#1-1\relax}
\lst@AddToHook{OnNewLine}{%
\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}