我在Emacs 25.2上启用了js2-mode和flycheck / eslint。
当前按下制表符(或换行符)将按照js2-mode-js-indent-level缩进。
我希望它能够动态匹配flycheck / eslint设置
有办法做到这一点吗?
答案 0 :(得分:3)
Emacs已经有了解析json
(在这种情况下为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)