doomemacs/modules/module-js.el

114 lines
4.7 KiB
EmacsLisp
Raw Normal View History

2015-06-15 09:06:10 +02:00
;;; module-js.el
(use-package js2-mode
:mode "\\.js$"
:interpreter "node"
2015-12-09 01:54:30 -05:00
:init
2016-03-31 03:21:16 -04:00
(use-package nodejs-repl :defer t :commands (nodejs-repl)
:config (evil-set-initial-state 'nodejs-repl-mode 'emacs))
2015-12-09 01:54:30 -05:00
(define-repl! js2-mode nodejs-repl)
(define-docset! js2-mode "js,javascript,nodejs,angularjs,express,jquery,mongoose")
(add-hook! js2-mode
(electric-indent-local-mode +1)
(setq electric-indent-chars '(?} ?\) ?.)
narf-electric-indent-words '("||" "&&")))
2015-06-15 09:06:10 +02:00
:config
(setq-default
js2-skip-preprocessor-directives t
js2-show-parse-errors nil
js2-global-externs '("module" "require" "buster" "sinon" "assert"
"refute" "setTimeout" "clearTimeout"
"setInterval" "clearInterval" "location"
"__dirname" "console" "JSON" "jQuery" "$"
;; Launchbar API
2016-02-19 12:33:57 -05:00
"LaunchBar" "File" "Action" "HTTP" "include" "Lib"))
2015-06-15 09:06:10 +02:00
(map! :map js2-mode-map
(:localleader
:nv ";" 'narf/append-semicolon))
2015-06-15 09:06:10 +02:00
(after! web-beautify
(add-hook! js2-mode (setenv "jsbeautify_indent_size" "4"))
(map! :map js2-mode-map :m "gQ" 'web-beautify-js))
2015-06-15 09:06:10 +02:00
(use-package js2-refactor
2016-03-29 23:13:31 -04:00
:init (add-hook 'js2-mode-hook 'emr-initialize)
:config
2015-10-26 00:36:23 -04:00
(require 'emr)
(mapc (lambda (x)
(let ((command-name (car x))
(title (cadr x))
(region-p (caddr x))
predicate)
(setq predicate (cond ((eq region-p 'both) nil)
(t (if region-p
(lambda () (use-region-p))
(lambda () (not (use-region-p)))))))
2016-03-29 23:13:31 -04:00
(emr-declare-command
(intern (format "js2r-%s" (symbol-name command-name)))
:title title :modes 'js2-mode :predicate predicate)))
'((extract-function "extract function" t)
(extract-method "extract method" t)
(introduce-parameter "introduce parameter" t)
(localize-parameter "localize parameter" nil)
(expand-object "expand object" nil)
(contract-object "contract object" nil)
(expand-function "expand function" nil)
(contract-function "contract function" nil)
(expand-array "expand array" nil)
(contract-array "contract array" nil)
(wrap-buffer-in-iife "wrap buffer in ii function" nil)
(inject-global-in-iife "inject global in ii function" t)
(add-to-globals-annotation "add to globals annotation" nil)
(extract-var "extract variable" t)
(inline-var "inline variable" t)
(rename-var "rename variable" nil)
(var-to-this "var to this" nil)
(arguments-to-object "arguments to object" nil)
(ternary-to-if "ternary to if" nil)
(split-var-declaration "split var declaration" nil)
(split-string "split string" nil)
(unwrap "unwrap" t)
(log-this "log this" 'both)
(debug-this "debug this" 'both)
(forward-slurp "forward slurp" nil)
(forward-barf "forward barf" nil))))
2015-06-15 09:06:10 +02:00
;; [pedantry intensifies]
(defadvice js2-mode (after js2-mode-rename-modeline activate)
2016-02-26 00:07:10 -05:00
(setq mode-name "JS2")))
2015-09-19 00:56:16 -04:00
2016-02-26 00:07:10 -05:00
(define-minor-mode nodejs-mode
:lighter " node" :keymap (make-sparse-keymap)
(add-yas-minor-mode! 'nodejs-mode))
(associate! nodejs-mode :files ("package.json") :in (js2-mode))
2016-02-17 20:07:26 -05:00
2016-02-26 00:07:10 -05:00
(define-minor-mode electron-mode
:lighter " electron" :keymap (make-sparse-keymap)
(add-yas-minor-mode! 'electron-mode))
(associate! electron-mode
:files ("package.json" "app/index.html" "app/main.js")
:in (web-mode js2-mode markdown-mode json-mode coffee-mode))
2015-06-15 09:06:10 +02:00
(use-package tern
:commands tern-mode
:init (add-hook! js2-mode 'tern-mode)
:config
2016-03-29 23:59:09 -04:00
(require 'company-tern)
(define-company-backend! js2-mode (tern)))
2015-06-15 09:06:10 +02:00
(use-package unityjs-mode
2015-07-17 12:07:49 +02:00
:mode "/Assets/.*\\.js$"
2015-06-15 09:06:10 +02:00
:config
2016-01-18 01:43:28 -05:00
(add-hook! unityjs-mode 'flycheck-mode))
2015-06-15 09:06:10 +02:00
2015-10-18 02:27:19 -04:00
(use-package coffee-mode
:mode "\\.coffee$"
:config
2016-01-30 21:16:10 -05:00
(setq-default coffee-indent-like-python-mode t))
2015-10-18 02:27:19 -04:00
2015-06-15 09:06:10 +02:00
(provide 'module-js)
;;; module-js.el ends here