help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: font-lock


From: Andreas Politz
Subject: Re: font-lock
Date: Thu, 17 Sep 2009 02:57:27 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Florian Kaufmann <sensorflo@gmail.com> writes:

[...]
> (defconst adoc-font-lock-keywords
>   (eval-when-compile
>     (list
>      (cons "##.*$" 'font-lock-comment-face)
>      (cons "\".*?\"" 'font-lock-string-face)
>     )))
>
> Now in my test buffer
>
> "foo##bar"
> ##foo"bar"
>
> The first line is not correctly fontified. I expect that the while
> line has the string face, but "foo has no face, and ##bar" has comment
> face. If I reverse the two (cons ...) lines, then the 2nd line in the
> test buffer is ill formated: ##foo has no face, and "bar" has comment
> face; I expect the whole 2nd line to be in comment face.
>
,----[ (info "(elisp) Search-based Fontification") ]
|    Each element of `font-lock-keywords' specifies how to find certain
| cases of text, and how to highlight those cases.  Font Lock mode
| processes the elements of `font-lock-keywords' one by one, and for each
| element, it finds and handles all matches.  Ordinarily, once part of
| the text has been fontified already, this cannot be overridden by a
| subsequent match in the same text; but you can specify different
| behavior using the OVERRIDE element of a SUBEXP-HIGHLIGHTER.
`----

> I think I can't make use of syntax tables, because actually my
> comments/strings are more complex (and even that is a bit simplified
> for this post):
>
Why not use both ? Syntax tables for, what I suppose are, multiline
matches (since they are difficult to do `by hand') and keywords for the
rest.

> comments
> ##.*$
> #\w+
> #\*.*?\*#
>
> strings
> ".*?"
> '\w+
> '\[.*?\]
> `\W+

-ap





reply via email to

[Prev in Thread] Current Thread [Next in Thread]