I'm trying to add a new key to a custom listings environment. I have tried to modify this example.
My problem is that the value I am attempting to pass through in the document for the key does not seem to be used.
Here is an MWE:
\documentclass{article}
\usepackage{listings}
\makeatletter
\lst@Key{pagewidth}{\linewidth}{\def\LSTwidth{#1}}
\makeatother
\lstnewenvironment{mylisting}[1][]{%
\noindent
\minipage{\LSTwidth}
\lstset{#1}
}
{\endminipage}
\begin{document}
\centering
\begin{mylisting}[pagewidth=0.5\linewidth, frame=lrtb]
NOT IMPORTANT NOT IMPORTANT
NOT IMPORTANT NOT IMPORTANT
\end{mylisting}
\end{document}

minipagewas not aware of the change to its width, because the change was being made after the initial value (\linewidth) had been used as the width for theminipage. – Gonzalo Medina Apr 16 '13 at 17:29