Q:

Listings package excerpt code lines between with keywords/escape keys?

Instead of using firstline= and lastline=, is it possible to include code within a certain, user-defined key? That way, if I wanted to include only one definition of a long file, for example, I would not need to worry about typing above the definition, since that would change the first line.

A:

listings provides an experimental feature to include parts of code based on certain begin and end markers (see section 5.7 "Arbitrary linerange markers" of the listings guide).
The options
rangeprefix = <prefix>,
rangesuffix = <suffix>,
linerange   = <startmarker>-<endmarker>

would look in the included code for lines
... some boring code ...
<prefix><startmarker><suffix>
... interesting code ...
<prefix><endmarker><suffix>
... more boring code ...

and include only the interesting parts of the code in the listing (including the start/end markers, unless includerangemarker=false). Several marker pairs can be used with linerange, all separated by commas. Special characters in the prefix, suffix or markers need to be escaped by \.
The disadvantage of this method is that you need to annotate the input code with start and end markers.
Usage example:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\begin{filecontents*}{\jobname.hs}
{- begin map -}
map :: (a -> b) -> [a] -> [b]
map f []     = []
map f (x:xs) = f x : map f xs
{- end map -}

{- begin head -}
head :: [a] -> a
head (x:_) = x
head []    = error "Prelude.head: empty list"
{- end head -}

{- begin tail -}
tail :: [a] -> [a]
tail (_:xs) = xs
tail []     = error "Prelude.tail: empty list"
{- end tail -}
\end{filecontents*}

\lstset{
    language=Haskell,
    basicstyle=\ttfamily,
    backgroundcolor=\color{black!5}
}

\begin{document}
\lstinputlisting[
    linerange=8-10
]{\jobname.hs}

\lstinputlisting[
    rangeprefix=\{-\ ,
    rangesuffix=\ -\},
    includerangemarker=false,
    linerange=begin\ head-end\ head
]{\jobname.hs}
\end{document}

outputs

