# Grouping the list of listings by chapter

I am using the listings package. I want to print out a list of listings, which I can do. The thing is that in the other listings the typesetter "groups" figures/tables by chapter. Is it possible to achieve a similar behaviour with the list of listings?

Here is an example

Here is how it is now

-

Write into the preamble:

\let\Chapter\chapter

-
This solution seems better as it works automatically for every chapter. I need to learn how to make those kinds of macros, where should I start? –  Tiago Veloso Feb 3 '11 at 10:58
Difficult to say, because there are tons of manuals ... For TeX related stuff: http://tex.stackexchange.com/questions/7695/ and for LaTeX see http://mirror.ctan.org/info/ –  Herbert Feb 3 '11 at 11:05

Add the following to your preamble (adjusted for the book and report class):

\usepackage{etoolbox}

\makeatletter
\patchcmd{\@chapter}{%
\chaptermark{#1}%
}{
\chaptermark{#1}%

EDIT: The "chapter gap" mechanism of the KOMA-Script classes works for any "listofsomething".
Your hack worked. Unfortunately the listings package only provides a \lstlistoflistings which does not match the \listofsomething rule. Is there a better package for listings? –  Tiago Veloso Feb 3 '11 at 10:43
@Tiago: I shouldn't have use code tags for "listofsomething". The KOMA-Script classes control the layout of \lstlistoflistings. –  lockstep Feb 3 '11 at 10:48