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

93 lines
3.4 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- react Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Andrea Moretti <axyzxp@gmail.com>
;; URL: https://github.com/axyz
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq react-packages
2015-07-28 22:05:16 +00:00
'(
company
company-tern
evil-matchit
flycheck
js-doc
2016-04-21 14:35:28 +00:00
smartparens
tern
2015-07-28 22:05:16 +00:00
web-beautify
web-mode
2015-07-28 22:05:16 +00:00
))
(defun react/post-init-company ()
(spacemacs|add-company-hook react-mode))
(defun react/post-init-company-tern ()
(push 'company-tern company-backends-react-mode))
(defun react/post-init-evil-matchit ()
(with-eval-after-load 'evil-matchit
(plist-put evilmi-plugins 'react-mode '((evilmi-simple-get-tag evilmi-simple-jump)
(evilmi-javascript-get-tag evilmi-javascript-jump)
(evilmi-html-get-tag evilmi-html-jump)))))
(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 'react-mode)))
(defun react/use-eslint-from-node-modules ()
(let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory)
"node_modules"))
(global-eslint (executable-find "eslint"))
(local-eslint (expand-file-name "node_modules/.bin/eslint"
root))
(eslint (if (file-executable-p local-eslint)
local-eslint
global-eslint)))
(setq-local flycheck-javascript-eslint-executable eslint)))
(add-hook 'react-mode-hook #'react/use-eslint-from-node-modules)
2016-01-27 20:08:25 +00:00
(spacemacs/add-flycheck-hook 'react-mode))
(defun react/post-init-js-doc ()
(add-hook 'react-mode-hook 'spacemacs/js-doc-require)
(spacemacs/js-doc-set-key-bindings 'react-mode))
2016-04-21 14:35:28 +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)))
(defun react/post-init-tern ()
(add-hook 'react-mode-hook 'tern-mode)
(spacemacs//set-tern-key-bindings 'react-mode))
(defun react/post-init-web-beautify ()
(spacemacs/set-leader-keys-for-major-mode 'react-mode "=" 'web-beautify-js))
2015-07-28 22:05:16 +00:00
(defun react/post-init-web-mode ()
(define-derived-mode react-mode web-mode "react")
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . react-mode))
(add-to-list 'auto-mode-alist '("\\.react.js\\'" . react-mode))
(add-to-list 'auto-mode-alist '("\\index.android.js\\'" . react-mode))
(add-to-list 'auto-mode-alist '("\\index.ios.js\\'" . react-mode))
2016-02-08 14:54:28 +00:00
(add-to-list 'magic-mode-alist '("/\\*\\* @jsx React\\.DOM \\*/" . react-mode))
(add-to-list 'magic-mode-alist '("^import React" . react-mode))
(defun spacemacs//setup-react-mode ()
"Adjust web-mode to accommodate react-mode"
(emmet-mode 0)
;; See https://github.com/CestDiego/emmet-mode/commit/3f2904196e856d31b9c95794d2682c4c7365db23
(setq-local emmet-expand-jsx-className? t)
2015-12-01 08:07:19 +00:00
;; Enable js-mode snippets
(yas-activate-extra-mode 'js-mode)
2015-09-29 02:03:10 +00:00
;; Force jsx content type
(web-mode-set-content-type "jsx")
2016-01-22 08:34:12 +00:00
;; Don't auto-quote attribute values
2016-04-25 18:02:38 +00:00
(setq-local web-mode-enable-auto-quoting nil))
(add-hook 'react-mode-hook 'spacemacs//setup-react-mode))