Adding format on save to javascript layer.
Adding formatting on save option to javascript layer, similar to typescript layer. One small syntax error fix in typescript layer.
This commit is contained in:
parent
785c155ca1
commit
9665670f8e
|
@ -1546,6 +1546,7 @@ Other:
|
||||||
- Added ES6 module extension to =init-js2-mode= (thanks to Nathan Lloyd)
|
- Added ES6 module extension to =init-js2-mode= (thanks to Nathan Lloyd)
|
||||||
- Added =org-babel= support (thanks to Michael Rohleder)
|
- Added =org-babel= support (thanks to Michael Rohleder)
|
||||||
- Added debug support via =dap= layer (Firefox and Google Chrome)
|
- Added debug support via =dap= layer (Firefox and Google Chrome)
|
||||||
|
- Added format on save option. (thanks to Trapez Breen)
|
||||||
- Key bindings
|
- Key bindings
|
||||||
- Improved coffeescript support:
|
- Improved coffeescript support:
|
||||||
- ~SPC m '~ to create or go to REPL
|
- ~SPC m '~ to create or go to REPL
|
||||||
|
|
|
@ -118,6 +118,16 @@ Formatter can be chosen on a per project basis using directory local variables
|
||||||
|
|
||||||
*Note:* you can easily add a directory local variable with ~SPC f v d~.
|
*Note:* you can easily add a directory local variable with ~SPC f v d~.
|
||||||
|
|
||||||
|
You can choose formatting tool:
|
||||||
|
|
||||||
|
#+BEGIN_SRC elisp
|
||||||
|
(setq-default dotspacemacs-configuration-layers '(
|
||||||
|
(javascript :variables
|
||||||
|
javascript-fmt-tool 'prettier)))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Default is =’web-beautify=.
|
||||||
|
|
||||||
* Backends
|
* Backends
|
||||||
** Tern
|
** Tern
|
||||||
See [[file:../../+tools/tern/README.org][tern layer]] documentation.
|
See [[file:../../+tools/tern/README.org][tern layer]] documentation.
|
||||||
|
|
|
@ -21,3 +21,6 @@
|
||||||
|
|
||||||
(defvar javascript-import-tool nil
|
(defvar javascript-import-tool nil
|
||||||
"The import backend to import modules. Possible values are `import-js' and `nil' to disable.")
|
"The import backend to import modules. Possible values are `import-js' and `nil' to disable.")
|
||||||
|
|
||||||
|
(defvar javascript-fmt-on-save nil
|
||||||
|
"Run formatter on buffer save.")
|
||||||
|
|
|
@ -130,3 +130,21 @@
|
||||||
(spacemacs/skewer-eval-region beg end)
|
(spacemacs/skewer-eval-region beg end)
|
||||||
(skewer-repl)
|
(skewer-repl)
|
||||||
(evil-insert-state))
|
(evil-insert-state))
|
||||||
|
|
||||||
|
|
||||||
|
;; Others
|
||||||
|
|
||||||
|
(defun spacemacs/javascript-format ()
|
||||||
|
"Call formatting tool specified in `javascript-fmt-tool'."
|
||||||
|
(interactive)
|
||||||
|
(cond
|
||||||
|
((eq javascript-fmt-tool 'prettier)
|
||||||
|
(call-interactively 'prettier-js))
|
||||||
|
((eq javascript-fmt-tool 'web-beautify)
|
||||||
|
(call-interactively 'web-beautify-js))
|
||||||
|
(t (error (concat "%s isn't valid javascript-fmt-tool value."
|
||||||
|
" It should be 'web-beutify or 'prettier.")
|
||||||
|
(symbol-name javascript-fmt-tool)))))
|
||||||
|
|
||||||
|
(defun spacemacs/javascript-fmt-before-save-hook ()
|
||||||
|
(add-hook 'before-save-hook 'spacemacs/javascript-format t t))
|
||||||
|
|
|
@ -84,6 +84,8 @@
|
||||||
(cons 'javascript-backend value))))
|
(cons 'javascript-backend value))))
|
||||||
:config
|
:config
|
||||||
(progn
|
(progn
|
||||||
|
(when javascript-fmt-on-save
|
||||||
|
(add-hook 'js2-mode-local-vars-hook 'spacemacs/javascript-fmt-before-save-hook))
|
||||||
;; prefixes
|
;; prefixes
|
||||||
(spacemacs/declare-prefix-for-mode 'js2-mode "mh" "documentation")
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mh" "documentation")
|
||||||
(spacemacs/declare-prefix-for-mode 'js2-mode "mg" "goto")
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mg" "goto")
|
||||||
|
|
|
@ -131,8 +131,8 @@
|
||||||
((eq typescript-fmt-tool 'prettier)
|
((eq typescript-fmt-tool 'prettier)
|
||||||
(call-interactively 'prettier-js))
|
(call-interactively 'prettier-js))
|
||||||
(t (error (concat "%s isn't valid typescript-fmt-tool value."
|
(t (error (concat "%s isn't valid typescript-fmt-tool value."
|
||||||
" It should be 'tide, 'typescript-formatter or 'prettier."
|
" It should be 'tide, 'typescript-formatter or 'prettier.")
|
||||||
(symbol-name typescript-fmt-tool))))))
|
(symbol-name typescript-fmt-tool)))))
|
||||||
|
|
||||||
(defun spacemacs/typescript-fmt-before-save-hook ()
|
(defun spacemacs/typescript-fmt-before-save-hook ()
|
||||||
(add-hook 'before-save-hook 'spacemacs/typescript-format t t))
|
(add-hook 'before-save-hook 'spacemacs/typescript-format t t))
|
||||||
|
|
Loading…
Reference in a new issue