-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-beautify.el
32 lines (27 loc) · 1009 Bytes
/
js-beautify.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;; 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 --indent-size=2"
"Arguments to pass to jsbeautify script"
:type '(string)
:group 'js-beautify)
(defcustom js-beautify-path "~/.nvm/versions/node/v12.18.0/bin/js-beautify"
"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 js-beautify-path
" --file=- "
js-beautify-args)
nil t)
(goto-char orig-point)))
(provide 'js-beautify)
;;; js-beautify.el ends here