\usepackage{listings}
\newcounter{tmp}
% https://tex.stackexchange.com/questions/149056/how-can-i-define-additional-literate-replacements-without-deleting-existing-ones
\makeatletter
\def\addToLiterate#1{\edef\lst@literate{\unexpanded\expandafter{\lst@literate}\unexpanded{#1}}}
\lst@Key{moreliterate}{}{\addToLiterate{#1}}
\makeatother
% General listings settings
\lstset{%
	basewidth=0.5em,
	basicstyle=\tt\small,
	breakatwhitespace=false,
	breaklines=true,
	captionpos=b,
	columns=[c]fixed,
	commentstyle=\sl,
	escapeinside={[+}{+]},  % chktex 9
	frame=,
	backgroundcolor=\color{lstbg},
	keepspaces=true,
	keywordstyle=\bf,
	postbreak=\mbox{\textcolor{gray}{$\hookrightarrow$}\space},
	showspaces=false,
	showstringspaces=false,
	showtabs=false,
	stringstyle=\it,
	tabsize=4,
%	upquote=true,
	numberstyle=\tiny,
}
\usepackage{preamble/lstlangclean}
\usepackage{preamble/lstlanghaskell}
\usepackage{preamble/lstlangarduino}
\lstloadlanguages{%
	{[Arduino]C++},%
	{c},%
	{Python},%
	{Clean},%
	{[Regular]Haskell},
	{[Lhs2Tex]Haskell}}
\newcommand{\cinline}[1]{\lstinline[language=c,postbreak=]|#1|}
\newcommand{\arduinoinline}[1]{\lstinline[language={[Arduino]C++},postbreak=]|#1|}
\newcommand{\pythoninline}[1]{\lstinline[language=Python,postbreak=]|#1|}
\newcommand{\cleaninline}[1]{\lstinline[language=Clean,postbreak=]|#1|}
\newcommand{\cleaninputlisting}[2][]{\renewcommand*{\lstlistingname}{Listing (\gls{CLEAN})}\lstinputlisting[escapeinside={/*}{*/},language=Clean,#1]{\subfix{#2}}}
\newcommand{\haskellinline}[1]{\lstinline[language={[Regular]Haskell},postbreak=]|#1|}
\newcommand{\haskellinputlisting}[2][]{\renewcommand*{\lstlistingname}{Listing (\gls{HASKELL})}\lstinputlisting[language={[Regular]Haskell},#1]{\subfix{#2}}}
\newcommand{\haskelllhstexinline}[1]{\lstinline[language={[Lhs2Tex]Haskell},postbreak=]|#1|}
%For storing listings in footnotes
\newsavebox{\LstBox}
% Fix list of listings title
\renewcommand{\lstlistlistingname}{List of Listings}
% Fix list of listings chapter separator
\makeatletter
\let\my@chapter\@chapter%
\renewcommand*{\@chapter}{%
  \addtocontents{lol}{\protect\addvspace{10pt}}%
  \my@chapter}
\makeatother

\lstnewenvironment{lstPython}[1][]
	{% 
		\lstset{language=Python, #1}
		\renewcommand*{\lstlistingname}{Listing (\gls{PYTHON})}
	}
	{}
\lstnewenvironment{lstClean}[1][]
	{% 
		\lstset{language=Clean, #1}
		\renewcommand*{\lstlistingname}{Listing (\gls{CLEAN})}
	}
	{}
\lstnewenvironment{lstArduino}[1][]
	{% 
		\lstset{language={[Arduino]C++}, #1}
		\renewcommand*{\lstlistingname}{Listing (\gls{CPP})}
	}
	{}
\lstnewenvironment{lstHaskell}[1][]
	{%
		\lstset{language={[Regular]Haskell},#1}%
		\renewcommand*{\lstlistingname}{Listing (\gls{HASKELL})}
	}
	{}
\lstnewenvironment{lstHaskellLhstex}[1][]
	{%
		\lstset{language={[Lhs2Tex]Haskell},#1}%
		\renewcommand*{\lstlistingname}{Listing (\gls{HASKELL})}
	}
	{}

% Pseudocode
\usepackage[algochapter,linesnumbered,lined,boxed]{algorithm2e}
% Fix the algorithm font
\renewcommand\AlCapFnt{\normalfont}

