2019-01-13 20:33:17 +01:00
|
|
|
;; wpc-javascript.el --- My Javascript preferences -*- lexical-binding: t -*-
|
2018-04-25 19:26:53 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; This module hosts my Javascript tooling preferences
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; Constants
|
|
|
|
(defconst wpc/js-hooks
|
2018-09-10 20:51:14 +02:00
|
|
|
'(js-mode-hook js2-mode-hook rjsx-mode-hook)
|
2018-09-04 20:55:41 +02:00
|
|
|
"All of the commonly used hooks for Javascript buffers.")
|
|
|
|
|
|
|
|
(defconst wpc/frontend-hooks
|
|
|
|
(-insert-at 0 'css-mode-hook wpc/js-hooks)
|
|
|
|
"All of the commonly user hooks for frontend development.")
|
2018-04-25 19:26:53 +02:00
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
|
|
|
|
;; Helper functions
|
2018-04-25 19:26:53 +02:00
|
|
|
(defun wpc/insert-flow-annotation ()
|
|
|
|
"Insert a flow type annotation to the beginning of a buffer."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert "// @flow\n")))
|
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; frontend indentation settings
|
|
|
|
(setq js-indent-level 2
|
|
|
|
css-indent-offset 2)
|
|
|
|
|
2018-04-25 19:26:53 +02:00
|
|
|
;; ;; javascript
|
|
|
|
;; (evil-leader/set-key-for-mode 'rjsx-mode "t" #'wpc/toggle-between-js-test-and-module)
|
|
|
|
;; (evil-leader/set-key-for-mode 'rjsx-mode "x" #'wpc/toggle-between-js-component-and-store)
|
|
|
|
;; (evil-leader/set-key-for-mode 'rjsx-mode "u" #'wpc/jump-to-parent-file)
|
|
|
|
|
|
|
|
;; Flow for Javascript
|
2018-09-10 20:51:14 +02:00
|
|
|
(use-package add-node-modules-path
|
|
|
|
:config
|
|
|
|
(general-add-hook wpc/js-hooks #'add-node-modules-path))
|
|
|
|
|
2018-04-25 19:26:53 +02:00
|
|
|
(use-package flow-minor-mode
|
|
|
|
:requires evil-leader
|
|
|
|
:config
|
2018-09-10 20:51:14 +02:00
|
|
|
(general-add-hook wpc/js-hooks #'flow-minor-mode)
|
2018-04-25 19:26:53 +02:00
|
|
|
(evil-leader/set-key-for-mode 'rjsx-mode "F" #'wpc/insert-flow-annotation))
|
|
|
|
|
2019-01-13 20:33:17 +01:00
|
|
|
(use-package web-mode
|
|
|
|
:mode "\\.html\\'"
|
|
|
|
:config
|
|
|
|
(setq web-mode-css-indent-offset 2)
|
|
|
|
(setq web-mode-code-indent-offset 2)
|
|
|
|
(setq web-mode-markup-indent-offset 2))
|
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; Shouldn't need this once LSP is setup properly
|
|
|
|
;; (use-package company-flow
|
|
|
|
;; :after (company)
|
|
|
|
;; :config
|
|
|
|
;; (add-to-list 'company-flow-modes 'rjsx-mode)
|
|
|
|
;; (add-to-list 'company-backends 'company-flow))
|
2018-04-25 19:26:53 +02:00
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; Shouldn't need this once LSP is setup properly
|
|
|
|
;; (use-package flycheck-flow
|
|
|
|
;; :after (flycheck)
|
|
|
|
;; :config
|
|
|
|
;; (flycheck-add-mode 'javascript-flow 'rjsx-mode)
|
|
|
|
;; (flycheck-add-mode 'javascript-flow 'flow-minor-mode)
|
|
|
|
;; (flycheck-add-mode 'javascript-eslint 'flow-minor-mode)
|
|
|
|
;; (flycheck-add-next-checker 'javascript-flow 'javascript-eslint))
|
2018-04-25 19:26:53 +02:00
|
|
|
|
|
|
|
;; JSX highlighting
|
|
|
|
(use-package rjsx-mode
|
|
|
|
:mode "\\.js\\'"
|
|
|
|
:config
|
2019-01-13 20:33:17 +01:00
|
|
|
(general-unbind rjsx-mode-map "<" ">" "C-d")
|
|
|
|
(general-nmap
|
|
|
|
:keymaps 'rjsx-mode-map
|
|
|
|
"K" #'flow-minor-type-at-pos)
|
2018-04-25 19:26:53 +02:00
|
|
|
(setq js2-mode-show-parse-errors nil
|
|
|
|
js2-mode-show-strict-warnings nil))
|
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; JS autoformatting
|
|
|
|
(use-package prettier-js
|
|
|
|
:after (rjsx-mode)
|
|
|
|
:config
|
|
|
|
(general-add-hook wpc/frontend-hooks #'prettier-js-mode))
|
|
|
|
|
2018-04-25 19:26:53 +02:00
|
|
|
(provide 'wpc-javascript)
|
|
|
|
;;; wpc-javascript.el ends here
|