2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- Javascript Layer packages File for Spacemacs
|
|
|
|
;;
|
2020-05-16 21:32:30 +00:00
|
|
|
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
|
2015-01-14 04:12:56 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2020-05-16 21:32:30 +00:00
|
|
|
(defconst javascript-packages
|
|
|
|
'(
|
|
|
|
add-node-modules-path
|
|
|
|
company
|
|
|
|
counsel-gtags
|
|
|
|
dap-mode
|
|
|
|
evil-matchit
|
|
|
|
flycheck
|
|
|
|
ggtags
|
|
|
|
helm-gtags
|
|
|
|
imenu
|
|
|
|
impatient-mode
|
|
|
|
import-js
|
|
|
|
js-doc
|
|
|
|
js2-mode
|
|
|
|
js2-refactor
|
|
|
|
livid-mode
|
|
|
|
nodejs-repl
|
|
|
|
org
|
|
|
|
prettier-js
|
|
|
|
skewer-mode
|
|
|
|
tern
|
|
|
|
tide
|
|
|
|
web-beautify))
|
2014-12-07 17:57:09 +00:00
|
|
|
|
2017-03-31 23:38:43 +00:00
|
|
|
(defun javascript/post-init-add-node-modules-path ()
|
2018-05-14 04:46:45 +00:00
|
|
|
(spacemacs/add-to-hooks #'add-node-modules-path '(css-mode-hook
|
2019-06-09 18:02:37 +00:00
|
|
|
js2-mode-hook)))
|
2017-03-31 23:38:43 +00:00
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
(defun javascript/post-init-company ()
|
|
|
|
(add-hook 'js2-mode-local-vars-hook #'spacemacs//javascript-setup-company))
|
|
|
|
|
2018-05-13 06:12:14 +00:00
|
|
|
(defun javascript/post-init-counsel-gtags ()
|
|
|
|
(spacemacs/counsel-gtags-define-keys-for-mode 'js2-mode))
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
(defun javascript/pre-init-dap-mode ()
|
2020-05-16 21:32:30 +00:00
|
|
|
(pcase (spacemacs//javascript-backend)
|
|
|
|
(`lsp (add-to-list 'spacemacs--dap-supported-modes 'js2-mode)))
|
2019-09-30 01:30:53 +00:00
|
|
|
(add-hook 'js2-mode-local-vars-hook #'spacemacs//javascript-setup-dap))
|
|
|
|
|
2018-05-13 06:12:14 +00:00
|
|
|
(defun javascript/post-init-evil-matchit ()
|
2019-02-10 08:44:35 +00:00
|
|
|
(add-hook `js2-mode-hook `turn-on-evil-matchit-mode))
|
2018-05-13 05:31:00 +00:00
|
|
|
|
2015-04-11 02:23:16 +00:00
|
|
|
(defun javascript/post-init-flycheck ()
|
2019-11-11 08:17:31 +00:00
|
|
|
(spacemacs/enable-flycheck 'js2-mode)
|
|
|
|
(add-hook 'js2-mode-hook #'spacemacs//javascript-setup-checkers 'append))
|
2014-12-23 03:51:44 +00:00
|
|
|
|
2016-04-05 04:08:34 +00:00
|
|
|
(defun javascript/post-init-ggtags ()
|
2016-08-15 19:24:44 +00:00
|
|
|
(add-hook 'js2-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
|
2016-04-05 04:08:34 +00:00
|
|
|
|
|
|
|
(defun javascript/post-init-helm-gtags ()
|
|
|
|
(spacemacs/helm-gtags-define-keys-for-mode 'js2-mode))
|
|
|
|
|
2018-05-13 13:16:04 +00:00
|
|
|
(defun javascript/post-init-imenu ()
|
2018-05-13 05:31:00 +00:00
|
|
|
;; Required to make imenu functions work correctly
|
|
|
|
(add-hook 'js2-mode-hook 'js2-imenu-extras-mode))
|
|
|
|
|
2015-08-27 11:21:24 +00:00
|
|
|
(defun javascript/post-init-impatient-mode ()
|
2018-05-13 06:14:09 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
|
2018-06-05 05:57:25 +00:00
|
|
|
"I" 'spacemacs/impatient-mode))
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
(defun javascript/pre-init-import-js ()
|
|
|
|
(when (eq javascript-import-tool 'import-js)
|
|
|
|
(add-to-list 'spacemacs--import-js-modes (cons 'js2-mode 'js2-mode-hook))))
|
2018-05-30 13:07:21 +00:00
|
|
|
|
2015-08-26 01:02:51 +00:00
|
|
|
(defun javascript/init-js-doc ()
|
|
|
|
(use-package js-doc
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2020-04-22 03:46:28 +00:00
|
|
|
:init (spacemacs/js-doc-set-key-bindings 'js2-mode)
|
|
|
|
(add-hook 'js2-mode-hook 'spacemacs/js-doc-require)))
|
2015-08-26 01:02:51 +00:00
|
|
|
|
2014-12-07 17:57:09 +00:00
|
|
|
(defun javascript/init-js2-mode ()
|
|
|
|
(use-package js2-mode
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2018-08-03 08:11:36 +00:00
|
|
|
:mode (("\\.m?js\\'" . js2-mode))
|
2018-05-13 06:14:09 +00:00
|
|
|
:init
|
|
|
|
(progn
|
2018-06-02 22:11:47 +00:00
|
|
|
(add-hook 'js2-mode-local-vars-hook #'spacemacs//javascript-setup-backend)
|
2019-04-13 07:12:06 +00:00
|
|
|
(add-hook 'js2-mode-local-vars-hook #'spacemacs//javascript-setup-next-error-fn)
|
2018-05-13 06:14:09 +00:00
|
|
|
;; safe values for backend to be used in directory file variables
|
2020-02-24 16:13:40 +00:00
|
|
|
(dolist (value '(lsp tern tide))
|
2018-05-13 06:14:09 +00:00
|
|
|
(add-to-list 'safe-local-variable-values
|
|
|
|
(cons 'javascript-backend value))))
|
2014-12-07 17:57:09 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2019-04-24 12:03:27 +00:00
|
|
|
(when javascript-fmt-on-save
|
|
|
|
(add-hook 'js2-mode-local-vars-hook 'spacemacs/javascript-fmt-before-save-hook))
|
2017-01-02 03:45:23 +00:00
|
|
|
;; prefixes
|
2016-04-03 04:12:28 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mh" "documentation")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mg" "goto")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mr" "refactor")
|
2015-07-31 03:20:54 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mz" "folding")
|
2017-01-02 03:45:23 +00:00
|
|
|
;; key bindings
|
2016-04-03 04:12:28 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
|
|
|
|
"w" 'js2-mode-toggle-warnings-and-errors
|
|
|
|
"zc" 'js2-mode-hide-element
|
|
|
|
"zo" 'js2-mode-show-element
|
|
|
|
"zr" 'js2-mode-show-all
|
|
|
|
"ze" 'js2-mode-toggle-element
|
|
|
|
"zF" 'js2-mode-toggle-hide-functions
|
|
|
|
"zC" 'js2-mode-toggle-hide-comments))))
|
2014-12-07 17:57:09 +00:00
|
|
|
|
|
|
|
(defun javascript/init-js2-refactor ()
|
|
|
|
(use-package js2-refactor
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2014-12-19 02:39:41 +00:00
|
|
|
:init
|
|
|
|
(progn
|
2015-08-26 00:57:56 +00:00
|
|
|
(add-hook 'js2-mode-hook 'spacemacs/js2-refactor-require)
|
2017-01-02 03:45:23 +00:00
|
|
|
;; prefixes
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mr3" "ternary")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mra" "add/args")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrb" "barf")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrc" "contract")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mre" "expand/extract")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mri" "inline/inject/introduct")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrl" "localize/log")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrr" "rename")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrs" "split/slurp")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrt" "toggle")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mru" "unwrap")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrv" "var")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mrw" "wrap")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mx" "text")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mxm" "move")
|
|
|
|
;; key bindings
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
|
|
|
|
"r3i" 'js2r-ternary-to-if
|
|
|
|
"rag" 'js2r-add-to-globals-annotation
|
|
|
|
"rao" 'js2r-arguments-to-object
|
|
|
|
"rba" 'js2r-forward-barf
|
|
|
|
"rca" 'js2r-contract-array
|
|
|
|
"rco" 'js2r-contract-object
|
|
|
|
"rcu" 'js2r-contract-function
|
|
|
|
"rea" 'js2r-expand-array
|
|
|
|
"ref" 'js2r-extract-function
|
|
|
|
"rem" 'js2r-extract-method
|
|
|
|
"reo" 'js2r-expand-object
|
|
|
|
"reu" 'js2r-expand-function
|
|
|
|
"rev" 'js2r-extract-var
|
|
|
|
"rig" 'js2r-inject-global-in-iife
|
|
|
|
"rip" 'js2r-introduce-parameter
|
|
|
|
"riv" 'js2r-inline-var
|
|
|
|
"rlp" 'js2r-localize-parameter
|
|
|
|
"rlt" 'js2r-log-this
|
|
|
|
"rrv" 'js2r-rename-var
|
|
|
|
"rsl" 'js2r-forward-slurp
|
|
|
|
"rss" 'js2r-split-string
|
|
|
|
"rsv" 'js2r-split-var-declaration
|
|
|
|
"rtf" 'js2r-toggle-function-expression-and-declaration
|
|
|
|
"ruw" 'js2r-unwrap
|
|
|
|
"rvt" 'js2r-var-to-this
|
|
|
|
"rwi" 'js2r-wrap-buffer-in-iife
|
|
|
|
"rwl" 'js2r-wrap-in-for-loop
|
|
|
|
"k" 'js2r-kill
|
|
|
|
"xmj" 'js2r-move-line-down
|
|
|
|
"xmk" 'js2r-move-line-up))))
|
2014-12-07 17:57:09 +00:00
|
|
|
|
2018-05-13 06:12:14 +00:00
|
|
|
(defun javascript/init-livid-mode ()
|
2019-06-09 18:02:37 +00:00
|
|
|
(when (eq javascript-repl 'skewer)
|
|
|
|
(use-package livid-mode
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "mT" "toggle")
|
|
|
|
(spacemacs|add-toggle javascript-repl-live-evaluation
|
|
|
|
:mode livid-mode
|
|
|
|
:documentation "Live evaluation of JS buffer change."
|
|
|
|
:evil-leader-for-mode (js2-mode . "Tl"))
|
|
|
|
(spacemacs|diminish livid-mode " 🅻" " [l]")))))
|
2015-04-03 21:12:56 +00:00
|
|
|
|
2019-02-04 19:44:41 +00:00
|
|
|
(defun javascript/init-nodejs-repl ()
|
2019-06-09 18:02:37 +00:00
|
|
|
(when (eq javascript-repl 'nodejs)
|
|
|
|
(use-package nodejs-repl
|
|
|
|
:defer nil
|
|
|
|
:init
|
|
|
|
(spacemacs/register-repl 'nodejs-repl
|
|
|
|
'nodejs-repl
|
|
|
|
"nodejs-repl")
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "ms" "nodejs-repl")
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
|
|
|
|
"'" 'nodejs-repl
|
|
|
|
"ss" 'nodejs-repl
|
|
|
|
"si" 'nodejs-repl-switch-to-repl
|
|
|
|
"se" 'nodejs-repl-send-last-expression
|
|
|
|
"sE" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(nodejs-repl-send-last-expression)
|
|
|
|
(nodejs-repl-switch-to-repl))
|
|
|
|
"sb" 'nodejs-repl-send-buffer
|
|
|
|
"sB" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(nodejs-repl-send-buffer)
|
|
|
|
(nodejs-repl-switch-to-repl))
|
|
|
|
"sl" 'nodejs-repl-send-line
|
|
|
|
"sL" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(nodejs-repl-send-line)
|
|
|
|
(nodejs-repl-switch-to-repl))
|
|
|
|
"sr" 'nodejs-repl-send-region
|
|
|
|
"sR" (lambda (start end)
|
|
|
|
(interactive "r")
|
|
|
|
(nodejs-repl-send-region start end)
|
|
|
|
(nodejs-repl-switch-to-repl)))
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode
|
|
|
|
"msE" "nodejs-send-last-expression-and-focus")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode
|
|
|
|
"msB" "nodejs-send-buffer-and-focus")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode
|
|
|
|
"msL" "nodejs-send-line-and-focus")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode
|
2020-05-16 21:32:30 +00:00
|
|
|
"msR" "nodejs-send-region-and-focus")))))
|
|
|
|
|
2019-02-04 19:44:41 +00:00
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
(defun javascript/pre-init-org ()
|
|
|
|
(spacemacs|use-package-add-hook org
|
|
|
|
:post-config (add-to-list 'org-babel-load-languages '(js . t))))
|
|
|
|
|
|
|
|
(defun javascript/pre-init-prettier-js ()
|
|
|
|
(when (eq javascript-fmt-tool 'prettier)
|
|
|
|
(add-to-list 'spacemacs--prettier-modes 'js2-mode)))
|
|
|
|
|
|
|
|
(defun javascript/init-skewer-mode ()
|
|
|
|
(when (eq javascript-repl 'skewer)
|
|
|
|
(use-package skewer-mode
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(spacemacs/register-repl 'skewer-mode
|
|
|
|
'spacemacs/skewer-start-repl
|
|
|
|
"skewer")
|
|
|
|
(add-hook 'js2-mode-hook 'skewer-mode))
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(spacemacs|hide-lighter skewer-mode)
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "ms" "skewer")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'js2-mode "me" "eval")
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
|
|
|
|
"'" 'spacemacs/skewer-start-repl
|
|
|
|
"ee" 'skewer-eval-last-expression
|
|
|
|
"eE" 'skewer-eval-print-last-expression
|
|
|
|
"sb" 'skewer-load-buffer
|
|
|
|
"sB" 'spacemacs/skewer-load-buffer-and-focus
|
|
|
|
"si" 'spacemacs/skewer-start-repl
|
|
|
|
"sf" 'skewer-eval-defun
|
|
|
|
"sF" 'spacemacs/skewer-eval-defun-and-focus
|
|
|
|
"sr" 'spacemacs/skewer-eval-region
|
|
|
|
"sR" 'spacemacs/skewer-eval-region-and-focus
|
|
|
|
"ss" 'skewer-repl)))))
|
|
|
|
|
2018-05-18 03:34:24 +00:00
|
|
|
(defun javascript/post-init-tern ()
|
|
|
|
(add-to-list 'tern--key-bindings-modes 'js2-mode))
|
2018-04-26 23:33:41 +00:00
|
|
|
|
2020-02-24 16:13:40 +00:00
|
|
|
(defun javascript/post-init-tide ()
|
2020-03-08 11:34:31 +00:00
|
|
|
(when (eq (spacemacs//typescript-backend) `tide)
|
|
|
|
(add-to-list 'tide-managed-modes 'js2-mode)))
|
2020-02-24 16:13:40 +00:00
|
|
|
|
2018-05-19 05:53:33 +00:00
|
|
|
(defun javascript/pre-init-web-beautify ()
|
2019-05-12 14:01:05 +00:00
|
|
|
(when (eq javascript-fmt-tool 'web-beautify)
|
2019-06-09 18:02:37 +00:00
|
|
|
(add-to-list 'spacemacs--web-beautify-modes
|
|
|
|
(cons 'js2-mode 'web-beautify-js))))
|