0

Im trying to get a basic JS IDE in Emacs but I just can't get everything to work.

The problems I have is:
1. If I press enter I am not getting auto indent.
2. Flyckeck is not showing up as a minor mode

Below is the relevant part om my .init file.

;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 ////////////////////////////// 

Im borrowing heavily from http://howardabrams.com/projects/dot-files/emacs-javascript.html

user3139545
  • 6,882
  • 13
  • 44
  • 87
  • 1
    Please follow the [installation instructions](http://flycheck.readthedocs.org/en/latest/guide/installation.html) of Flycheck, and take a look at the [Quickstart section](http://flycheck.readthedocs.org/en/latest/guide/quickstart.html). And please don't just copy random code from somewhere without understanding it. That won't get you far… –  Sep 10 '14 at 13:17

1 Answers1

2

Flycheck isn't working because you're requireing it, but then trying to enable Flymake, which is a different mode. Try this instead:

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

If you want to enable flycheck-mode globally (as the author recommends in the comments below), you can do this instead:

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

Prior to version 24.4, most modes in Emacs didn't indent when pressing enter; that was bound to C-j. To bind newline-and-indent to Enter, try something like this, modified from EmacsWiki:

(add-hook 'js2-mode-hook '(lambda ()
  (local-set-key (kbd "RET") 'newline-and-indent)))
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • The recommended way to use Flycheck is to use `(global-flycheck-mode)`, rather than adding `flycheeck-mode` to individual hooks. –  Sep 10 '14 at 13:17
  • Thanks, @lunaryorn, that's what I do myself. I was trying to keep with the spirit of the question, but I've updated my answer to include your recommendation. – ChrisGPT was on strike Sep 10 '14 at 13:23
  • Perfect thanks, Emacs makes so much sense once you hear it from someone experienced but learning from scratch is a pain – user3139545 Sep 10 '14 at 16:16