2015-06-15 09:06:10 +02:00
|
|
|
;;; module-js.el
|
|
|
|
|
|
|
|
(use-package js2-mode
|
|
|
|
:mode "\\.js$"
|
|
|
|
:interpreter "node"
|
2016-05-13 00:28:44 -04:00
|
|
|
:init (add-hook 'js2-mode-hook 'tern-mode)
|
2016-05-01 01:10:30 -04:00
|
|
|
:config
|
2016-04-23 22:08:46 -04:00
|
|
|
(def-repl! js2-mode nodejs-repl)
|
|
|
|
(def-docset! js2-mode "js,javascript,nodejs,angularjs,express,jquery,mongoose")
|
2016-05-18 17:00:00 -04:00
|
|
|
(def-company-backend! js2-mode (tern yasnippet))
|
2016-04-23 22:08:46 -04:00
|
|
|
(def-electric! js2-mode :chars (?\} ?\) ?.) :words ("||" "&&"))
|
2015-06-15 09:06:10 +02:00
|
|
|
(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
|
|
|
|
2016-04-12 02:58:30 -04:00
|
|
|
;; [pedantry intensifies]
|
2016-04-23 22:08:46 -04:00
|
|
|
(add-hook! js2-mode (setq mode-name "JS2"))
|
|
|
|
|
|
|
|
(map! :map js2-mode-map (:localleader :nv ";" 'narf/append-semicolon)))
|
|
|
|
|
|
|
|
(use-package tern
|
|
|
|
:after js2-mode
|
|
|
|
:commands (tern-mode))
|
2016-04-12 02:58:30 -04:00
|
|
|
|
2016-04-23 22:08:46 -04:00
|
|
|
(use-package company-tern
|
|
|
|
:after tern)
|
2016-04-12 02:58:30 -04:00
|
|
|
|
2016-04-23 22:08:46 -04:00
|
|
|
(use-package js2-refactor
|
|
|
|
:after js2-mode
|
|
|
|
:config
|
2016-04-20 21:36:32 -04:00
|
|
|
(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)))))))
|
|
|
|
(emr-declare-command
|
2016-04-23 22:08:46 -04:00
|
|
|
(intern (format "js2r-%s" (symbol-name command-name)))
|
|
|
|
:title title :modes 'js2-mode :predicate predicate)))
|
2016-04-20 21:36:32 -04:00
|
|
|
'((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-09-19 00:56:16 -04:00
|
|
|
|
2016-04-23 22:08:46 -04:00
|
|
|
(use-package nodejs-repl :commands (nodejs-repl))
|
|
|
|
|
|
|
|
;;
|
2016-04-19 02:41:34 -04:00
|
|
|
(use-package jsx-mode :mode "\\.jsx$")
|
2015-06-15 09:06:10 +02:00
|
|
|
|
|
|
|
(use-package unityjs-mode
|
2015-07-17 12:07:49 +02:00
|
|
|
:mode "/Assets/.*\\.js$"
|
2016-04-12 02:58:30 -04:00
|
|
|
:config (add-hook 'unityjs-mode-hook 'flycheck-mode))
|
2015-06-15 09:06:10 +02:00
|
|
|
|
2015-10-18 02:27:19 -04:00
|
|
|
(use-package coffee-mode
|
|
|
|
:mode "\\.coffee$"
|
2016-04-12 02:58:30 -04:00
|
|
|
:config (setq-default coffee-indent-like-python-mode t))
|
2015-10-18 02:27:19 -04:00
|
|
|
|
2016-05-19 03:18:33 -04:00
|
|
|
(use-package typescript-mode
|
|
|
|
:mode "\\.ts$")
|
|
|
|
|
|
|
|
(use-package tide
|
|
|
|
:after typescript-mode
|
|
|
|
:config
|
|
|
|
(setq tide-format-options
|
|
|
|
'(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t
|
|
|
|
:placeOpenBraceOnNewLineForFunctions nil))
|
|
|
|
(defun narf|tide-setup ()
|
|
|
|
(tide-setup)
|
|
|
|
(flycheck-mode +1)
|
|
|
|
(eldoc-mode +1))
|
|
|
|
(add-hook 'typescript-mode-hook 'narf|tide-setup)
|
|
|
|
(add-hook! web-mode
|
|
|
|
(when (f-ext? buffer-file-name "tsx")
|
|
|
|
(narf|tide-setup)))
|
|
|
|
|
|
|
|
(map! :map typescript-mode-map
|
|
|
|
:m "gd" 'tide-jump-to-definition
|
|
|
|
(:leader :n "h" 'tide-documentation-at-point)))
|
|
|
|
|
2016-04-16 21:36:24 -04:00
|
|
|
;;
|
2016-05-20 16:55:32 -04:00
|
|
|
(defvar npm-conf (make-hash-table :test 'equal))
|
2016-04-23 22:08:46 -04:00
|
|
|
(def-project-type! nodejs "node"
|
2016-05-20 16:55:32 -04:00
|
|
|
:modes (web-mode js-mode coffee-mode css-mode sass-mode pug-mode)
|
|
|
|
:files ("package.json")
|
|
|
|
:when
|
|
|
|
(lambda (&rest _)
|
|
|
|
(let* ((project-path (narf/project-root))
|
|
|
|
(hash (gethash project-path npm-conf))
|
|
|
|
(package-file (f-expand "package.json" project-path))
|
|
|
|
deps)
|
|
|
|
(awhen (and (not hash) (f-exists? package-file)
|
|
|
|
(json-read-file package-file))
|
|
|
|
(puthash project-path it npm-conf)))
|
|
|
|
t))
|
2016-04-16 21:36:24 -04:00
|
|
|
|
2016-05-20 16:55:32 -04:00
|
|
|
(def-project-type! expressjs "express"
|
|
|
|
:modes (nodejs-project-mode bower-project-mode)
|
|
|
|
:when
|
|
|
|
(lambda (&rest _)
|
|
|
|
(awhen (gethash (narf/project-root) npm-conf)
|
|
|
|
(assq 'express (cdr-safe (assq 'dependencies it))))))
|
2016-04-16 21:36:24 -04:00
|
|
|
|
|
|
|
;; TODO electron-compile support
|
2016-05-20 16:55:32 -04:00
|
|
|
(def-project-type! electron "electron"
|
2016-04-19 02:41:34 -04:00
|
|
|
:modes (nodejs-project-mode)
|
2016-05-20 16:55:32 -04:00
|
|
|
:files ("app/index.html" "app/main.js")
|
|
|
|
:when
|
|
|
|
(lambda (&rest _)
|
|
|
|
(awhen (gethash (narf/project-root) npm-conf)
|
|
|
|
(let ((deps (append (car-safe (assq 'dependencies it))
|
|
|
|
(car-safe (assq 'devDependencies it)))))
|
|
|
|
(or (assq 'electron-prebuilt deps)
|
|
|
|
(assq 'electron-packager deps)
|
|
|
|
(string-prefix-p "electron" (or (assq 'start it) "") t))))))
|
|
|
|
|
|
|
|
(def-project-type! reactjs "react"
|
|
|
|
:modes (nodejs-project-mode bower-project-mode)
|
|
|
|
:when
|
|
|
|
(lambda (&rest _)
|
|
|
|
(let* ((project (narf/project-root))
|
|
|
|
(deps (append (cdr-safe (assq 'dependencies (gethash project bower-conf)))
|
|
|
|
(cdr-safe (assq 'dependencies (gethash project npm-conf))))))
|
|
|
|
(assq 'react deps))))
|
2016-04-19 02:41:34 -04:00
|
|
|
|
2016-04-16 21:36:24 -04:00
|
|
|
;; TODO react
|
|
|
|
|
2015-06-15 09:06:10 +02:00
|
|
|
(provide 'module-js)
|
|
|
|
;;; module-js.el ends here
|