\makeatletter
\let\OldStatex\Statex
\renewcommand{\Statex}[1][3]{%
	\setlength\@tempdima{\algorithmicindent}%
	\OldStatex\hskip\dimexpr#1\@tempdima\relax}
\makeatother

\makeatletter
% code borrowed from Andrew Stacey; See
% https://tex.stackexchange.com/a/50054/3954
\tikzset{%
  remember picture with id/.style={%
    remember picture,
    overlay,
    save picture id=#1,
  },
  save picture id/.code={%
    \edef\pgf@temp{#1}%
    \immediate\write\pgfutil@auxout{%
      \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}%
  },
  if picture id/.code args={#1#2#3}{%
    \@ifundefined{save@pt@#1}{%
      \pgfkeysalso{#3}%
    }{
      \pgfkeysalso{#2}%
    }
  }
}

\def\savepointas#1#2{%
  \expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

\def\tmk@labeldef#1,#2\@nil{%
  \def\tmk@label{#1}%
  \def\tmk@def{#2}%
}

\tikzdeclarecoordinatesystem{pic}{%
  \pgfutil@in@,{#1}%
  \ifpgfutil@in@%
    \tmk@labeldef#1\@nil
  \else
    \tmk@labeldef#1,(0pt,0pt)\@nil
  \fi
  \@ifundefined{save@pt@\tmk@label}{%
    \tikz@scan@one@point\pgfutil@firstofone\tmk@def
  }{%
  \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
  \pgfsys@getposition{\pgfpictureid}\save@this@pic%
  \pgf@process{\pgfpointorigin\save@this@pic}%
  \pgf@xa=\pgf@x
  \pgf@ya=\pgf@y
  \pgf@process{\pgfpointorigin\save@orig@pic}%
  \advance\pgf@x by -\pgf@xa
  \advance\pgf@y by -\pgf@ya
  }%
}

% end of Andrew's code

\newlength\AlgIndent
\setlength\AlgIndent{0pt}
% main command to draw the colored background
\newcounter{mymark}
\newcommand\ColorLine[1]{%
  \stepcounter{mymark}%
  \tikz[remember picture with id=mark-\themymark,overlay] {;}%
  \begin{tikzpicture}[remember picture,overlay]%
    \filldraw[#1]%
   let \p1=(pic cs:mark-\themymark), 
   \p2=(current page.east)  in 
   ([xshift=-\ALG@thistlm-0.3em,yshift=-0.7ex]0,\y1)  rectangle ++(\linewidth+\AlgIndent,\baselineskip);
  \end{tikzpicture}%
}%

% colored loops and declarations
\algnewcommand\CREQUIRE[1]{\item[\setlength\AlgIndent{1.6em}\ColorLine{#1}\algorithmicrequire]}%
\algnewcommand\CENSURE[1]{\item[\setlength\AlgIndent{1.6em}\ColorLine{#1}\algorithmicensure]}%
\algnewcommand\CSTATE[1]{\State\ColorLine{#1}}%
\algnewcommand\CSTATEx[1]{\Statex\ColorLine{#1}}%
\algnewcommand\CCOMMENT[1]{\Comment\ColorLine{#1}}%

%\algdef{SE}[WHILE]{CWHILE}{ENDWHILE}%
%   [2][default]{\ColorLine{redL}\algorithmicwhile\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
%   {\algorithmicend\ \algorithmicwhile}%
%\algdef{SE}[FOR]{CFOR}{ENDFOR}%
%   [2][default]{\ColorLine{redL}\algorithmicfor\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
%   {\algorithmicend\ \algorithmicfor}%
%\algdef{S}[FOR]{CFORALL}%
%   [2][default]{\ColorLine{redL}\algorithmicforall\ #2\ \algorithmicdo\ALG@compatcomm{#1}}%
%\algdef{SE}[LOOP]{CLOOP}{ENDLOOP}%
%   [1][default]{\ColorLine{redL}\algorithmicloop\ALG@compatcomm{#1}}%
%   {\algorithmicend\ \algorithmicloop}%
%\algdef{SE}[REPEAT]{CREPEAT}{UNTIL}%
%   [1][default]{\ColorLine{redL}\algorithmicrepeat\ALG@compatcomm{#1}}%
%   [1]{\algorithmicuntil\ #1}%
%\algdef{SE}[IF]{CIF}{ENDIF}%
%   [2][default]{\ColorLine{redL}\algorithmicif\ #2\ \algorithmicthen\ALG@compatcomm{#1}}%
%   {\algorithmicend\ \algorithmicif}%
%\algdef{C}[IF]{IF}{CELSIF}%
%   [2][default]{\ColorLine{redL}\algorithmicelse\ \algorithmicif\ #2\ \algorithmicthen\ALG@compatcomm{#1}}%
%\algdef{Ce}[ELSE]{IF}{CELSE}{ENDIF}%
%   [1][default]{\ColorLine{redL}\algorithmicelse\ALG@compatcomm{#1}}%
\makeatother
