Let's say I have a document with a listings. And I want to convert that listing into a hyperlink (e.g. to the source code).
The first instinctive attempt will be something like:
\documentclass{article}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{xcolor}
\lstset{basicstyle=\ttfamily,}
\begin{document}
\href{file}{
\begin{lstlisting}[columns=fullflexible, backgroundcolor=\color{black!20}]
code code
\end{lstlisting}
}
\end{document}
This fails because of know limitation (see Strange interaction between hyperref, listings and animate)
The second attempt will be to create a escape inside the code:
\begin{lstlisting}[columns=fullflexible, backgroundcolor=\color{black!20}, escapeinside={\%*}{*)}]
%*\href{file}{Link}*)code code
\end{lstlisting}
(Note, above the line starting with % is not a comment because but a escape combination in a verbatim/lstlistings)
This works but still doesn't cover the whole environment (or at least something that covers most of the line).
I need something like this (fake code to make the typeset code into a link)
\begin{lstlisting}[columns=fullflexible, backgroundcolor=\color{black!20}, escapeinside={\%*}{*)}]
"\href"{file}{code code}
\end{lstlisting}
How can I convert most of the listings line into a hyperlink? I am mostly interested in one-line (or very short) listings.

