[Top][All Lists]

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

Re: highlighting large regions (comments) with font-lock keywords

From: Stefan Monnier
Subject: Re: highlighting large regions (comments) with font-lock keywords
Date: Tue, 27 Sep 2011 21:30:43 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> I'm working on a major mode for a new language [1] which comments
> regions between \* ... *\.  I've properly (I believe) instantiated
> font-lock keywords, and I have added a function to the
> `font-lock-extend-region-functions' list to ensure that both ends of a
> comment are always considered at the same time but unfortunately comment
> highlighting often does not work.

> Specifically, when I first enter a buffer and right after calling
> `shen-mode' all comments are properly highlighted, however as I edit and
> navigate in the buffer larger comments often lose fontification.

Let's see:

   (defun shen-font-lock-extend-region-comment ()
     "Move fontification boundaries to contain whole comments."
     (let ((changed nil))
       (goto-char font-lock-beg)
       (when (and (re-search-forward "\\\\\\*" font-lock-end t)
                  (< (match-beginning 0) font-lock-beg))
         (setq font-lock-beg (match-beginning 0)
               changed t)
         (when (and (re-search-forward "\\*\\\\" nil t)
                    (> (match-end 0) font-lock-end))
           (setq font-lock-end (match-end 0)
                 changed t)))

We have an obvious problem here: after (goto-char font-lock-beg) we're
at font-lock-beg, and after (re-search-forward "\\\\\\*" font-lock-end
t), we can only be further, so (match-beginning 0) will never be
< font-lock-beg.

BTW, why not simply do:

   (defvar shen-mode-syntax-table
     (let ((table (make-syntax-table)))
       (modify-syntax-entry ?- "w" table)
       (modify-syntax-entry ?\\ ". 14" table)
       (modify-syntax-entry ?* ". 23" table)
       (modify-syntax-entry ?? "w" table)
       (modify-syntax-entry ?< "w" table)
       (modify-syntax-entry ?> "w" table)
     "Syntax table to use in shen-mode.")

Oh, and I haven't looked any other part of the code, but just happened
to see:

  (add-to-list 'font-lock-extend-region-functions
               'shen-font-lock-extend-region-comment t))

Where the `local' arg is nil whereas it should be t (maybe the t was
meant for `local' rather than for `append'?).


reply via email to

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