Javascript Emacs自动缩进和flycheck不符合我的要求

时间:2014-09-10 07:58:52

标签: javascript emacs flycheck

我试图在Emacs中获得一个基本的JS IDE,但我无法让一切工作。

我遇到的问题是:
1.如果我按下输入,我没有得到自动缩进 2. Flyckeck没有显示为次要模式

以下是我的.init文件的相关部分。

;JS settings start

(setq js-basic-indent 2)
(setq-default js2-basic-indent 2)

(setq-default js2-basic-offset 2)
(setq-default js2-auto-indent-p t)
(setq-default js2-cleanup-whitespace t)
(setq-default js2-enter-indents-newline t)
(setq-default js2-global-externs "jQuery $")
(setq-default js2-indent-on-enter-key t)
(setq-default js2-mode-indent-ignore-first-tab t)

(setq-default js2-global-externs '("module" "require" "buster" "sinon" "assert" "refute" "setTimeout" "clearTimeout" "setInterval" "clearInterval" "location" "__dirname" "console" "JSON"))

;; We'll let fly do the error parsing...
(setq-default js2-show-parse-errors nil)

;; (autoload 'js2-mode "js2-mode" nil t)
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

;make the word function in to just f
(font-lock-add-keywords
 'js2-mode `(("\\(function *\\)("
             (0 (progn (compose-region (match-beginning 1) (match-end 1) "ƒ")
                       nil)))))

;place warning font around TODO and others
(font-lock-add-keywords 'js2-mode
                        '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\):"
                           1 font-lock-warning-face t)))

;color any defined variables with color-identifiers-mode
(add-hook 'js2-mode-hook 'color-identifiers-mode)

;;Flyckeck for jshint
(require 'flycheck)
(add-hook 'js2-mode-hook
          (lambda () (flymake-mode 1)))

;tern mode active for js mode
(add-hook 'js2-mode-hook (lambda () (tern-mode t)))
; End js settings ////////////////////////////// 

我大量借鉴http://howardabrams.com/projects/dot-files/emacs-javascript.html

1 个答案:

答案 0 :(得分:3)

Flycheck无法正常工作,因为您正在require,但随后尝试启用 Flymake ,这是一种不同的模式。试试这个:

(add-hook 'js2-mode-hook #'flycheck-mode)

如果您想全局启用flycheck-mode(正如作者在下面的评论中所建议的那样),您可以do this instead

(add-hook 'after-init-hook #'global-flycheck-mode)

在版本24.4之前,当按下Enter键时,Emacs中的大多数模式都没有缩进;与C-j绑定的。要将newline-and-indent绑定到输入,请尝试以下操作,修改from EmacsWiki

(add-hook 'js2-mode-hook '(lambda ()
  (local-set-key (kbd "RET") 'newline-and-indent)))