Skip to content

Instantly share code, notes, and snippets.

@sishen
Created January 7, 2011 12:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sishen/769416 to your computer and use it in GitHub Desktop.
Save sishen/769416 to your computer and use it in GitHub Desktop.
Emacs Func: Use ~/bin/jslint4java-1.4.4.jar to automatically JSLint the Javascript file
;;; C-x c calls jslint and outputs to the *compilation* buffer.
(setq jslint-wrapper (concat "java -jar " (substitute-in-file-name "$HOME") "/bin/jslint4java-1.4.4.jar "))
(require 'compile)
(add-hook 'javascript-mode-hook
(lambda ()
(set (make-local-variable 'compilation-read-command) nil)
(set (make-local-variable 'compile-command)
(concat jslint-wrapper buffer-file-name))
(local-set-key (kbd "C-x c") 'compile)))
;;;auto check on save of a javascript file
(defun jslint-hook ()
(let* ((filename (buffer-file-name))
(suffix (downcase (file-name-extension filename))))
(if (and filename (string= suffix "js"))
(call-interactively 'compile))))
(add-hook 'after-save-hook 'jslint-hook)
(defun notify-compilation-result(buffer msg)
"Notify that the compilation is finished,
close the *compilation* buffer if the compilation is successful,
and set the focus back to Emacs frame"
(if (string-match "^finished" msg)
(progn
(delete-windows-on buffer)
(tooltip-show "\n Compilation Successful :-) \n "))
(tooltip-show "\n Compilation Failed :-( \n "))
(setq current-frame (car (car (cdr (current-frame-configuration)))))
(select-frame-set-input-focus current-frame))
(add-to-list 'compilation-finish-functions 'notify-compilation-result)
@purcell
Copy link

purcell commented Dec 11, 2012

Also check out https://github.com/purcell/flymake-jslint, which uses flymake to show jslint hints directly in the javascript buffer.

-Steve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment