From: Eric <etklaus@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Multiline Font Lock
Date: Wed, 10 Sep 2008 07:50:34 -0700 (PDT) [thread overview]
Message-ID: <f6df65b1-b6c3-46ae-8aea-0ab50b16e9e6@k7g2000hsd.googlegroups.com> (raw)
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))
next reply other threads:[~2008-09-10 14:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-10 14:50 Eric [this message]
2008-09-10 20:59 ` Multiline Font Lock Lennart Borgman (gmail)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6df65b1-b6c3-46ae-8aea-0ab50b16e9e6@k7g2000hsd.googlegroups.com \
--to=etklaus@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.