

%% Copyright (C) 2011-2012 by Martin Scharrer <martin@scharrer-online.de>
%% ----------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files lstlinebgrd.dtx and lstladdons.ins
%% and the derived filebase lstlinebgrd.sty.
%%
\ProvidesPackage{lstlinebgrd}[%
    2012/05/03
    v0.1
    Provides 'listings' options to color the background of lines]
\RequirePackage{listings}
\RequirePackage{xcolor}

\lst@Key{numbers}{none}{%
    \def\lst@PlaceNumber{\lst@linebgrd}%
    \lstKV@SwitchCases{#1}%
    {none&\\%
     left&\def\lst@PlaceNumber{\llap{\normalfont
                \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\%
     right&\def\lst@PlaceNumber{\rlap{\normalfont
                \kern\linewidth \kern\lst@numbersep
                \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}

\lst@Key{linebackgroundcolor}{}{%
    \def\lst@linebgrdcolor{#1}%
}
\lst@Key{linebackgroundsep}{0pt}{%
    \def\lst@linebgrdsep{#1}%
}
\lst@Key{linebackgroundwidth}{\linewidth}{%
    \def\lst@linebgrdwidth{#1}%
}
\lst@Key{linebackgroundheight}{\ht\strutbox}{%
    \def\lst@linebgrdheight{#1}%
}
\lst@Key{linebackgrounddepth}{\dp\strutbox}{%
    \def\lst@linebgrddepth{#1}%
}
\lst@Key{linebackgroundcmd}{\color@block}{%
    \def\lst@linebgrdcmd{#1}%
}

\newcommand{\lst@linebgrd}{%
    \ifx\lst@linebgrdcolor\empty\else
    \rlap{%
        \lst@basicstyle
        \color{-.}% By default use the opposite (`-`) of the current color (`.`) as background
        \lst@linebgrdcolor{%
        \kern-\dimexpr\lst@linebgrdsep\relax%
        \lst@linebgrdcmd{\lst@linebgrdwidth}{\lst@linebgrdheight}{\lst@linebgrddepth}%
        }%
    }%
    \fi
}
\endinput
%%
%% End of file `lstlinebgrd.sty'.
