2016-04-06 12:20:44 +00:00
|
|
|
|
;;; funcs.el --- Javascript Layer functions File for Spacemacs
|
|
|
|
|
;;
|
2017-01-06 03:51:13 +00:00
|
|
|
|
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
|
2016-04-06 12:20:44 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Muneeb Shaikh <muneeb@reversehack.in>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
2017-01-02 03:45:23 +00:00
|
|
|
|
|
|
|
|
|
;; js-doc
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/js-doc-require ()
|
|
|
|
|
"Lazy load js-doc"
|
|
|
|
|
(require 'js-doc))
|
|
|
|
|
(add-hook 'js2-mode-hook 'spacemacs/js-doc-require)
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/js-doc-set-key-bindings (mode)
|
|
|
|
|
"Setup the key bindings for `js2-doc' for the given MODE."
|
|
|
|
|
(spacemacs/declare-prefix-for-mode mode "mrd" "documentation")
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"rdb" 'js-doc-insert-file-doc
|
2017-07-02 13:48:06 +00:00
|
|
|
|
"rdf" (if (configuration-layer/package-used-p 'yasnippet)
|
2017-03-09 17:57:07 +00:00
|
|
|
|
'js-doc-insert-function-doc-snippet
|
|
|
|
|
'js-doc-insert-function-doc)
|
2017-01-02 03:45:23 +00:00
|
|
|
|
"rdt" 'js-doc-insert-tag
|
|
|
|
|
"rdh" 'js-doc-describe-tag))
|
|
|
|
|
|
|
|
|
|
;; js-refactor
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/js2-refactor-require ()
|
|
|
|
|
"Lazy load js2-refactor"
|
|
|
|
|
(require 'js2-refactor))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; coffee
|
|
|
|
|
|
|
|
|
|
(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))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; skewer
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/skewer-start-repl ()
|
|
|
|
|
"Attach a browser to Emacs and start a skewer REPL."
|
|
|
|
|
(interactive)
|
|
|
|
|
(run-skewer)
|
|
|
|
|
(skewer-repl))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/skewer-load-buffer-and-focus ()
|
|
|
|
|
"Execute whole buffer in browser and switch to REPL in insert state."
|
|
|
|
|
(interactive)
|
|
|
|
|
(skewer-load-buffer)
|
|
|
|
|
(skewer-repl)
|
|
|
|
|
(evil-insert-state))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/skewer-eval-defun-and-focus ()
|
|
|
|
|
"Execute function at point in browser and switch to REPL in insert state."
|
|
|
|
|
(interactive)
|
|
|
|
|
(skewer-eval-defun)
|
|
|
|
|
(skewer-repl)
|
|
|
|
|
(evil-insert-state))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/skewer-eval-region (beg end)
|
|
|
|
|
"Execute the region as JavaScript code in the attached browser."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(skewer-eval (buffer-substring beg end) #'skewer-post-minibuffer))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/skewer-eval-region-and-focus (beg end)
|
|
|
|
|
"Execute the region in browser and swith to REPL in insert state."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(spacemacs/skewer-eval-region beg end)
|
|
|
|
|
(skewer-repl)
|
|
|
|
|
(evil-insert-state))
|
|
|
|
|
|
2016-06-21 23:03:18 +00:00
|
|
|
|
|
|
|
|
|
;; tern
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//set-tern-key-bindings (mode)
|
|
|
|
|
"Set the key bindings for tern and the given MODE."
|
2016-09-04 16:24:43 +00:00
|
|
|
|
(add-to-list (intern (format "spacemacs-jump-handlers-%S" mode))
|
2016-10-29 20:03:54 +00:00
|
|
|
|
'(tern-find-definition :async t))
|
2016-06-21 23:03:18 +00:00
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
"rrV" 'tern-rename-variable
|
|
|
|
|
"hd" 'tern-get-docs
|
|
|
|
|
"gG" 'tern-find-definition-by-name
|
|
|
|
|
(kbd "C-g") 'tern-pop-find-definition
|
|
|
|
|
"ht" 'tern-get-type))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//tern-detect ()
|
2016-04-06 12:20:44 +00:00
|
|
|
|
"Detect tern binary and warn if not found."
|
2016-04-08 03:13:25 +00:00
|
|
|
|
(let ((found (executable-find "tern")))
|
|
|
|
|
(unless found
|
|
|
|
|
(spacemacs-buffer/warning "tern binary not found!"))
|
|
|
|
|
found))
|