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

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

Multiline Font Lock


From: Eric
Subject: Multiline Font Lock
Date: Wed, 10 Sep 2008 07:50:34 -0700 (PDT)
User-agent: G2/1.0

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))


reply via email to

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