From e9ea75243035c3837bec904191d11dd89ca1c330 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Mon, 16 Jan 2023 00:25:35 +0800 Subject: [PATCH] use typescript-ts-mode and tsx-ts-mode at first --- .gitmodules | 16 ++++---- lisp/init-awesome-pair.el | 5 ++- lisp/init-eglot.el | 6 ++- lisp/init-flymake.el | 5 ++- lisp/init-prettier.el | 5 ++- lisp/init-typescript.el | 37 ++++++++++--------- {site-lisp => optional-pkg}/elisp-tree-sitter | 0 {site-lisp => optional-pkg}/tree-sitter-langs | 0 {site-lisp => optional-pkg}/tsi | 0 {site-lisp => optional-pkg}/typescript | 0 10 files changed, 45 insertions(+), 29 deletions(-) rename {site-lisp => optional-pkg}/elisp-tree-sitter (100%) rename {site-lisp => optional-pkg}/tree-sitter-langs (100%) rename {site-lisp => optional-pkg}/tsi (100%) rename {site-lisp => optional-pkg}/typescript (100%) diff --git a/.gitmodules b/.gitmodules index 5427857..addd10b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -88,17 +88,17 @@ [submodule "site-lisp/editorconfig-emacs"] path = site-lisp/editorconfig-emacs url = https://github.com/editorconfig/editorconfig-emacs.git -[submodule "site-lisp/typescript"] - path = site-lisp/typescript +[submodule "optional-pkg/typescript"] + path = optional-pkg/typescript url = https://github.com/emacs-typescript/typescript.el.git -[submodule "site-lisp/elisp-tree-sitter"] - path = site-lisp/elisp-tree-sitter +[submodule "optional-pkg/elisp-tree-sitter"] + path = optional-pkg/elisp-tree-sitter url = https://github.com/emacs-tree-sitter/elisp-tree-sitter.git -[submodule "site-lisp/tree-sitter-langs"] - path = site-lisp/tree-sitter-langs +[submodule "optional-pkg/tree-sitter-langs"] + path = optional-pkg/tree-sitter-langs url = https://github.com/emacs-tree-sitter/tree-sitter-langs.git -[submodule "site-lisp/tsi"] - path = site-lisp/tsi +[submodule "optional-pkg/tsi"] + path = optional-pkg/tsi url = https://github.com/orzechowskid/tsi.el.git [submodule "site-lisp/prettier"] path = site-lisp/prettier diff --git a/lisp/init-awesome-pair.el b/lisp/init-awesome-pair.el index 373c888..1332265 100644 --- a/lisp/init-awesome-pair.el +++ b/lisp/init-awesome-pair.el @@ -55,7 +55,10 @@ (defun creature/awesome-pair-kill () (interactive) - (cond ((and (derived-mode-p 'js-mode 'typescript-mode 'web-mode) + (cond ((and (derived-mode-p 'js-mode + 'typescript-mode + 'typescript-ts-base-mode + 'web-mode) (creature/awesome-pair-in-template-string-p) (awesome-pair-in-curly-p)) (creature/awesome-pair-kill-template-string-curly-content)) diff --git a/lisp/init-eglot.el b/lisp/init-eglot.el index 3113132..2562243 100644 --- a/lisp/init-eglot.el +++ b/lisp/init-eglot.el @@ -21,7 +21,11 @@ (unless (derived-mode-p 'js-json-mode 'json-mode) (eglot-ensure)))) -(dolist (hook '(css-mode-hook typescript-mode-hook c-mode-hook c++-mode-hook)) +(dolist (hook '(css-mode-hook + typescript-mode-hook + typescript-ts-base-mode-hook + c-mode-hook + c++-mode-hook)) (add-hook hook #'eglot-ensure)) diff --git a/lisp/init-flymake.el b/lisp/init-flymake.el index d2dbd14..d420add 100644 --- a/lisp/init-flymake.el +++ b/lisp/init-flymake.el @@ -33,7 +33,10 @@ (when (and flymake-mode (not creature/eslint-inited) - (derived-mode-p 'js-mode 'typescript-mode 'web-mode)) + (derived-mode-p 'js-mode + 'typescript-mode + 'typescript-ts-base-mode + 'web-mode)) ;; flymake-eslint-enable 内部会再次调用 (flymake-mode 1) ,为防止无限 ;; 循环调用,用 ‘creature/eslint-inited’ 记录该函数调用状态避免多次调用 diff --git a/lisp/init-prettier.el b/lisp/init-prettier.el index fd042fc..ecb54e0 100644 --- a/lisp/init-prettier.el +++ b/lisp/init-prettier.el @@ -21,7 +21,10 @@ (add-to-list 'prettier-major-mode-parsers '(js-json-mode . creature/prettier-json-parser))) -(dolist (hook '(css-mode-hook js-mode-hook typescript-mode-hook)) +(dolist (hook '(css-mode-hook + js-mode-hook + typescript-mode-hook + typescript-ts-base-mode-hook)) (add-hook hook #'prettier-mode)) (provide 'init-prettier) diff --git a/lisp/init-typescript.el b/lisp/init-typescript.el index f67fa2e..72c3450 100644 --- a/lisp/init-typescript.el +++ b/lisp/init-typescript.el @@ -1,24 +1,27 @@ ;; -*- coding: utf-8; lexical-binding: t; -*- -(require 'typescript-mode) +(unless (and (fboundp 'treesit-available-p) (treesit-available-p)) + (add-subdirs-to-load-path (expand-file-name "optional-pkg" creature/config-dir)) + (require 'typescript-mode) + + (define-derived-mode typescript-tsx-mode typescript-mode "Tsx" + "Major mode for editing TSX file." + (require 'tree-sitter) + (require 'tree-sitter-hl) + (require 'tree-sitter-langs) + (require 'tree-sitter-debug) + (require 'tree-sitter-query) + + (require 'tsi-typescript) + (tsi-typescript-mode)) + + (add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)) + + (with-eval-after-load 'tree-sitter-langs + (tree-sitter-require 'tsx) + (add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx)))) -(define-derived-mode typescript-tsx-mode typescript-mode "Tsx" - "Major mode for editing TSX file." - (require 'tree-sitter) - (require 'tree-sitter-hl) - (require 'tree-sitter-langs) - (require 'tree-sitter-debug) - (require 'tree-sitter-query) - - (require 'tsi-typescript) - (tsi-typescript-mode)) - -(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)) - -(with-eval-after-load 'tree-sitter-langs - (tree-sitter-require 'tsx) - (add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx))) (provide 'init-typescript) diff --git a/site-lisp/elisp-tree-sitter b/optional-pkg/elisp-tree-sitter similarity index 100% rename from site-lisp/elisp-tree-sitter rename to optional-pkg/elisp-tree-sitter diff --git a/site-lisp/tree-sitter-langs b/optional-pkg/tree-sitter-langs similarity index 100% rename from site-lisp/tree-sitter-langs rename to optional-pkg/tree-sitter-langs diff --git a/site-lisp/tsi b/optional-pkg/tsi similarity index 100% rename from site-lisp/tsi rename to optional-pkg/tsi diff --git a/site-lisp/typescript b/optional-pkg/typescript similarity index 100% rename from site-lisp/typescript rename to optional-pkg/typescript