我试图在 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大量借用