问题
How can I treat the a shebang line of the form
#! /usr/bin/env node
As a comment line, when using js2-mode
? I've tried a couple things, one as a modification of something Stefan proposed on another thread (can't find it now), eg. a modification to the syntax-propertize-rules
,
(defalias 'my-js2-syntax-propertize-shebang
(syntax-propertize-rules
("\\`\\(#\\)!.*/[^ \t\n]+" (1 "!"))))
(defun my-js2-hook ()
(add-function :before (local 'syntax-propertize-rules)
#'my-js2-syntax-propertize-shebang))
Which doesn't seem to have any effect. so, I just added another regex via font-lock-add-keywords
, eg.
(defun my-js2-font-lock-additions ()
(font-lock-add-keywords
nil
'(("\\`\\(#!\\s-*.*/[^ \t\n]+\\)\\s-*\\([^ \t\n]+\\)\\s-*$"
(1 font-lock-comment-face t)
(2 font-lock-type-face t))))
(font-lock-flush)
(font-lock-ensure))
Which does result in the shebang line being fontified, but the js2-mode
parser still tries to parse it, treats it as errors, and adds the relevant overlays. How can I tell js2-mode
to ignore that line, or do something like mark it as external to the AST/buffer or something?
来源:https://stackoverflow.com/questions/60592024/font-lock-and-disable-js2-mode-parsing-node-shebang-line