2015-01-14 04:12:56 +00:00
|
|
|
;;; packages.el --- Javascript Layer packages File for Spacemacs
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 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
|
|
|
|
|
2015-04-19 03:40:24 +00:00
|
|
|
(setq javascript-packages
|
2014-12-07 17:57:09 +00:00
|
|
|
'(
|
2014-12-14 03:49:24 +00:00
|
|
|
coffee-mode
|
2015-04-09 03:57:22 +00:00
|
|
|
company
|
2015-03-22 06:23:12 +00:00
|
|
|
company-tern
|
2014-12-23 03:51:44 +00:00
|
|
|
flycheck
|
2014-12-07 17:57:09 +00:00
|
|
|
js2-mode
|
|
|
|
js2-refactor
|
2014-12-23 03:51:44 +00:00
|
|
|
json-mode
|
2014-12-07 17:57:09 +00:00
|
|
|
tern
|
2015-04-08 11:19:04 +00:00
|
|
|
js-doc
|
2015-04-26 06:38:38 +00:00
|
|
|
web-beautify
|
2015-04-19 03:40:24 +00:00
|
|
|
))
|
2014-12-07 17:57:09 +00:00
|
|
|
|
2014-12-14 03:49:24 +00:00
|
|
|
(defun javascript/init-coffee-mode ()
|
|
|
|
(use-package coffee-mode
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(defun javascript/coffee-indent ()
|
|
|
|
(if (coffee-line-wants-indent)
|
|
|
|
;; We need to insert an additional tab because the last line was special.
|
|
|
|
(coffee-insert-spaces (+ (coffee-previous-indent) coffee-tab-width))
|
|
|
|
;; otherwise keep at the same indentation level
|
|
|
|
(coffee-insert-spaces (coffee-previous-indent)))
|
|
|
|
)
|
2015-04-20 10:19:29 +00:00
|
|
|
;; indent to right position after `evil-open-below' and `evil-open-above'
|
2014-12-14 03:49:24 +00:00
|
|
|
(add-hook 'coffee-mode-hook '(lambda ()
|
|
|
|
(setq indent-line-function 'javascript/coffee-indent
|
|
|
|
evil-shift-width coffee-tab-width))))))
|
|
|
|
|
2015-04-11 02:23:16 +00:00
|
|
|
(defun javascript/post-init-flycheck ()
|
2014-12-23 03:51:44 +00:00
|
|
|
(add-hook 'coffee-mode-hook 'flycheck-mode)
|
|
|
|
(add-hook 'js2-mode-hook 'flycheck-mode)
|
|
|
|
(add-hook 'json-mode-hook 'flycheck-mode))
|
|
|
|
|
2014-12-07 17:57:09 +00:00
|
|
|
(defun javascript/init-js2-mode ()
|
|
|
|
(use-package js2-mode
|
|
|
|
:defer t
|
2014-12-17 18:43:42 +00:00
|
|
|
:init
|
|
|
|
(progn
|
2014-12-17 23:54:58 +00:00
|
|
|
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
|
|
|
|
;; required to make `<SPC> s l' to work correctly
|
|
|
|
(add-hook 'js2-mode-hook 'js2-imenu-extras-mode))
|
2014-12-07 17:57:09 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "m" "major mode")
|
2014-12-07 17:57:09 +00:00
|
|
|
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mw" 'js2-mode-toggle-warnings-and-errors)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mz" "folding")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mzc" 'js2-mode-hide-element)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mzo" 'js2-mode-show-element)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mzr" 'js2-mode-show-all)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mze" 'js2-mode-toggle-element)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mzF" 'js2-mode-toggle-hide-functions)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mzC" 'js2-mode-toggle-hide-comments))))
|
|
|
|
|
|
|
|
(defun javascript/init-js2-refactor ()
|
|
|
|
(use-package js2-refactor
|
|
|
|
:defer t
|
2014-12-19 02:39:41 +00:00
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(defun javascript/load-js2-refactor ()
|
|
|
|
"Lazy load js2-refactor"
|
|
|
|
(require 'js2-refactor))
|
|
|
|
(add-hook 'js2-mode-hook 'javascript/load-js2-refactor))
|
2014-12-07 17:57:09 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mr" "refactor")
|
2014-12-07 17:57:09 +00:00
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mr3" "ternary")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mr3i" 'js2r-ternary-to-if)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mra" "add/args")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrag" 'js2r-add-to-globals-annotation)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrao" 'js2r-arguments-to-object)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrb" "barf")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrba" 'js2r-forward-barf)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrc" "contract")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrca" 'js2r-contract-array)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrco" 'js2r-contract-object)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrcu" 'js2r-contract-function)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mre" "expand/extract")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrea" 'js2r-expand-array)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mref" 'js2r-extract-function)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrem" 'js2r-extract-method)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mreo" 'js2r-expand-object)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mreu" 'js2r-expand-function)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrev" 'js2r-extract-var)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mri" "inline/inject/introduct")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrig" 'js2r-inject-global-in-iife)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrip" 'js2r-introduce-parameter)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mriv" 'js2r-inline-var)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrl" "localize/log")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrlp" 'js2r-localize-parameter)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrlt" 'js2r-log-this)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrr" "rename")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrrv" 'js2r-rename-var)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrs" "split/slurp")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrsl" 'js2r-forward-slurp)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrss" 'js2r-split-string)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrsv" 'js2r-split-var-declaration)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrt" "toggle")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrtf" 'js2r-toggle-function-expression-and-declaration)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mru" "unwrap")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mruw" 'js2r-unwrap)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrv" "var")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrvt" 'js2r-var-to-this)
|
|
|
|
|
2014-12-08 17:59:17 +00:00
|
|
|
;;(spacemacs/declare-prefix-for-mode 'js2-mode "mrw" "wrap")
|
2014-12-07 17:57:09 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrwi" 'js2r-wrap-buffer-in-iife)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrwl" 'js2r-wrap-in-for-loop)
|
|
|
|
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mk" 'js2r-kill)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "xmj" 'js2r-move-line-down)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "xmk" 'js2r-move-line-up))))
|
|
|
|
|
2014-12-23 03:51:44 +00:00
|
|
|
(defun javascript/init-json-mode ()
|
|
|
|
(use-package json-mode
|
|
|
|
:defer t))
|
|
|
|
|
2014-12-07 17:57:09 +00:00
|
|
|
(defun javascript/init-tern ()
|
|
|
|
(use-package tern
|
|
|
|
:defer t
|
2014-12-19 02:39:41 +00:00
|
|
|
:init (add-hook 'js2-mode-hook 'tern-mode)
|
2014-12-07 17:57:09 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2015-04-21 05:38:58 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrrV" 'tern-rename-variable)
|
2014-12-22 03:52:57 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mhd" 'tern-get-docs)
|
2015-01-21 03:32:13 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mgg" 'tern-find-definition)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mgG" 'tern-find-definition-by-name)
|
2014-12-08 05:39:19 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode (kbd "m C-g") 'tern-pop-find-definition)
|
2015-04-21 05:38:58 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mht" 'tern-get-type))))
|
2015-04-03 21:12:56 +00:00
|
|
|
|
2015-04-08 11:19:04 +00:00
|
|
|
(defun javascript/init-js-doc ()
|
|
|
|
(use-package js-doc
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(defun javascript/load-js-doc ()
|
|
|
|
"Lazy load js-doc"
|
|
|
|
(require 'js-doc))
|
|
|
|
(add-hook 'js2-mode-hook 'javascript/load-js-doc))
|
|
|
|
:config
|
|
|
|
(progn
|
2015-04-21 05:36:02 +00:00
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrdb" 'js-doc-insert-file-doc)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrdf" 'js-doc-insert-function-doc)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrdt" 'js-doc-insert-tag)
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "mrdh" 'js-doc-describe-tag))))
|
2015-04-08 11:19:04 +00:00
|
|
|
|
2015-04-26 06:38:38 +00:00
|
|
|
(defun javascript/init-web-beautify ()
|
|
|
|
(use-package web-beautify
|
|
|
|
:defer t
|
|
|
|
:init
|
2015-04-28 04:02:35 +00:00
|
|
|
(progn
|
|
|
|
(evil-leader/set-key-for-mode 'js2-mode "m=" 'web-beautify-js)
|
|
|
|
(evil-leader/set-key-for-mode 'json-mode "m=" 'web-beautify-js)
|
|
|
|
(evil-leader/set-key-for-mode 'web-mode "m=" 'web-beautify-html)
|
|
|
|
(evil-leader/set-key-for-mode 'css-mode "m=" 'web-beautify-css))))
|
2015-04-26 06:38:38 +00:00
|
|
|
|
|
|
|
|
2015-04-03 23:13:52 +00:00
|
|
|
(when (configuration-layer/layer-usedp 'auto-completion)
|
2015-04-09 03:57:22 +00:00
|
|
|
(defun javascript/post-init-company ()
|
|
|
|
(spacemacs|add-company-hook js2-mode))
|
|
|
|
|
2015-04-03 21:12:56 +00:00
|
|
|
(defun javascript/init-company-tern ()
|
|
|
|
(use-package company-tern
|
2015-04-03 23:13:52 +00:00
|
|
|
:if (and (configuration-layer/package-usedp 'company)
|
|
|
|
(configuration-layer/package-usedp 'tern))
|
2015-04-03 21:12:56 +00:00
|
|
|
:defer t
|
2015-04-09 03:57:22 +00:00
|
|
|
:init
|
2015-04-30 03:54:30 +00:00
|
|
|
(push 'company-tern company-backends-js2-mode))))
|