2018-04-26 19:43:50 +00:00
|
|
|
;;; packages.el --- react layer packages file for Spacemacs. -*- lexical-binding: t -*-
|
2015-07-24 20:07:03 +00:00
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2015-07-24 20:07:03 +00:00
|
|
|
;;
|
|
|
|
;; Author: Andrea Moretti <axyzxp@gmail.com>
|
|
|
|
;; URL: https://github.com/axyz
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-07-24 20:07:03 +00:00
|
|
|
|
2018-04-26 19:43:50 +00:00
|
|
|
(defconst react-packages
|
|
|
|
'(
|
|
|
|
add-node-modules-path
|
|
|
|
company
|
|
|
|
emmet-mode
|
|
|
|
evil-matchit
|
|
|
|
flycheck
|
2018-06-05 05:57:25 +00:00
|
|
|
import-js
|
2018-04-26 19:43:50 +00:00
|
|
|
js-doc
|
2018-06-19 06:25:33 +00:00
|
|
|
prettier-js
|
2018-04-26 19:43:50 +00:00
|
|
|
rjsx-mode
|
|
|
|
smartparens
|
2018-05-18 04:16:43 +00:00
|
|
|
tern
|
2018-04-26 19:43:50 +00:00
|
|
|
web-beautify
|
2021-03-16 17:47:15 +00:00
|
|
|
yasnippet))
|
|
|
|
|
2015-07-24 20:07:03 +00:00
|
|
|
|
2018-04-26 19:43:50 +00:00
|
|
|
(defun react/post-init-add-node-modules-path ()
|
|
|
|
(add-hook 'rjsx-mode-hook #'add-node-modules-path))
|
|
|
|
|
|
|
|
(defun react/post-init-company ()
|
|
|
|
(add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-setup-company))
|
2015-07-24 20:07:03 +00:00
|
|
|
|
2016-10-10 01:44:35 +00:00
|
|
|
(defun react/post-init-emmet-mode ()
|
2018-05-19 05:15:04 +00:00
|
|
|
(add-hook 'rjsx-mode-hook 'spacemacs/react-emmet-mode))
|
2016-10-03 21:54:21 +00:00
|
|
|
|
2016-02-28 08:15:24 +00:00
|
|
|
(defun react/post-init-evil-matchit ()
|
2019-02-05 21:26:50 +00:00
|
|
|
(add-hook 'rjsx-mode-hook 'turn-on-evil-matchit-mode))
|
2016-02-28 08:15:24 +00:00
|
|
|
|
2015-08-26 00:57:56 +00:00
|
|
|
(defun react/post-init-flycheck ()
|
2016-04-21 08:42:22 +00:00
|
|
|
(with-eval-after-load 'flycheck
|
2016-06-05 08:08:41 +00:00
|
|
|
(dolist (checker '(javascript-eslint javascript-standard))
|
2018-04-26 19:43:50 +00:00
|
|
|
(flycheck-add-mode checker 'rjsx-mode)))
|
2019-11-11 08:17:31 +00:00
|
|
|
(spacemacs/enable-flycheck 'rjsx-mode)
|
|
|
|
(add-hook 'rjsx-mode-hook #'spacemacs//javascript-setup-checkers 'append))
|
2015-07-27 22:26:47 +00:00
|
|
|
|
2019-04-13 01:59:47 +00:00
|
|
|
(defun react/pre-init-import-js ()
|
2019-05-12 14:01:05 +00:00
|
|
|
(when (eq javascript-import-tool 'import-js)
|
2019-04-13 01:59:47 +00:00
|
|
|
(add-to-list 'spacemacs--import-js-modes (cons 'rjsx-mode 'rjsx-mode-hook))))
|
2018-06-05 05:57:25 +00:00
|
|
|
|
2015-08-26 00:57:56 +00:00
|
|
|
(defun react/post-init-js-doc ()
|
2018-04-26 19:43:50 +00:00
|
|
|
(add-hook 'rjsx-mode-hook 'spacemacs/js-doc-require)
|
|
|
|
(spacemacs/js-doc-set-key-bindings 'rjsx-mode))
|
|
|
|
|
|
|
|
(defun react/init-rjsx-mode ()
|
|
|
|
(use-package rjsx-mode
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
|
2021-03-18 03:29:20 +00:00
|
|
|
(add-to-list 'magic-mode-alist (cons #'spacemacs//javascript-jsx-file-p 'rjsx-mode))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
|
|
;; setup rjsx backend
|
|
|
|
(add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-setup-backend)
|
2019-04-13 07:12:06 +00:00
|
|
|
;; set next-error-function to nil because we use flycheck
|
|
|
|
(add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-setup-next-error-fn)
|
2019-10-09 15:26:12 +00:00
|
|
|
;; setup fmt on save
|
|
|
|
(when javascript-fmt-on-save
|
2019-11-22 19:54:19 +00:00
|
|
|
(add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-fmt-before-save-hook))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
2020-11-23 18:59:01 +00:00
|
|
|
;; set the javascript layers keymap as parent to the react layers keymap
|
|
|
|
(set-keymap-parent spacemacs-rjsx-mode-map spacemacs-js2-mode-map)
|
|
|
|
|
2018-04-26 19:43:50 +00:00
|
|
|
:config
|
2020-11-23 18:59:01 +00:00
|
|
|
;; declare prefixes
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "m=" "format")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mT" "toggle")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "me" "eval")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mg" "goto")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mh" "documentation")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mr" "refactor")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mr3" "ternary")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mra" "add/args")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrb" "barf")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrc" "contract")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mre" "expand/extract")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mri" "inline/inject/introduct")
|
2020-04-10 17:30:03 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrl" "localize/log")
|
2018-04-26 19:43:50 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrr" "rename")
|
2020-11-23 18:59:01 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrs" "split/slurp")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrt" "toggle")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mru" "unwrap")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrv" "var")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrw" "wrap")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "ms" "skewer")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mx" "text")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mxm" "move")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mz" "folding")
|
2018-04-26 19:43:50 +00:00
|
|
|
|
2020-04-10 17:30:03 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'rjsx-mode "rlt" 'js2r-log-this)
|
2019-02-05 21:26:50 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'rjsx-mode "rt" 'rjsx-rename-tag-at-point)
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
|
|
(with-eval-after-load 'rjsx-mode
|
|
|
|
(define-key rjsx-mode-map (kbd "C-d") nil))))
|
2015-07-27 22:26:47 +00:00
|
|
|
|
2018-06-19 06:25:33 +00:00
|
|
|
(defun react/pre-init-prettier-js ()
|
2019-05-12 14:01:05 +00:00
|
|
|
(when (eq javascript-fmt-tool 'prettier)
|
|
|
|
(add-to-list 'spacemacs--prettier-modes 'rjsx-mode)))
|
2018-06-19 06:25:33 +00:00
|
|
|
|
2018-03-04 04:37:53 +00:00
|
|
|
(defun react/post-init-smartparens ()
|
2021-03-16 17:47:15 +00:00
|
|
|
(add-hook 'rjsx-mode-hook #'spacemacs//activate-smartparens))
|
2016-04-21 14:35:28 +00:00
|
|
|
|
2018-05-18 04:16:43 +00:00
|
|
|
(defun react/post-init-tern ()
|
|
|
|
(add-to-list 'tern--key-bindings-modes 'rjsx-mode))
|
|
|
|
|
2018-05-19 05:53:33 +00:00
|
|
|
(defun react/pre-init-web-beautify ()
|
2019-05-12 14:01:05 +00:00
|
|
|
(when (eq javascript-fmt-tool 'web-beautify)
|
|
|
|
(add-to-list 'spacemacs--web-beautify-modes
|
|
|
|
(cons 'rjsx-mode 'web-beautify-js))))
|
2018-06-02 00:34:48 +00:00
|
|
|
|
|
|
|
(defun react/post-init-yasnippet ()
|
|
|
|
(add-hook 'rjsx-mode-hook #'spacemacs//react-setup-yasnippet))
|