I was just wonder if it would be possible to have a "Copy to Clipboard Button" next to each listing which would just copy the verbatim content of the lstlistings environment to the clipboard.
An acroread-only solution would suffice for my purposes.
Ok, here are two approaches, both of which not perfect, both of which not 100% what was requested. But maybe together we can optimise them :-)
\documentclass{article}
\usepackage{listings}
\usepackage{attachfile}
\usepackage{accsupp}
\usepackage{verbatim}
\usepackage{color}
\usepackage[misc]{ifsym}
\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
\makeatletter
\lst@RequireAspects{writefile}
% Use \attachfile command to add listing content as paperclip.
\lstnewenvironment{attachedlisting}{%
\lst@BeginAlsoWriteFile{\jobname.lsttmp}%
}
{%
\lst@EndWriteFile
\marginpar{\attachfile[appearance=false,icon=Paperclip,mimetype=text/tex]{\jobname.lsttmp}}
}
% Use accsupp package to add listing content as copyable text.
\lstnewenvironment{copyablelisting}{%
\lst@BeginAlsoWriteFile{\jobname.lsttmp}%
}
{%
\lst@EndWriteFile
\let\verbatim@processline\add@lstline
\global\let\lstfile\empty
\verbatiminput{\jobname.lsttmp}%
\marginpar{(\BeginAccSupp{method=escape,ActualText={\lstfile}}\PaperPortrait\EndAccSupp{})}
}
\def\add@lstline
{\xdef\lstfile{\unexpanded\expandafter{\lstfile}\the\verbatim@line\string^^J}}
\makeatother
\begin{document}
\lstset{breakatwhitespace=true,breaklines=true,language=[LaTeX]TeX,basicstyle=\small\ttfamily,flexiblecolumns,backgroundcolor=\color{lstbgcolor}}
\begin{attachedlisting}
\documentclass{article}
\title{Cartesian closed categories and the price of eggs}
\author{Jane Doe}
\date{September 1994}
\begin{document}
\maketitle
Hello world!
\end{document}
\end{attachedlisting}
\begin{copyablelisting}
\documentclass{article}
\title{Cartesian closed categories and the price of eggs}
\author{Jane Doe}
\date{September 1994}
\begin{document}
\maketitle
Hello world!
\end{document}
\end{copyablelisting}
\end{document}

The first environment, attachedlisting displays a paper clip which allows to open the listing contents in an editor (or save to file).
The second environment, copyablelisting displays a symbol which, when copied, will paste to the listing contents.
So this is as good as I can make it for the time being. I'm open to suggestions of course.
attachfilepackage. in that case the user would be able to save the source to file as opposed to copy it to the clipboard. Note that the text to be attached has to come from a separate file though. – ArTourter Jun 06 '13 at 12:31listingsoffer any means to get at the verbatim content of the environment? I just skimmed the code and didn't find any obvious place where a line of code is stored before processing (or whatever unitlistingsis reading the code in). – Stephan Lehmke Nov 18 '13 at 15:56