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
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
;; Copyright (c) 2012-2018 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.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2018-04-26 19:43:50 +00:00
|
|
|
(defconst react-packages
|
|
|
|
'(
|
|
|
|
add-node-modules-path
|
|
|
|
company
|
|
|
|
emmet-mode
|
|
|
|
evil-matchit
|
|
|
|
flycheck
|
|
|
|
js-doc
|
|
|
|
rjsx-mode
|
|
|
|
smartparens
|
2018-05-18 04:16:43 +00:00
|
|
|
tern
|
2018-04-26 19:43:50 +00:00
|
|
|
web-beautify
|
|
|
|
))
|
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 ()
|
|
|
|
(with-eval-after-load 'evil-matchit
|
2018-04-26 19:43:50 +00:00
|
|
|
(plist-put evilmi-plugins 'rjsx-mode
|
2017-01-02 03:45:23 +00:00
|
|
|
'((evilmi-simple-get-tag evilmi-simple-jump)
|
|
|
|
(evilmi-javascript-get-tag evilmi-javascript-jump)
|
|
|
|
(evilmi-html-get-tag evilmi-html-jump)))))
|
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)))
|
|
|
|
(spacemacs/enable-flycheck 'rjsx-mode))
|
2015-07-27 22:26:47 +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
|
|
|
|
;; enable rjsx mode by using magic-mode-alist
|
|
|
|
(defun +javascript-jsx-file-p ()
|
|
|
|
(and buffer-file-name
|
|
|
|
(equal (file-name-extension buffer-file-name) "js")
|
|
|
|
(re-search-forward "\\(^\\s-*import React\\|\\( from \\|require(\\)[\"']react\\)"
|
|
|
|
magic-mode-regexp-match-limit t)
|
|
|
|
(progn (goto-char (match-beginning 1))
|
2018-05-19 05:16:18 +00:00
|
|
|
(not (spacemacs//react-inside-string-or-comment-q)))))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
|
|
(push (cons #'+javascript-jsx-file-p 'rjsx-mode) magic-mode-alist)
|
|
|
|
|
|
|
|
;; setup rjsx backend
|
|
|
|
(add-hook 'rjsx-mode-local-vars-hook #'spacemacs//react-setup-backend)
|
|
|
|
|
|
|
|
:config
|
|
|
|
;; declare prefix
|
|
|
|
(spacemacs/declare-prefix-for-mode 'rjsx-mode "mr" "refactor")
|
|
|
|
(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")
|
|
|
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'rjsx-mode "rrt" 'rjsx-rename-tag-at-point)
|
|
|
|
|
|
|
|
(with-eval-after-load 'rjsx-mode
|
|
|
|
(define-key rjsx-mode-map (kbd "C-d") nil))))
|
2015-07-27 22:26:47 +00:00
|
|
|
|
2018-03-04 04:37:53 +00:00
|
|
|
(defun react/post-init-smartparens ()
|
|
|
|
(if dotspacemacs-smartparens-strict-mode
|
|
|
|
(add-hook 'react-mode-hook #'smartparens-strict-mode)
|
|
|
|
(add-hook 'react-mode-hook #'smartparens-mode)))
|
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 ()
|
2018-05-20 04:41:17 +00:00
|
|
|
(add-to-list 'spacemacs--web-beautify-modes (cons 'rjsx-mode 'web-beautify-js)))
|