Skip to content

Instantly share code, notes, and snippets.

@tlync
Created May 11, 2011 08:50
Show Gist options
  • Save tlync/966133 to your computer and use it in GitHub Desktop.
Save tlync/966133 to your computer and use it in GitHub Desktop.
;;; 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 "~/Dropbox/Tools/js-beautify/python/jsbeautifier.py"
"Path to jsbeautifier python file"
:type '(string)
:group 'js-beautify)
(defun js-beautify-region ()
"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)))
(defun js-beautify-buffer ()
"Beautify the buffer using the code from jsbeautify.org"
(interactive)
(let ((orig-point (point)))
(setq command (concat "python " js-beautify-path " --stdin " js-beautify-args))
(shell-command-on-region (point-min) (point-max) command nil t)
(goto-char orig-point)))
(provide 'js-beautify)
;;; js-beautify.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment