Created
November 23, 2010 19:51
-
-
Save slackorama/712405 to your computer and use it in GitHub Desktop.
beautify some js code in emacs
This file contains hidden or 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
| ;;; js-beautify.el -- beautify some js code | |
| (defgroup js-beautify nil | |
| "Use jsbeautify to beautify some js" | |
| :group 'editing) | |
| (defcustom js-beautify-args "--jslint-happy --brace-style=end-expand --keep-array-indentation" | |
| "Arguments to pass to jsbeautify script" | |
| :type '(string) | |
| :group 'js-beautify) | |
| (defcustom js-beautify-path "~/projects/js-beautify/python/jsbeautifier.py" | |
| "Path to jsbeautifier python file" | |
| :type '(string) | |
| :group 'js-beautify) | |
| (defun js-beautify () | |
| "Beautify a region of javascript using the code from jsbeautify.org" | |
| (interactive) | |
| (let ((orig-point (point))) | |
| (unless (mark) | |
| (mark-defun)) | |
| (shell-command-on-region (point) | |
| (mark) | |
| (concat "python " | |
| js-beautify-path | |
| " --stdin " | |
| js-beautify-args) | |
| nil t) | |
| (goto-char orig-point))) | |
| (provide 'js-beautify) | |
| ;;; js-beautify.el ends here |
Author
Thanks! I just updated to use the python version.
Author
Shameless plug: http://sethmason.com/2011/04/28/jsbeautify-in-emacs.html
correct link : https://sethmason.com/2011/04/28/beautify-your-javascript-in-emacs.html
Author
@yashasolutions Thanks! Updated my comment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for putting this out there. I added to this a bit (checked in also):
;;; js-beautify.el -- beautify some js code (defcustom rhino-jar "~/software/rhino1_7R" "Location of the rhino jar e.g. rhino1_7R2" :type '(string) :group 'data) (defcustom beautify-dir "~/software/js-beautify" "Location of the js-beautify directory e.g. ~/software/js-beautify" :type '(string) :group 'data) (defun js-beautify-region () "Beautify a region of javascript using the code from jsbeautify.org. If you don't have a region selected, the code will go from the cursor to the end of the line." (interactive) (let ((orig-point (point))) (setq endm 0) (if mark-active (setq endm (mark)) (setq endm (point-at-eol)) ) (setq command (concatenate 'string "java -jar " rhino-jar "/js.jar " beautify-dir "/beautify-cl.js -i 4 -p -d " beautify-dir )) (shell-command-on-region (point) endm command nil t) (goto-char orig-point))) (defun js-beautify-buffer () "Beautify the buffer using the code from jsbeautify.org" (interactive) (let ((orig-point (point))) (setq command (concatenate 'string "java -jar " rhino-jar "/js.jar " beautify-dir "/beautify-cl.js -i 4 -p -d " beautify-dir )) (shell-command-on-region (point-min) (point-max) command nil t) (goto-char orig-point))) (provide 'js-beautify)