[Tex/LaTex] listings-package custom language use space as comment-delimiter

commentslistings

I'm creating a custom language definition with the LaTeX listings package that should render Java's Jar-Manifest files (key: value Pairs) so that one can easily distinguish key and value.

My approach ("hacky" but alright for my problem) is to declare the space character as delimiter for comments (as // is in Java etc.) and style comments as normal text and normal text (what will everything left from the first space be – especially the key:) as keywords. So I'll even style multiline entries (by specification starting with a space) correctly. All by a one-line language definition.

a part of a sample manifest file

Manifest-Version: 1.0
Bundle-Description: The realization of the context bus on top of Sodapop
 7 as part of the universAAL Middleware (OSGi)

my language definition

\lstdefinelanguage{manifest}{
    morecomment=[l] % <-- this is the problem
}

My problem is: how can I declare the space char as the delimiter for comments?

Escaping it with a preceeding backslash (like recommended when using #, & or other TeX-reserved charaters) does not work. Hacking around with the unicode representation U+0020 and the inputenc package does neither.

Edit: Minimal Working Example

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage{listings}

\lstdefinelanguage{manifest}{
    morecomment=[l]: % works only for single-line entries, need 'space', not ':'
}

\begin{document}
\begin{lstlisting}[language=manifest, 
    basicstyle=\bfseries, 
    commentstyle=\normalfont]
Manifest-Version: 1.0
Bundle-Description: The realization of the context bus on top of Sodapop
 7 as part of the universAAL Middleware (OSGi)
\end{lstlisting}
\end{document}

Best Answer

Try this for single line comments:

morecomment=[l]{\ }
Related Question