From 59c95e7da222be701200087ca221b86813d832cf Mon Sep 17 00:00:00 2001 From: Tommy Groshong Date: Wed, 9 Oct 2019 11:26:12 -0400 Subject: [PATCH] Make react layer respect js fmt on save The react layer relies on the javascript layer and uses multiple values from it including definition of a formatter. However, the react layer does not respect the javascript layer setting for formatting a file on save. This patch configures the react layer to add a before save hook that calls the javascript layer formatting function when the 'javascript-fmt-on-save variable is enabled. --- CHANGELOG.develop | 2 ++ layers/+frameworks/react/funcs.el | 4 ++++ layers/+frameworks/react/packages.el | 3 +++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index b6d4983fd..528dad907 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -2441,6 +2441,8 @@ Other: - Configure =emmet-mode= to expand classes using =className= instead of =class= (thanks to Sylvain Benner) - Open =.jsx= files with =rjsx-mode= (thanks to Thomas de BeauchĂȘne) + - Made =react= layer respect =javascript= layers variable + =javascript-fmt-on-save= (thanks to Tommy Groshong) - Key bindings: - Added =import-js= support with key bindings: - ~SPC m i i~ to mport the module for the variable under the cursor diff --git a/layers/+frameworks/react/funcs.el b/layers/+frameworks/react/funcs.el index 57359a314..0f18a10b0 100644 --- a/layers/+frameworks/react/funcs.el +++ b/layers/+frameworks/react/funcs.el @@ -81,3 +81,7 @@ If optional argument P is present, test this instead of point." (defun spacemacs//react-setup-yasnippet () (yas-activate-extra-mode 'js-mode)) + +;; Format +(defun spacemacs/react-fmt-before-save-hook () + (add-hook 'before-save-hook 'spacemacs/javascript-format t t)) diff --git a/layers/+frameworks/react/packages.el b/layers/+frameworks/react/packages.el index 1b0224fa2..e2b596c8a 100644 --- a/layers/+frameworks/react/packages.el +++ b/layers/+frameworks/react/packages.el @@ -72,6 +72,9 @@ (add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-setup-backend) ;; set next-error-function to nil because we use flycheck (add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-setup-next-error-fn) + ;; setup fmt on save + (when javascript-fmt-on-save + (add-hook 'rjsx-mode-local-vars-hook 'spacemacs/react-fmt-before-save-hook)) :config ;; declare prefix