2

I am trying to get js-mode to highlight a "shebang" (#!/usr/bin/env node) as a comment, but my code is not working. Instead, the entire buffer is colored like a comment. I've read the documentation for modify-syntax-entry carefully but am still not getting anywhere.

I have tried these calls and several similar combinations, but without success:

(modify-syntax-entry ?# "< 1" js-mode-syntax-table)
(modify-syntax-entry ?! "< 2" js-mode-syntax-table)

1 Answer 1

5

Try

(modify-syntax-entry ?# ". 1" js-mode-syntax-table)
(modify-syntax-entry ?! ". 2b" js-mode-syntax-table)

Reference

2
  • This worked! Out of curiosity, what makes this correct and my attempt not? May 4, 2016 at 13:54
  • @Jackson Technically, the only thing you were missing is the b in the second line. The problem was that your comment had a beginning, but no ending. This solution works because the newline character is already set up in js-mode-syntax-table to be a comment end character for comments of type b.
    – nispio
    May 4, 2016 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.