* font-lock
@ 2009-09-15 10:03 Florian Kaufmann
2009-09-17 0:57 ` font-lock Andreas Politz
0 siblings, 1 reply; 2+ messages in thread
From: Florian Kaufmann @ 2009-09-15 10:03 UTC (permalink / raw)
To: help-gnu-emacs
I want to configure font-lock for my own mode. I still have troubles
to understand what I have to do so font-lock understands what to do
when matches overlap. Say my comments start with 2 hashes and go until
the end of the line, and strings are in between double quotes:
(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.
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):
comments
##.*$
#\w+
#\*.*?\*#
strings
".*?"
'\w+
'\[.*?\]
`\W+
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: font-lock
2009-09-15 10:03 font-lock Florian Kaufmann
@ 2009-09-17 0:57 ` Andreas Politz
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Politz @ 2009-09-17 0:57 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-09-17 0:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-15 10:03 font-lock Florian Kaufmann
2009-09-17 0:57 ` font-lock Andreas Politz
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.