From f96c176dab750890ad7c2041c8f5f3b07606d04a Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Fri, 10 Nov 2023 14:49:49 +0000 Subject: [PATCH] Preliminary tree sitter support Add new rustic-ts-mode that extends rust-ts-mode. Add new option rustic-prefer-ts Ensure auto-mode-alist is set appropriately --- rustic.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rustic.el b/rustic.el index c3c58f3e..fd41b928 100644 --- a/rustic.el +++ b/rustic.el @@ -118,6 +118,9 @@ this variable." :type 'function :group 'rustic) +(defcustom rustic-prefer-ts nil + "If non-nil, prefer the tree-sitter derived mode.") + ;;; Mode (defvar rustic-mode-map @@ -163,13 +166,28 @@ this variable." (add-hook 'lsp-after-diagnostics-hook 'rustic-cargo-add-missing-dependencies-hook nil t))) ;;;###autoload -(add-to-list 'auto-mode-alist '("\\.rs\\'" . rustic-mode)) +(when (fboundp 'rust-ts-mode) + (define-derived-mode rustic-ts-mode rust-ts-mode "Rustic-ts" + "Major mode for Rust code, using tree-sitter." + :group)) 'rustic + + +;;;###autoload +(add-to-list 'auto-mode-alist + `("\\.rs\\'" . + ,(if (and (fboundp 'rustic-ts-mode) rustic-prefer-ts) + 'rustic-ts-mode + 'rustic-mode))) ;; remove rust-mode from `auto-mode-alist' (let ((mode '("\\.rs\\'" . rust-mode))) (when (member mode auto-mode-alist) (setq auto-mode-alist (remove mode auto-mode-alist)))) +(let ((mode '("\\.rs\\'" . rust-ts-mode))) + (when (member mode auto-mode-alist) + (setq auto-mode-alist (remove mode auto-mode-alist)))) + ;;; envrc support ;; To support envrc, it is necessary to wrap any buffer creation code