[typescript] Restore format bindings for typescript-tsx-mode
This commit is contained in:
parent
b3992c61ef
commit
37008c07c4
2 changed files with 24 additions and 22 deletions
|
@ -109,7 +109,7 @@
|
|||
(call-interactively 'prettier-js))
|
||||
(t (error (concat "%s isn't valid typescript-fmt-tool value."
|
||||
" It should be 'tide, 'typescript-formatter or 'prettier.")
|
||||
(symbol-name typescript-fmt-tool)))))
|
||||
(symbol-name typescript-fmt-tool)))))
|
||||
|
||||
(defun spacemacs/typescript-fmt-before-save-hook ()
|
||||
(add-hook 'before-save-hook 'spacemacs/typescript-format t t))
|
||||
|
@ -139,3 +139,17 @@
|
|||
(defun spacemacs//typescript-setup-checkers ()
|
||||
(when-let* ((found (executable-find "eslint_d")))
|
||||
(set (make-local-variable 'flycheck-javascript-eslint-executable) found)))
|
||||
|
||||
(defun spacemacs/typescript-mode-init (hook)
|
||||
(add-hook hook 'spacemacs//typescript-setup-backend)
|
||||
(when typescript-fmt-on-save
|
||||
(add-hook hook 'spacemacs/typescript-fmt-before-save-hook)))
|
||||
|
||||
(defun spacemacs/typescript-mode-config (mode)
|
||||
(spacemacs/set-leader-keys-for-major-mode mode
|
||||
"p" 'spacemacs/typescript-open-region-in-playground)
|
||||
(pcase (spacemacs//typescript-backend)
|
||||
('lsp (spacemacs/set-leader-keys-for-major-mode mode
|
||||
"==" 'spacemacs/typescript-format))
|
||||
(_ (spacemacs/set-leader-keys-for-major-mode mode
|
||||
"=" 'spacemacs/typescript-format))))
|
||||
|
|
|
@ -92,36 +92,24 @@
|
|||
(spacemacs/add-to-hooks #'smartparens-mode '(typescript-mode-hook
|
||||
typescript-tsx-mode-hook))))
|
||||
|
||||
(defun typescript/post-init-web-mode ()
|
||||
(define-derived-mode typescript-tsx-mode web-mode "TypeScript-tsx")
|
||||
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)))
|
||||
|
||||
(defun typescript/post-init-yasnippet ()
|
||||
(spacemacs/add-to-hooks #'spacemacs/typescript-yasnippet-setup '(typescript-mode-hook
|
||||
typescript-tsx-mode-hook)))
|
||||
|
||||
(defun typescript/post-init-web-mode ()
|
||||
(define-derived-mode typescript-tsx-mode web-mode "TypeScript-tsx")
|
||||
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode))
|
||||
(spacemacs/typescript-mode-init 'typescript-tsx-mode-local-vars-hook)
|
||||
(spacemacs/typescript-mode-config 'typescript-tsx-mode))
|
||||
|
||||
(defun typescript/init-typescript-mode ()
|
||||
(use-package typescript-mode
|
||||
:defer t
|
||||
:init
|
||||
(progn
|
||||
(let ((hooks '(typescript-mode-local-vars-hook typescript-tsx-mode-local-vars-hook)))
|
||||
(dolist (hook hooks)
|
||||
(add-hook hook 'spacemacs//typescript-setup-backend)
|
||||
(when typescript-fmt-on-save
|
||||
(add-hook hook 'spacemacs/typescript-fmt-before-save-hook))))
|
||||
(spacemacs/typescript-safe-local-variables '(lsp tide)))
|
||||
:config
|
||||
(progn
|
||||
(let ((modes '(typescript-mode typescript-tsx-mode)))
|
||||
(dolist (mode modes)
|
||||
(spacemacs/set-leader-keys-for-major-mode mode
|
||||
"p" 'spacemacs/typescript-open-region-in-playground)
|
||||
(pcase (spacemacs//typescript-backend)
|
||||
('lsp (spacemacs/set-leader-keys-for-major-mode mode
|
||||
"==" 'spacemacs/typescript-format))
|
||||
(_ (spacemacs/set-leader-keys-for-major-mode mode
|
||||
"=" 'spacemacs/typescript-format))))))))
|
||||
(spacemacs/typescript-safe-local-variables '(lsp tide))
|
||||
(spacemacs/typescript-mode-init 'typescript-mode-local-vars-hook))
|
||||
:config (spacemacs/typescript-mode-config 'typescript-mode)))
|
||||
|
||||
(defun typescript/pre-init-import-js ()
|
||||
(if (eq javascript-import-tool 'import-js)
|
||||
|
|
Reference in a new issue