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

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

Re: modify-syntax-entry with single and two character comments


From: Stefan Monnier
Subject: Re: modify-syntax-entry with single and two character comments
Date: Wed, 27 Oct 2004 19:11:26 GMT
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux)

>      (modify-syntax-entry ?\n ">" st)
>      (modify-syntax-entry ?\| "<1b4b" st)
>      (modify-syntax-entry ?\* ".2b3b" st)

The syntax string has the following structure:
- 1st char is the main syntax category.
- 2nd char is only used for ( and ) categories.
- the rest are flags with no ordering.

I.e. in your above code the "<1b4b" is equivalent to "< b4b" because the
`1' is ignored.  It's also equivalent to "< 4bb" (because ordering of
flags is ignored) which is equivalent to "< 4b" (because turning ON a flag
twice is the same as turning it ON once).

A correct syntax-table would be:

      (modify-syntax-entry ?\n ">" st)
      (modify-syntax-entry ?\| "< 14" st)
      (modify-syntax-entry ?\* ". 23b" st)

which says:
- | starts a non-b comment and \n ends such a non-b comment.
- | can be the 1nd char of a 2-char comment-starter or the 2nd char of
  a 2-char comment-ender.
- * can be the 2nd char of a 2-char b-style comment-starter or the 3rd char
  of a 2-char b-style comment-ender.

Sadly, this will not work because current Emacsen will immediately think
that | starts the comment without checking the subsequent char to see if
it's a *.

Please report a bug via M-x report-emacs-bug about it.

To work around this problem, two solutions:

1 - use "| " instead of "|" as the non-b comment-starter:

      (modify-syntax-entry ?\n ">" st)
      (modify-syntax-entry ?\| ". 14" st)
      (modify-syntax-entry ?\* ". 23b" st)
      (modify-syntax-entry ?\  "  2" st)

    Any char that can reasonably be expected to appear after a |
    comment-starter should then have the `2' flag added to its syntax :-(

2 - use font-lock-syntactic-keywords to change the syntax of | when it is
    followed by a *.  This is less intrusive but will only work when
    font-lock is used and has been applied to the text.


-- Stefan


reply via email to

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