From: bmaron2@hotmail.com
To: help-gnu-emacs@gnu.org
Subject: Re: font-lock and multiline comments
Date: 9 Feb 2007 12:45:18 -0800 [thread overview]
Message-ID: <1171053918.087543.102250@v33g2000cwv.googlegroups.com> (raw)
In-Reply-To: <jwv4ppvxeur.fsf-monnier+gnu.emacs.help@gnu.org>
On Feb 9, 3:28 pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> > I am writing a new major mode for an in-house programming language.
> > We'd like to have emacs do syntactic highlighting on the comments. The
> > language supports two kinds of comments:
> > // In-line C++ style comments
> > Comments
> > Multi-line comments flagged by Comments/EndComments
> > Here is another line
> > EndComments
> > The in-line style I was able to easily add with a syntax table
> > modification. The multi-line comments, however, I can't do because the
> > syntax tables only support comment syntax with 1 or 2 characters.
> > I then turned to font-lock mode. Adding the following font-lock
> > keyword didn't work if there were more than maybe 7 or 8 lines between
> > Comments and EndComments:
> > '("^[ \t]*Comments\\(.\\|\n\\)*EndComments" . font-lock-comment-face)
> > Apparently font-lock regions aren't designed to span multiple lines?
> > Can someone tell me how to get font-lock to recognize and properly
> > mark these multi-line comments?
>
> Use `font-lock-syntactic-keywords' along the lines of
>
> (defvar foo-font-lock-syntactic-keywords
> '(("^Comments\\(\n\\)" (1 "< b"))
> ("EndComments$"
> (0 (unless (eq (match-beginning 0) (point-min))
> (put-text-property (1- (match-beginning 0)) (match-beginning 0)
> 'syntax-table (eval-when-compile
> (string-to-syntax "> b")))
> (put-text-property (1- (match-beginning 0)) (match-end 0)
> 'font-lock-multiline t)
> nil)))))
>
> and then set font-lock-defaults to
>
> (foo-font-lock-keywords ...blablabla...
> (font-lock-syntactic-keywords . foo-font-lock-syntactic-keywords))
>
> See the docstring of font-lock-defaults to see how many entries to place
> before the f-l-s-k one.
>
> Note that it will not work correctly for
>
> Comments
> EndComments
>
> :-(
>
> Stefan
Dear Stefan,
That worked perfectly. Thanks for the expert (and prompt) advice!
prev parent reply other threads:[~2007-02-09 20:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-09 20:14 font-lock and multiline comments bmaron2
2007-02-09 20:28 ` Stefan Monnier
2007-02-09 20:45 ` bmaron2 [this message]
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=1171053918.087543.102250@v33g2000cwv.googlegroups.com \
--to=bmaron2@hotmail.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.