Skip to content

Instantly share code, notes, and snippets.

@davestevens
Created February 25, 2013 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davestevens/5029577 to your computer and use it in GitHub Desktop.
Save davestevens/5029577 to your computer and use it in GitHub Desktop.
Setup jshint in emacs
This seems to run quicker than the jshint-mode example (https://github.com/daleharvey/jshint-mode) as it doesn't set up a node server each time.
1. Install node and get jshint
$ brew install node
$ npm install -g jshint
2. Update PATH to point to Node Packagem Manager bin directory
$ export PATH=$PATH:/usr/local/share/npm/bin
3. Get flymake-cursor (shows warnings/errors in buffer for using terminal)
$ curl http://www.emacswiki.org/emacs/download/flymake-cursor.el > ~/.elisp/flymake-mode.el
4. Update .emacs file
;; jshint
(when (load "flymake" t)
(defun flymake-jshint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "jshint"
(list local-file))
))
(setq flymake-err-line-patterns
(cons '("^.*: line \\([[:digit:]]+\\), col \\([[:digit:]]+\\), \\(.*\\)$"
nil 1 2 3)
flymake-err-line-patterns))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.js\\'" flymake-jshint-init))
(require 'flymake-cursor))
;; Auto load witn javascript file
(add-hook 'js-mode-hook
(lambda ()
(flymake-mode t)
(define-key js-mode-map "\C-c\C-n" 'flymake-goto-next-error)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment