Subject: Re: bug#31972: 27.0.50; syntax-ppss depth incorrect after font-lock syntax-alist

From: Noam Postavsky <[email-masked]>
Date: Mon, 25 Jun 2018 19:59:22 -0400

tags 31972 + notabug
quit

Brady Trainor <[email-masked]> writes:

> (define-derived-mode dart-mode prog-mode "Dart"
>   ""
>   (setq comment-start "//")
>   (setq comment-end "")
>   (setq font-lock-defaults '(nil nil nil ((?/ . "_ 12")
>                                           (?\n . ">"))))
>   ;; (modify-syntax-entry ?/ "_ 12")
>   ;; (modify-syntax-entry ?\n ">")
>   )

> I open a file and `M-x dart-mode RET`, with contents say
>
> // A comment (with a parenthesized
> // note).
>
> Then with point on beginning of second line, I try `M-: (car
> (syntax-ppss)) RET` and find that depth is reported as 1, rather than 0.
> If I comment out the `font-lock-defaults` expression and instead use
> `modify-syntax-entry` expressions, I get depth 0 throughout.

That looks all correct to me.  In the first case, the "//" doesn't start
a comment, it's only fontified as if it starts a comment.  So of course
when you're inside a paren you'll see depth 1.  In the second case, you
set "//" as a comment start, so you see depth 0.

I think you want

(define-derived-mode dart-mode prog-mode "Dart"
  ""
  (setq comment-start "//")
  (setq comment-end "")
  (setq font-lock-defaults '(nil nil nil nil)) ; Same as '(nil).
  (modify-syntax-entry ?/ "_ 12")
  (modify-syntax-entry ?\n ">"))