* Fontification with a specific function
@ 2004-10-15 10:00 joao
2004-10-15 10:27 ` Joakim Hove
0 siblings, 1 reply; 4+ messages in thread
From: joao @ 2004-10-15 10:00 UTC (permalink / raw)
Hi all,
I'm trying to define a function to find text for fontification. This is
one of the possible elements of `font-lock-keywords'. Looking at the
emacs lisp reference manual (Font Lock Mode/Search-based Fontification),
I see that
When FUNCTION is called, it receives one argument, the limit of
the search. It should return non-`nil' if it succeeds, and set the
match data to describe the match that was found.
I don't see where this "match data" is defined. Can anyone point me to
an example, in the emacs sources or in some package, of this usage of
fontification ?
Thanks,
Joao
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Fontification with a specific function
2004-10-15 10:00 Fontification with a specific function joao
@ 2004-10-15 10:27 ` Joakim Hove
2004-10-15 12:42 ` Oliver Scholz
0 siblings, 1 reply; 4+ messages in thread
From: Joakim Hove @ 2004-10-15 10:27 UTC (permalink / raw)
joao17@mailinator.com (joao) writes:
> I don't see where this "match data" is defined. Can anyone point me to
> an example, in the emacs sources or in some package, of this usage of
> fontification ?
<Disclaimer: I have never done this myself>
The match data is some global emacs variable/stack of the last regexp
search results. Let us say you you wanted to fontify the word 'horse'
then function could be like this:
(defun find-horse (p-max)
;; OK the regexp is probably far to simple, but it finds
;; "horse". Maybe the optional fourth argument COUNT should be
;; set??
(if (re-search-forward " \\(horse\\) " p-max t)
t nil))
This function will return t or nil depending on wether the string
horse was found, and if it was found. The match (i.e. horse), and
other information about the match can be found from the functions
match-string, match-beginning , match-data etc, and I guess that is
what the internals of the font-lock code does. Hence, the match data
is automatically set by the (re-search-forward ) function, you don't
have to do that.
Good luck
Joakim
--
Joakim Hove
hove AT ift uib no
+47 (55 5)8 27 90
http://www.ift.uib.no/~hove/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Fontification with a specific function
2004-10-15 10:27 ` Joakim Hove
@ 2004-10-15 12:42 ` Oliver Scholz
2004-10-16 20:27 ` joao
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Scholz @ 2004-10-15 12:42 UTC (permalink / raw)
Joakim Hove <hove@ift.uib.no> writes:
> joao17@mailinator.com (joao) writes:
>
>
>> I don't see where this "match data" is defined. Can anyone point me to
>> an example, in the emacs sources or in some package, of this usage of
>> fontification ?
>
> <Disclaimer: I have never done this myself>
>
> The match data is some global emacs variable/stack of the last regexp
> search results. Let us say you you wanted to fontify the word 'horse'
> then function could be like this:
>
[function using `re-search-forward'.]
> Hence, the match data is automatically set by the (re-search-forward
> ) function, you don't have to do that.
[...]
Note that you can also set the match-data explicetly with
`set-match-data'. See (info "(elisp)Entire Match Data").
Oliver
--
24 Vendémiaire an 213 de la Révolution
Liberté, Egalité, Fraternité!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Fontification with a specific function
2004-10-15 12:42 ` Oliver Scholz
@ 2004-10-16 20:27 ` joao
0 siblings, 0 replies; 4+ messages in thread
From: joao @ 2004-10-16 20:27 UTC (permalink / raw)
Oliver Scholz <alkibiades@gmx.de> writes:
> Joakim Hove <hove@ift.uib.no> writes:
> [function using `re-search-forward'.]
>
>> Hence, the match data is automatically set by the (re-search-forward
>> ) function, you don't have to do that.
Yes, that's simple enough... but the problem is, my search criteria
here are not purely syntactical, if they were, then I could've used the
other, more usual forms of fontification. Maybe I mix : search with the
regexp functions, then apply my own criteria on top of the match...
> Note that you can also set the match-data explicetly with
> `set-match-data'. See (info "(elisp)Entire Match Data").
This sounds more promising, I'll look into this.
Thank you, Joakim, Oliver.
Joao
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-10-16 20:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-15 10:00 Fontification with a specific function joao
2004-10-15 10:27 ` Joakim Hove
2004-10-15 12:42 ` Oliver Scholz
2004-10-16 20:27 ` joao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).