2020-08-31 15:19:14 +02:00
|
|
|
;;; wpc-javascript.el --- My Javascript preferences -*- lexical-binding: t -*-
|
|
|
|
|
2018-04-25 19:26:53 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-08-31 15:19:14 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; Package-Requires: ((emacs "24"))
|
2018-04-25 19:26:53 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
2019-12-22 22:28:01 +01:00
|
|
|
;; This module hosts my Javascript tooling preferences. This also includes
|
|
|
|
;; tooling for TypeScript and other frontend tooling. Perhaps this module will
|
|
|
|
;; change names to more accurately reflect that.
|
2019-10-09 13:13:56 +02:00
|
|
|
;;
|
|
|
|
;; Depends
|
|
|
|
;; - yarn global add prettier
|
2018-04-25 19:26:53 +02:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2020-01-20 13:11:46 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2020-09-02 16:01:43 +02:00
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'general)
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2020-01-20 13:11:46 +01:00
|
|
|
;; Configuration
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; Constants
|
2020-08-31 15:19:14 +02:00
|
|
|
(defconst wpc-javascript--js-hooks
|
2020-08-31 18:20:04 +02:00
|
|
|
'(js-mode-hook
|
|
|
|
web-mode-hook
|
|
|
|
typescript-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.")
|
|
|
|
|
2020-08-31 15:19:14 +02:00
|
|
|
(defconst wpc-javascript--frontend-hooks
|
|
|
|
(-insert-at 0 'css-mode-hook wpc-javascript--js-hooks)
|
2018-09-04 20:55:41 +02:00
|
|
|
"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
|
|
|
;; frontend indentation settings
|
2019-12-22 22:28:01 +01:00
|
|
|
(setq typescript-indent-level 2
|
|
|
|
js-indent-level 2
|
2018-09-04 20:55:41 +02:00
|
|
|
css-indent-offset 2)
|
|
|
|
|
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-04-25 19:26:53 +02:00
|
|
|
;; JSX highlighting
|
|
|
|
(use-package rjsx-mode
|
|
|
|
: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))
|
|
|
|
|
2019-12-22 22:28:01 +01:00
|
|
|
(progn
|
2020-08-31 15:19:14 +02:00
|
|
|
(defun wpc-javascript-tide-setup ()
|
2019-12-22 22:28:01 +01:00
|
|
|
(interactive)
|
|
|
|
(tide-setup)
|
|
|
|
(flycheck-mode 1)
|
|
|
|
(setq flycheck-check-syntax-automatically '(save mode-enabled))
|
|
|
|
(eldoc-mode 1)
|
|
|
|
(tide-hl-identifier-mode 1)
|
|
|
|
(company-mode 1))
|
|
|
|
(use-package tide
|
|
|
|
:config
|
2020-08-31 15:19:14 +02:00
|
|
|
(add-hook 'typescript-mode-hook #'wpc-javascript-tide-setup))
|
2019-12-22 22:28:01 +01:00
|
|
|
(require 'web-mode)
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
|
|
|
|
(add-hook 'web-mode-hook
|
|
|
|
(lambda ()
|
|
|
|
(when (string-equal "tsx" (f-ext buffer-file-name))
|
2020-08-31 15:19:14 +02:00
|
|
|
(wpc-javascript-tide-setup))))
|
2019-12-22 22:28:01 +01:00
|
|
|
(flycheck-add-mode 'typescript-tslint 'web-mode))
|
|
|
|
|
2018-09-04 20:55:41 +02:00
|
|
|
;; JS autoformatting
|
|
|
|
(use-package prettier-js
|
|
|
|
:config
|
2020-08-31 15:19:14 +02:00
|
|
|
(general-add-hook wpc-javascript--frontend-hooks #'prettier-js-mode))
|
2018-09-04 20:55:41 +02:00
|
|
|
|
2020-04-11 18:45:59 +02:00
|
|
|
;; Support Elm
|
2020-10-10 18:03:08 +02:00
|
|
|
(use-package elm-mode
|
|
|
|
:config
|
|
|
|
(add-hook 'elm-mode-hook #'elm-format-on-save-mode))
|
2020-04-11 18:45:59 +02:00
|
|
|
|
2018-04-25 19:26:53 +02:00
|
|
|
(provide 'wpc-javascript)
|
|
|
|
;;; wpc-javascript.el ends here
|