I modified your MWE into this:
\documentclass{article}
\def\cccolorbox#1#2{\ifx#2\relax\let\next\allowbreak\else
\def\next{\colorbox{#1}{#2}\allowbreak\cccolorbox{#1}}\fi\next}
\def\ccolorbox#1#2{\fboxsep0pt\cccolorbox{#1}#2\relax}
\def\!#1{\ifx#1\ccolorbox\allowbreak\expandafter\ccolorbox\else
\ifx#1\end\expandafter\expandafter\expandafter\end\else
#1\allowbreak\expandafter\expandafter\expandafter\!\fi\fi}
\def\cccolorbox#1#2{\ifx#2\relax\let\next\allowbreak\else
\def\next{\colorbox{#1}{\strut #2}\allowbreak\cccolorbox{#1}}\fi\next}
\usepackage{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{listings}
\usepackage{lstlinebgrd}
\usepackage{listings}
\usepackage{lstlinebgrd}
\lstset{columns=fullflexible,
basicstyle=\small,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\color{ForestGreen},
frame=single,
extendedchars=true,
keywordstyle=\color{blue},
language=Python,
numbers=left,
numbersep=5pt,
numberstyle=\scriptsize\color{gray},
rulecolor=\color{black},
showspaces=false,
showstringspaces=false,
showtabs=false,
stepnumber=1,
stringstyle=\color{purple},
tabsize=2,
title=\lstname,
belowskip=-1em,
aboveskip=1em,
belowcaptionskip=0em,
}
\begin{document}
First example
\begin{lstlisting}[escapechar=!]
! \ccolorbox{blue!35}{dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-} !
\end{lstlisting}
second example
\begin{lstlisting}[escapechar=!]
dummycode
!\colorbox{blue!35}{\parbox{0.95\textwidth}{dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-}}!
\end{lstlisting}
\end{document}
The first example is based on this discussion:
Listing with background color not line breaking correctly
But the results looks ugly to me. Alternatively, in the second example I used a \parbox inside the \colorbox. It looks better but there is no indentation and the external frame it's still fragmented.
Here is what I obtain:
EDIT:
by commenting the line:
frame=single,
and using the framed environment defined in the framed package you could fix the fragmented box issue. Morever using hangpars environment you could indent correctly inside the parbox.
Here is the updated example:
\documentclass{article}
\def\cccolorbox#1#2{\ifx#2\relax\let\next\allowbreak\else
\def\next{\colorbox{#1}{#2}\allowbreak\cccolorbox{#1}}\fi\next}
\def\ccolorbox#1#2{\fboxsep0pt\cccolorbox{#1}#2\relax}
\def\!#1{\ifx#1\ccolorbox\allowbreak\expandafter\ccolorbox\else
\ifx#1\end\expandafter\expandafter\expandafter\end\else
#1\allowbreak\expandafter\expandafter\expandafter\!\fi\fi}
\def\cccolorbox#1#2{\ifx#2\relax\let\next\allowbreak\else
\def\next{\colorbox{#1}{\strut #2}\allowbreak\cccolorbox{#1}}\fi\next}
\usepackage{framed}
\usepackage{color}
\usepackage[dvipsnames]{xcolor}
\usepackage{listings}
\usepackage{lstlinebgrd}
\usepackage{listings}
\usepackage{lstlinebgrd}
\usepackage{hanging}
\lstset{columns=fullflexible,
basicstyle=\small,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\color{ForestGreen},
% frame=single,
extendedchars=true,
keywordstyle=\color{blue},
language=Python,
numbers=left,
numbersep=5pt,
numberstyle=\scriptsize\color{gray},
rulecolor=\color{black},
showspaces=false,
showstringspaces=false,
showtabs=false,
stepnumber=1,
stringstyle=\color{purple},
tabsize=2,
title=\lstname,
belowskip=-1em,
aboveskip=1em,
belowcaptionskip=0em,
}
\begin{document}
First example
\begin{framed}
\begin{lstlisting}[escapechar=!]
! \ccolorbox{blue!35}{dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-} !
\end{lstlisting}
\end{framed}
second example
\begin{framed}
\begin{lstlisting}[escapechar=!]
dummycode
!\colorbox{blue!35}{\parbox{0.95\textwidth}{\begin{hangparas}{.25in}{1}dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-dummycode-\end{hangparas}}}!
\end{lstlisting}
\end{framed}
\end{document}
which give me this results:
Best Answer
Better late than never
:)
As stated by Qrrbrbirlbel in his comment, the problem is that, because
%
is a (one-line) comment delimiter in theOctave
language,listings
treats your closing overlay delimiter@
as part of the comment.One workaround is to undefine
%
as a comment delimiter, but useliterate
to apply the comment style when that character is encountered anyway. You also need to reset the style at the beginning of each line.Two caveats of this approach:
%
character that occurs within a string literal will mess up the highlighting,