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))
|
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
|
2018-05-18 04:16:43 +00:00
|
|
|
|
(`tern (spacemacs/tern-setup-tern-company 'rjsx-mode))
|
2018-04-26 19:43:50 +00:00
|
|
|
|
(`lsp (spacemacs//react-setup-lsp-company))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; LSP
|
|
|
|
|
(defun spacemacs//react-setup-lsp ()
|
|
|
|
|
"Setup lsp backend."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
|
(progn
|
|
|
|
|
(lsp-javascript-typescript-enable)
|
|
|
|
|
(lsp-javascript-flow-enable)
|
|
|
|
|
(spacemacs//setup-lsp-jump-handler 'rjsx-mode))
|
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dofile.")))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//react-setup-lsp-company ()
|
|
|
|
|
"Setup lsp auto-completion."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
|
|
|
|
(progn
|
|
|
|
|
(fix-lsp-company-prefix)
|
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends company-lsp
|
|
|
|
|
:modes rjsx-mode
|
2018-05-18 04:33:48 +00:00
|
|
|
|
:variables company-minimum-prefix-length 2
|
2018-04-26 19:43:50 +00:00
|
|
|
|
:append-hooks nil
|
|
|
|
|
:call-hooks t)
|
|
|
|
|
(company-mode))
|
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dofile.")))
|
|
|
|
|
|
|
|
|
|
|
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)))
|