尝试在Web模式下设置内容类型时出现此错误:File mode specification error: (invalid-regexp Trailing backslash)
我很难调试这个。我是emacs的新手,所以我需要一些设置web模式的帮助。我一直在关注web-mode.org中的文档,但是很难让decypher。谢谢。
(use-package
web-mode
:defer 2
:ensure t
:mode ("\\.html?\\"
"\\.hbs$\\"
"\\.vue$\\"
"\\.css?\\"
"components/.*\\.js[x]?\\'"
"containers/.*\\.js[x]?\\'")
:config (progn
(setq web-mode-enable-auto-closing t
web-mode-enable-auto-opening t
web-mode-enable-auto-pairing t
web-mode-enable-auto-indentation t
web-mode-enable-auto-quoting t
;; right now paired with AutoComplete
web-mode-ac-sources-alist
'(("css" . (ac-source-css-property))
("vue" . (ac-source-words-in-buffer ac-source-abbrev))
("html" . (ac-source-words-in-buffer ac-source-abbrev)))
web-mode-content-types-alist
'(("jsx" . "components/.*\\.js[x]?\\'")
("jsx" . "containers/.*\\.js[x]?\\'")))))
;; usually I set them in containers/ or components/ directorie
;; and to keep seperate from plain JS
;; adjust indents for web-mode to 2 spaces
(defun my-web-mode-hook ()
"Hooks for Web mode. Adjust indents"
;;; http://web-mode.org/
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2))
(add-hook 'web-mode-hook 'my-web-mode-hook)
在:mode
之后的regexp列表中,确保它们都以\\'
结尾。目前其中有两个,但其中四个失去了最后的'
角色。
:mode ("\\.html?\\'"
"\\.hbs$\\'"
"\\.vue$\\'"
"\\.css?\\'"
"components/.*\\.js[x]?\\'"
"containers/.*\\.js[x]?\\'")
\'
是一个特殊的regexp构造,它“匹配空字符串,但只在缓冲区的末尾或匹配的字符串”。