This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+frameworks/react/packages.el

118 lines
4 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- react layer packages file for Spacemacs. -*- lexical-binding: t -*-
;;
2018-01-04 07:00:25 +00:00
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Andrea Moretti <axyzxp@gmail.com>
;; URL: https://github.com/axyz
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defconst react-packages
'(
add-node-modules-path
company
emmet-mode
evil-matchit
flycheck
2018-06-05 05:57:25 +00:00
import-js
js-doc
prettier-js
rjsx-mode
smartparens
tern
tide
web-beautify
yasnippet
))
(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))
2016-10-10 01:44:35 +00:00
(defun react/post-init-emmet-mode ()
(add-hook 'rjsx-mode-hook 'spacemacs/react-emmet-mode))
(defun react/post-init-evil-matchit ()
(add-hook 'rjsx-mode-hook 'turn-on-evil-matchit-mode))
(defun react/post-init-flycheck ()
2016-04-21 08:42:22 +00:00
(with-eval-after-load 'flycheck
(dolist (checker '(javascript-eslint javascript-standard))
(flycheck-add-mode checker 'rjsx-mode)))
(spacemacs/enable-flycheck 'rjsx-mode)
(add-hook 'rjsx-mode-hook #'spacemacs//javascript-setup-checkers 'append))
(defun react/pre-init-import-js ()
(when (eq javascript-import-tool 'import-js)
(add-to-list 'spacemacs--import-js-modes (cons 'rjsx-mode 'rjsx-mode-hook))))
2018-06-05 05:57:25 +00:00
(defun react/post-init-js-doc ()
(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
;; enable rjsx mode by using magic-mode-alist
(defun +javascript-jsx-file-p ()
(and buffer-file-name
2018-07-30 13:45:05 +00:00
(or (equal (file-name-extension buffer-file-name) "js")
(equal (file-name-extension buffer-file-name) "jsx"))
(re-search-forward "\\(^\\s-*import React\\|\\( from \\|require(\\)[\"']react\\)"
magic-mode-regexp-match-limit t)
(progn (goto-char (match-beginning 1))
(not (spacemacs//react-inside-string-or-comment-q)))))
(add-to-list 'magic-mode-alist (cons #'+javascript-jsx-file-p 'rjsx-mode))
;; setup rjsx backend
(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
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mr" "refactor")
2020-04-10 17:30:03 +00:00
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrl" "localize/log")
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mrr" "rename")
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mh" "documentation")
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mg" "goto")
2020-04-10 17:30:03 +00:00
(spacemacs/set-leader-keys-for-major-mode 'rjsx-mode "rlt" 'js2r-log-this)
(spacemacs/set-leader-keys-for-major-mode 'rjsx-mode "rt" 'rjsx-rename-tag-at-point)
(with-eval-after-load 'rjsx-mode
(define-key rjsx-mode-map (kbd "C-d") nil))))
(defun react/pre-init-prettier-js ()
(when (eq javascript-fmt-tool 'prettier)
(add-to-list 'spacemacs--prettier-modes 'rjsx-mode)))
(defun react/post-init-smartparens ()
(if dotspacemacs-smartparens-strict-mode
(add-hook 'rjsx-mode-hook #'smartparens-strict-mode)
(add-hook 'rjsx-mode-hook #'smartparens-mode)))
2016-04-21 14:35:28 +00:00
(defun react/post-init-tern ()
(add-to-list 'tern--key-bindings-modes 'rjsx-mode))
(defun react/post-init-tide ()
(when (eq (spacemacs//typescript-backend) `tide)
(add-to-list 'tide-managed-modes 'rjsx-mode)))
(defun react/pre-init-web-beautify ()
(when (eq javascript-fmt-tool 'web-beautify)
(add-to-list 'spacemacs--web-beautify-modes
(cons 'rjsx-mode 'web-beautify-js))))
(defun react/post-init-yasnippet ()
(add-hook 'rjsx-mode-hook #'spacemacs//react-setup-yasnippet))