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

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

Re: font-lock and multiline comments


From: bmaron2
Subject: Re: font-lock and multiline comments
Date: 9 Feb 2007 12:45:18 -0800
User-agent: G2/1.0

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!



reply via email to

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