我在Emacs25.2上启用了js2模式和flycheck/eslint。
当前按tab (或换行符)将按照js2-mode-js- indent -level进行缩进。
我希望它是动态的,以匹配flycheck/eslint设置
有没有办法做到这一点?
发布于 2018-05-31 20:20:57
Emacs已经提供了解析配置(本例中为eslint配置)的工具。
解析配置并将缩进配置设置为js-indent-level
(defun js2-mode-use-eslint-indent ()
(let ((json-object-type 'hash-table)
(json-config (shell-command-to-string (format "eslint --print-config %s"
(shell-quote-argument
(buffer-file-name))))))
(ignore-errors
(setq js-indent-level
(aref (gethash "indent" (gethash "rules" (json-read-from-string json-config))) 1)))))
(add-hook 'js2-mode-hook #'js2-mode-use-eslint-indent)https://stackoverflow.com/questions/48733723
复制相似问题