unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: highlighting large regions (comments) with font-lock keywords
Date: Tue, 27 Sep 2011 21:30:43 -0400	[thread overview]
Message-ID: <jwvaa9p4ful.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <871uv17nar.fsf@gmail.com> (Eric Schulte's message of "Tue, 27 Sep 2011 14:17:16 -0600")

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

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)
       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'?).


        Stefan



  reply	other threads:[~2011-09-28  1:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-27 20:17 highlighting large regions (comments) with font-lock keywords Eric Schulte
2011-09-28  1:30 ` Stefan Monnier [this message]
2011-09-28 13:08   ` Eric Schulte
2011-09-28 14:18 ` Djvu mode Camm Maguire
2011-09-28 16:50   ` Sivaram Neelakantan
2011-09-29 16:07     ` gnu-emacs-sources down? [was: Djvu mode] Roland Winkler
2011-09-29 16:21       ` gnu-emacs-sources down? Glenn Morris
2011-09-29 17:39       ` gnu-emacs-sources down? [was: Djvu mode] Sivaram Neelakantan
     [not found]       ` <87r52zl29j.fsf_-_@maguirefamily.org>
     [not found]         ` <20100.46983.768447.889306@gargle.gargle.HOWL>
     [not found]           ` <87d3ejgmmz.fsf@maguirefamily.org>
     [not found]             ` <20103.17789.10053.53615@gargle.gargle.HOWL>
2011-10-02  4:22               ` Djvu mode Camm Maguire
2011-10-03 18:23                 ` Roland Winkler
2011-10-03 19:41                   ` Camm Maguire
2011-10-03 19:59                   ` Camm Maguire
2011-10-03 20:35                   ` Camm Maguire
2011-10-04  6:20                     ` Roland Winkler
2011-10-12 15:19                       ` Camm Maguire
2011-10-14 12:52                         ` Roland Winkler
2011-10-04 10:21                     ` Roland Winkler
2011-09-28 21:02   ` Stefan Monnier
2011-09-29  6:26   ` Roland Winkler
2011-09-29  9:08     ` joakim
2011-09-29 19:07       ` Roland Winkler
2011-09-29 20:06         ` Camm Maguire
2011-09-29 21:34         ` joakim
2011-10-01 17:01           ` Roland Winkler
2011-10-01 17:19             ` joakim
2011-10-01 18:04               ` Roland Winkler

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvaa9p4ful.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=schulte.eric@gmail.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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