From: Eric Schulte <schulte.eric@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: highlighting large regions (comments) with font-lock keywords
Date: Wed, 28 Sep 2011 07:08:58 -0600 [thread overview]
Message-ID: <87ty7wu4gt.fsf@gmail.com> (raw)
In-Reply-To: jwvaa9p4ful.fsf-monnier+emacs@gnu.org
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 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.")
>
Hi Stefan,
Yes, the syntax-table method is definitely preferable. Simpler and
(more importantly) works reliably.
>
> 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'?).
>
You're right again, I should have made font-lock-extend-region-functions
local before appending to it. Luckily this font-lock-fanciness can be
discarded now thanks to the simple syntax table fix.
Thanks for the help, much appreciated -- Eric
>
>
> Stefan
--
Eric Schulte
http://cs.unm.edu/~eschulte/
next prev parent reply other threads:[~2011-09-28 13:08 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
2011-09-28 13:08 ` Eric Schulte [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ty7wu4gt.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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.