Created
September 19, 2011 12:11
-
-
Save alfredo/1226378 to your computer and use it in GitHub Desktop.
JavaScript with Google Closure on emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get google closure compiler to evaluate your javascript code on your emacs | |
-------------------------------------------------------------------------- | |
- Download the google closure compiler, unzip it and place ``compiler.jar`` somewhere accessible | |
(e.g. ``~/bin/compiler.jar``):: | |
http://closure-compiler.googlecode.com/files/compiler-latest.zip | |
- Create a shell script to run closure on a file (e.g. closure.sh):: | |
!#/bin/bash | |
java -jar ~/bin/compiler.jar --warning_level VERBOSE --js $1 --js_output_file /dev/null | |
- Add the following to your emacs config make sure you edit the filename to match the name of the | |
previous script (closure.sh in this case) and it is available on the PATH of your system:: | |
(when (load "flymake" t) | |
(defun flymake-closure-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 "closure.sh" (list local-file)))) | |
(add-to-list 'flymake-allowed-file-name-masks | |
'("\\.js\\'" flymake-closure-init))) | |
- Add flymake to your javascript mode hook:: | |
(add-hook 'javascript-mode-hook | |
(lambda () (flymake-mode t))) | |
- Get some javascript done, and the compiler will warn you if something is not quite right. | |
Bonus points: | |
- To show what the warning or the error is about on the mode line you will need ``flymake-cursor``:: | |
(load-library "flymake-cursor") | |
- To change the appearance of the errors and warnings, you can underline as well ``:underline "#ff0000"``:: | |
(custom-set-faces | |
'(flymake-errline ((((class color)) (:background "#ffffd7")))) | |
'(flymake-warnline ((((class color)) (:background "#0a2832"))))) | |
References:: | |
Originally from: "http://www.emacswiki.org/emacs/FlyMake#toc9 | |
Closure compiler: http://code.google.com/closure/compiler/docs/gettingstarted_app.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment