2018-04-26 19:43:50 +00:00
|
|
|
|
;;; funcs.el --- react layer funcs file for Spacemacs. -*- lexical-binding: t -*-
|
2017-01-02 03:45:23 +00:00
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2017-01-02 03:45:23 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Muneeb Shaikh <muneeb@reversehack.in>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
|
|
|
|
;; Backend
|
|
|
|
|
(defun spacemacs//react-setup-backend ()
|
|
|
|
|
"Conditionally setup react backend."
|
|
|
|
|
(pcase javascript-backend
|
2018-05-18 04:16:43 +00:00
|
|
|
|
(`tern (spacemacs/tern-setup-tern))
|
2020-02-24 16:13:40 +00:00
|
|
|
|
(`tide (spacemacs//tide-setup))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
(`lsp (spacemacs//react-setup-lsp))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//react-setup-company ()
|
|
|
|
|
"Conditionally setup company based on backend."
|
|
|
|
|
(pcase javascript-backend
|
2020-04-02 16:41:28 +00:00
|
|
|
|
(`tide (spacemacs//tide-setup-company 'rjsx-mode))))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
2019-04-13 07:12:06 +00:00
|
|
|
|
(defun spacemacs//react-setup-next-error-fn ()
|
|
|
|
|
"If the `syntax-checking' layer is enabled, disable `rjsx-mode''s
|
|
|
|
|
`next-error-function', and let `flycheck' handle any errors."
|
|
|
|
|
(when (configuration-layer/layer-used-p 'syntax-checking)
|
|
|
|
|
(setq-local next-error-function nil)))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
|
|
|
|
;; LSP
|
|
|
|
|
(defun spacemacs//react-setup-lsp ()
|
|
|
|
|
"Setup lsp backend."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
2019-04-13 07:12:06 +00:00
|
|
|
|
(progn
|
|
|
|
|
(when (not javascript-lsp-linter)
|
2020-09-18 18:31:30 +00:00
|
|
|
|
(setq-local lsp-diagnostics-provider :none))
|
2019-04-13 07:12:06 +00:00
|
|
|
|
(lsp))
|
2018-05-24 02:12:30 +00:00
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
|
|
|
|
|
|
2018-05-19 05:15:04 +00:00
|
|
|
|
;; Emmet
|
|
|
|
|
(defun spacemacs/react-emmet-mode ()
|
|
|
|
|
"Activate `emmet-mode' and configure it for local buffer."
|
|
|
|
|
(emmet-mode)
|
|
|
|
|
(setq-local emmet-expand-jsx-className? t))
|
|
|
|
|
|
2018-05-19 05:16:18 +00:00
|
|
|
|
|
2018-04-26 19:43:50 +00:00
|
|
|
|
;; Others
|
2018-05-19 05:16:18 +00:00
|
|
|
|
(defun spacemacs//react-inside-string-q ()
|
2018-04-26 19:43:50 +00:00
|
|
|
|
"Returns non-nil if inside string, else nil.
|
|
|
|
|
Result depends on syntax table's string quote character."
|
|
|
|
|
(let ((result (nth 3 (syntax-ppss))))
|
|
|
|
|
result))
|
|
|
|
|
|
2018-05-19 05:16:18 +00:00
|
|
|
|
(defun spacemacs//react-inside-comment-q ()
|
2018-04-26 19:43:50 +00:00
|
|
|
|
"Returns non-nil if inside comment, else nil.
|
|
|
|
|
Result depends on syntax table's comment character."
|
|
|
|
|
(let ((result (nth 4 (syntax-ppss))))
|
|
|
|
|
result))
|
|
|
|
|
|
2018-05-19 05:16:18 +00:00
|
|
|
|
(defun spacemacs//react-inside-string-or-comment-q ()
|
2018-04-26 19:43:50 +00:00
|
|
|
|
"Return non-nil if point is inside string, documentation string or a comment.
|
|
|
|
|
If optional argument P is present, test this instead of point."
|
2018-05-19 05:16:18 +00:00
|
|
|
|
(or (spacemacs//react-inside-string-q)
|
|
|
|
|
(spacemacs//react-inside-comment-q)))
|
2018-06-02 00:34:48 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//react-setup-yasnippet ()
|
|
|
|
|
(yas-activate-extra-mode 'js-mode))
|
2019-10-09 15:26:12 +00:00
|
|
|
|
|
|
|
|
|
;; Format
|
2019-11-22 19:54:19 +00:00
|
|
|
|
(defun spacemacs//react-fmt-before-save-hook ()
|
2019-10-09 15:26:12 +00:00
|
|
|
|
(add-hook 'before-save-hook 'spacemacs/javascript-format t t))
|