Fix commenting JS in web-mode

This commit is contained in:
Henrik Lissner 2020-02-19 19:03:46 -05:00
parent 4b8986cac4
commit 1ab9f8b99d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -63,6 +63,27 @@
(add-to-list 'web-mode-engines-alist '("elixir" . "\\.eex\\'"))
(let ((types '("javascript" "jsx")))
(setq web-mode-comment-formats
(cl-remove-if (lambda (item) (member (car item) types))
web-mode-comment-formats))
(dolist (type types)
(push (cons type "//") web-mode-comment-formats)))
(add-hook! 'web-mode-hook
(defun +web--fix-js-comments-h ()
"Fix comment handling in `web-mode' for JavaScript."
(when (member web-mode-content-type '("javascript" "jsx"))
;; For some reason the default is to insert HTML comments even
;; in JavaScript.
(setq-local comment-start "//")
(setq-local comment-end "")
;; Needed since otherwise the default value generated by
;; `comment-normalize-vars' will key off the syntax and think
;; that a single "/" starts a comment, which completely borks
;; auto-fill.
(setq-local comment-start-skip "// *"))))
(map! :map web-mode-map
(:localleader
:desc "Rehighlight buffer" "h" #'web-mode-buffer-highlight