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/+lang/javascript/packages.el

256 lines
8.7 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- Javascript Layer packages File for Spacemacs
;;
2018-01-04 07:00:25 +00:00
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq javascript-packages
'(
add-node-modules-path
coffee-mode
company
2017-07-03 07:52:54 +00:00
(company-tern :requires company)
evil-matchit
flycheck
ggtags
counsel-gtags
helm-gtags
impatient-mode
js-doc
js2-mode
js2-refactor
json-mode
json-snatcher
(tern :toggle (spacemacs//tern-detect))
web-beautify
skewer-mode
livid-mode
))
(defun javascript/post-init-add-node-modules-path ()
(add-hook 'css-mode-hook #'add-node-modules-path)
(add-hook 'coffee-mode-hook #'add-node-modules-path)
(add-hook 'js2-mode-hook #'add-node-modules-path)
(add-hook 'json-mode-hook #'add-node-modules-path))
(defun javascript/init-coffee-mode ()
(use-package coffee-mode
:defer t
:init
(progn
(spacemacs/register-repl 'coffee-mode 'coffee-repl "coffeescript")
;; keybindings
(spacemacs/declare-prefix-for-mode 'coffee-mode "mc" "compile")
(spacemacs/declare-prefix-for-mode 'coffee-mode "ms" "REPL")
(spacemacs/set-leader-keys-for-major-mode 'coffee-mode
"'" 'coffee-repl
"cc" 'coffee-compile-buffer
"cr" 'coffee-compile-region
"sb" 'coffee-send-buffer
"sl" 'coffee-send-line
"si" 'coffee-repl
"sr" 'coffee-send-region
"Tc" 'coffee-cos-mode)
2015-04-20 10:19:29 +00:00
;; indent to right position after `evil-open-below' and `evil-open-above'
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(add-hook 'coffee-mode-hook
'(lambda ()
(setq indent-line-function 'javascript/coffee-indent
evil-shift-width coffee-tab-width))))))
(defun javascript/init-company-tern ()
(use-package company-tern
:if (and (configuration-layer/package-used-p 'company)
(configuration-layer/package-used-p 'tern))
:defer t
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
:init (spacemacs|add-company-backends
:backends company-tern
:modes js2-mode)))
2017-02-14 16:19:34 +00:00
(defun javascript/post-init-company ()
(spacemacs|add-company-backends
:backends company-capf
:modes coffee-mode))
(defun javascript/post-init-flycheck ()
2016-01-27 20:08:25 +00:00
(dolist (mode '(coffee-mode js2-mode json-mode))
(spacemacs/enable-flycheck mode)))
(defun javascript/post-init-ggtags ()
(add-hook 'js2-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun javascript/post-init-counsel-gtags ()
(spacemacs/counsel-gtags-define-keys-for-mode 'js2-mode))
(defun javascript/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'js2-mode))
(defun javascript/post-init-impatient-mode ()
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "i" 'spacemacs/impatient-mode))
(defun javascript/init-js-doc ()
(use-package js-doc
:defer t
:init (spacemacs/js-doc-set-key-bindings 'js2-mode)))
(defun javascript/init-js2-mode ()
(use-package js2-mode
:defer t
:init
(progn
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
2016-02-27 13:56:42 +00:00
;; Required to make imenu functions work correctly
(add-hook 'js2-mode-hook 'js2-imenu-extras-mode))
:config
(progn
;; prefixes
(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")
(spacemacs/declare-prefix-for-mode 'js2-mode "mz" "folding")
;; key bindings
(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))))
2015-07-05 19:27:32 +00:00
(defun javascript/post-init-evil-matchit ()
(add-hook `js2-mode `turn-on-evil-matchit-mode))
(defun javascript/init-js2-refactor ()
(use-package js2-refactor
:defer t
:init
(progn
(add-hook 'js2-mode-hook 'spacemacs/js2-refactor-require)
;; 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))))
(defun javascript/init-json-mode ()
(use-package json-mode
:defer t))
2015-05-19 06:39:51 +00:00
(defun javascript/init-json-snatcher ()
(use-package json-snatcher
:defer t
:config
(spacemacs/set-leader-keys-for-major-mode 'json-mode
"hp" 'jsons-print-path)))
2015-05-19 06:39:51 +00:00
(defun javascript/init-tern ()
(use-package tern
:defer t
:init (add-hook 'js2-mode-hook 'tern-mode)
:config
(progn
(spacemacs|hide-lighter tern-mode)
2015-10-20 12:30:21 +00:00
(when javascript-disable-tern-port-files
(add-to-list 'tern-command "--no-port-file" 'append))
(spacemacs//set-tern-key-bindings 'js2-mode))))
(defun javascript/init-web-beautify ()
(use-package web-beautify
:defer t
:init
(progn
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
"=" 'web-beautify-js)
(spacemacs/set-leader-keys-for-major-mode 'json-mode
"=" 'web-beautify-js)
(spacemacs/set-leader-keys-for-major-mode 'web-mode
"=" 'web-beautify-html)
(spacemacs/set-leader-keys-for-major-mode 'css-mode
"=" 'web-beautify-css))))
(defun javascript/init-skewer-mode ()
(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)
2016-08-31 07:37:08 +00:00
(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))))
(defun javascript/init-livid-mode ()
(use-package livid-mode
:defer t
:init
(progn
(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]"))))