lang/javascript: update for v2.0

This commit is contained in:
Henrik Lissner 2017-01-16 23:30:37 -05:00
parent cea32a3957
commit 566fd39cf9
5 changed files with 90 additions and 202 deletions

View file

@ -1,50 +1,25 @@
HOSTNAME=`emacs --batch --eval '(message "%s" (system-name))' 2>&1`
EMACS=emacs
CACHE_DIR="private/cache/$(HOSTNAME)/"
REPO_URL="https://github.com/hlissner"
CACHE_DIR=""
all: install
all: install update
# If you run either of these with emacs open, run doom-reload afterwards
install: _install core/core.elc init.elc autoloads
update: _update core/core.elc init.elc autoloads
install: autoloads
@$(EMACS) -Q --batch --eval '(setq use-package-always-ensure t)' -l init.el
update: autoloads
@$(EMACS) -Q --batch -l init.el -f 'doom/packages-update'
autoloads:
@$(EMACS) --batch -l init.el --eval '(doom-reload-autoloads)' 2>&1
@$(EMACS) -Q --batch -l init.el -f 'doom/refresh-autoloads'
compile: clean
@$(EMACS) --batch -l init.el --eval '(doom-byte-compile t)' 2>&1
compile:
@$(EMACS) -Q --batch -l init.el -f 'doom/byte-compile'
snippets:
@[ -d private/snippets ] || git clone $(REPO_URL)/emacs-snippets private/snippets
clean: clean-elc
@$(EMACS) -Q --batch -l init.el -f 'doom/packages-clean'
clean:
@rm -rf auto-save-list recentf places ido.last async-bytecomp.log elpa tramp
@rm -rf projectile-bookmarks.eld projectile.cache company-statistics-cache.el
@rm -rf var semanticdb anaconda-mode
@rm -f *.elc {core,modules,private,contrib}/*.elc {core,modules}/defuns/*.elc
clean-elc:
@rm -fv init.elc
@find {core,modules} -type f -iname '*.elc' -exec rm \-fv {} \;
clean-cache:
@find $(CACHE_DIR) -type f -maxdepth 1 -delete
@rm -f $(CACHE_DIR)/{workgroups,pcache,ltxpng,backup}/*
clean-lite:
@rm -f init.elc core/core.elc
test:
@cask exec ert-runner -l core/core.el
########################################
%.elc: %.el
@$(EMACS) --batch -l init.el -f batch-byte-compile 2>&1 $<
_update: clean-lite
@cask update 2>&1
_install: clean-lite
@cask install 2>&1
@mkdir -p $(CACHE_DIR)/{undo,backup,workgroups}
.PHONY: all test
.PHONY: all

View file

@ -165,7 +165,7 @@
"REACTIONS" "BODYPARTS_ALL" "RESOURCES_ALL" "COLORS_ALL"))
(def-project-type! screeps "screeps"
(project! screeps "screeps"
:match "/screeps/.+$"
:modes (nodejs-project-mode))
@ -174,5 +174,3 @@
(add-to-list 'flycheck-disabled-checkers 'javascript-jshint)
(setq js2-additional-externs (append '("_") screeps-objects screeps-constants))))
(provide 'custom-screeps)
;;; custom-screeps.el ends here

View file

@ -0,0 +1,7 @@
;;; autoload.el --- description
;;;###autoload
(defun +js-fake-fun ())
(provide 'autoload)
;;; autoload.el ends here

View file

@ -1,169 +1,64 @@
;;; module-js.el
;;; config.el
(use-package unityjs-mode
:mode "/Assets/.*\\.js$"
:config (add-hook 'unityjs-mode-hook 'flycheck-mode))
(config! js2-mode
(add-hook! '(tern-mode flycheck-mode highlight-indent-guides-mode))
(use-package js2-mode
:mode "\\.js$"
:interpreter "node"
:init (add-hook! js2-mode '(tern-mode flycheck-mode))
:config
(def-repl! js2-mode nodejs-repl)
(def-company-backend! js2-mode (tern))
(def-docset! js2-mode "js,jquery,nodejs,angularjs,express")
(def-electric! js2-mode :chars (?\} ?\) ?.) :words ("||" "&&"))
(setq-default
js2-skip-preprocessor-directives t
js2-highlight-external-variables nil
js2-mode-show-parse-errors nil)
;; NOTE Do indentation settings after editorconfig has done its thing
(add-hook! (setq js-switch-indent-offset js-indent-level))
(add-hook! lb6-project-mode
(when (eq major-mode 'js2-mode)
(setq js2-additional-externs '("LaunchBar" "File" "Action" "HTTP" "include" "Lib"))))
(setq js2-skip-preprocessor-directives t
js2-highlight-external-variables nil
js2-mode-show-parse-errors nil)
;; [pedantry intensifies]
(add-hook! js2-mode (setq mode-name "JS2"
js-switch-indent-offset js-indent-level))
;;
(set! :repl nodejs-repl
:company-backends (tern)
:electric (?\} ?\) ?. "||" "&&")
:map (:localleader :nv ";" 'doom/append-semicolon)
:emr ((:v js2r-extract-function "extract function")
(:v js2r-extract-method "extract method")
(:v js2r-introduce-parameter "introduce parameter")
(:n js2r-localize-parameter "localize parameter")
(:n js2r-expand-object "expand object")
(:n js2r-contract-object "contract object")
(:n js2r-expand-function "expand function")
(:n js2r-contract-function "contract function")
(:n js2r-expand-array "expand array")
(:n js2r-contract-array "contract array")
(:n js2r-wrap-buffer-in-iife "wrap buffer in ii function")
(:v js2r-inject-global-in-iife "inject global in ii function")
(:n js2r-add-to-globals-annotation "add to globals annotation")
(:v js2r-extract-var "extract variable")
(:v js2r-inline-var "inline variable")
(:n js2r-rename-var "rename variable")
(:n js2r-var-to-this "var to this")
(:n js2r-arguments-to-object "arguments to object")
(:n js2r-ternary-to-if "ternary to if")
(:n js2r-split-var-declaration "split var declaration")
(:n js2r-split-string "split string")
(:v js2r-unwrap "unwrap")
(:nv js2r-log-this "log this")
(:nv js2r-debug-this "debug this")
(:n js2r-forward-slurp "forward slurp")
(:n js2r-forward-barf "forward barf"))))
(map! :map js2-mode-map (:localleader :nv ";" 'doom/append-semicolon)))
(config! coffee-mode
(setq-default coffee-indent-like-python-mode t))
(use-package tern
:after js2-mode
:commands (tern-mode))
(use-package company-tern
:after tern)
(use-package js2-refactor
:after js2-mode
:config
(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
(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))))
(use-package nodejs-repl :commands (nodejs-repl))
;;
(use-package jsx-mode :mode "\\.jsx$")
(use-package coffee-mode
:mode "\\.coffee$"
:config (setq-default coffee-indent-like-python-mode t))
(use-package typescript-mode
:mode "\\.ts$"
:init
(add-hook! typescript-mode
'(rainbow-delimiters-mode doom|ts-fontify)))
(use-package tide
:after typescript-mode
:config
(setq tide-format-options
'(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t
:placeOpenBraceOnNewLineForFunctions nil))
(defun doom|tide-setup ()
(tide-setup)
(flycheck-mode +1)
(eldoc-mode +1))
(add-hook 'typescript-mode-hook 'doom|tide-setup)
(add-hook! web-mode
(when (f-ext? buffer-file-name "tsx")
(doom|tide-setup)))
(map! :map typescript-mode-map
:m "gd" 'tide-jump-to-definition
(:leader :n "h" 'tide-documentation-at-point))
(advice-add 'tide-project-root :override 'doom/project-root))
;; Projects
;;
(defvar npm-conf (make-hash-table :test 'equal))
(def-project-type! nodejs "node"
:modes (web-mode js-mode coffee-mode css-mode sass-mode pug-mode)
(project! npm
:modes (web-mode js2-mode)
:files ("package.json")
:when
(lambda (&rest _)
(let* ((project-path (doom/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)
(ignore-errors (json-read-file package-file)))
(puthash project-path it npm-conf)))
t))
:config
(let* ((project-path (doom-project-root))
(hash (gethash project-path npm-conf))
(package-file (expand-file-name "package.json" project-path))
deps)
(when-let (json (and (not hash) (f-exists? package-file)
(ignore-errors (json-read-file package-file))))
(puthash project-path json npm-conf))))
(def-project-type! expressjs "express"
:modes (nodejs-project-mode bower-project-mode)
:when
(lambda (&rest _)
(awhen (gethash (doom/project-root) npm-conf)
(assq 'express (cdr-safe (assq 'dependencies it))))))
;; TODO electron-compile support
(def-project-type! electron "electron"
:modes (nodejs-project-mode)
:files ("app/index.html" "app/main.js")
:when
(lambda (&rest _)
(awhen (gethash (doom/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 (doom/project-root))
(deps (append (cdr-safe (assq 'dependencies (gethash project bower-conf)))
(cdr-safe (assq 'dependencies (gethash project npm-conf))))))
(assq 'react deps))))
(def-project-type! gulpjs "gulp"
:modes (nodejs-project-mode)
:files ("gulpfile.js")
:build ("gulp %s" "gulpfile.js"))
(provide 'module-js)
;;; module-js.el ends here

View file

@ -0,0 +1,13 @@
;;; lang/js/packages.el
(package! js2-mode :mode "\\.js$" :interpreter "node")
(package! jsx-mode :mode "\\.jsx$")
(package! coffee-mode :mode "\\.coffee$")
(package! tern :after js2-mode)
(package! company-tern :after js2-mode)
(package! js2-refactor :after js2-mode)