# adjustbox and lstnewenvironment

I'm trying to use adjustbox to make a frame around listings (I know that listings itself can do this, but its implementation produces sub-optimal results when the line heights are not equal throughout the code). Here is what I tried:

\documentclass{article}
\usepackage{listings}
% sanity checking: the following line works
%\lstnewenvironment{listing}{}{}

% the following line is what I'd like to do

\begin{document}
\begin{listing}
this is
some
test
code
\end{listing}
\end{document}


I tried defining a new listings environment that uses adjustbox to put a frame around the listing. However, this does not compile, but just hangs on running pdflatex:

*         % I just pressed enter here
(Please type a command or say \end')
*\end     % typing \end does not work either ;)

*\end

*
(Please type a command or say \end')


In Texmaker, pdflatex is a bit more chatty: "Emergency stop. <> test.tex (job aborted, no legal \end found)"

You can use the macro version \adjustbox{<options}{<box contents>} which as the manual states also works with \bgroup and \egroup: \adjustbox{<options}\bgroup<box contents>\egroup. That allows the following definition:

\lstnewenvironment{listing}
{\adjustbox{left,trim=0 0 0 2pt,fbox}\bgroup}
{\egroup}


\documentclass{article}
\usepackage{listings}

% the following line is what I'd like to do
\lstnewenvironment{listing}
{\adjustbox{left,trim=0 0 0 2pt,fbox}\bgroup}
{\egroup}

\begin{document}
\begin{listing}
this is
some
test
code
\end{listing}
\end{document}