* Multiline Font Lock
@ 2008-09-10 14:50 Eric
2008-09-10 20:59 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 2+ messages in thread
From: Eric @ 2008-09-10 14:50 UTC (permalink / raw)
To: help-gnu-emacs
I'm trying to set up multiline font-locking for a major mode I've been
working on. I've spent a fair bit of time wrestling with it, but I'm
still not getting completely desired results.
Emacs correctly fontifies the multiline region, and then correctly
refontifies it when the fontify-region function gets called again.
The problem is that when I make changes in the middle of the region,
the modified line and subsequent line get defontified until Emacs
comes through and refontifies.
When I set font-lock-multiline variable to 't', the text is never
defontified and new text is always immediately fontified correctly
(and without the aid of my region function [see below]). I'm guessing
then that there's some problem with my regexp or with the way I'm
applying my font-lock-multiline property.
What should I be doing differently so that I get the same behavior
without needing to turn font-lock-multiline on? Do I just _need_ to
set the font-lock-multiline variable to get the desired behavior?
The syntax for one of these multiline groups is:
JAVA_ON
whatever
text
your
heart desires with any
{{punctuation}}} until
JAVA_OFF
------
The emacs function I've added to font-lock-extend-region-functions is
below:
(defun ecf-font-lock-multiline-java-block-check ()
"Ensures that no java block exists in the region or that a full java
block exists in the region.
Returns t if the region had to be changed or nil if no changes were
needed."
;;There seems to be no way around the warning about font-lock-beg
and font-lock-end without binding them ourselves with defvar. We need
to use them (and they're defined for us in the function that will call
this one).
(let ((changed))
(save-excursion
(when (> font-lock-beg (point-min))
;look for a JAVA_OFF with no matching JAVA_ON
(goto-char font-lock-beg)
(when (re-search-forward "JAVA_OFF" font-lock-end t)
(when (> font-lock-beg (re-search-backward "JAVA_ON" (point-min)
t)) ;moves point to JAVA_ON or begin of buffer
(setq font-lock-beg (point))
(setq changed t))))
(when (< font-lock-end (point-max))
;look for a JAVA_ON with no matching JAVA_OFF
(goto-char font-lock-end)
(if (re-search-backward "JAVA_ON" font-lock-beg t)
(when (< font-lock-end (re-search-forward "JAVA_OFF" (point-max)
t))
(end-of-line)
(setq font-lock-end (point))
(setq changed t))))
(goto-char font-lock-beg)
(while (re-search-forward "JAVA_ON" font-lock-end t)
(let ((start-java-block (- (point) 7))
(end-java-block (+ 1 (re-search-forward "JAVA_OFF" font-lock-
end))))
(put-text-property start-java-block end-java-block font-lock-
multiline t)
)))
changed))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Multiline Font Lock
2008-09-10 14:50 Multiline Font Lock Eric
@ 2008-09-10 20:59 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 2+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-10 20:59 UTC (permalink / raw)
To: Eric; +Cc: help-gnu-emacs
Eric wrote:
> The syntax for one of these multiline groups is:
> JAVA_ON
> whatever
> text
> your
> heart desires with any
> {{punctuation}}} until
> JAVA_OFF
Perhaps an alternative is to use multiple major modes:
http://www.emacswiki.org/cgi-bin/wiki/MultipleModes
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-09-10 20:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-10 14:50 Multiline Font Lock Eric
2008-09-10 20:59 ` Lennart Borgman (gmail)
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).