Skip to content

Commit

Permalink
Preliminary tree sitter support
Browse files Browse the repository at this point in the history
Add new rustic-ts-mode that extends rust-ts-mode.
Add new option rustic-prefer-ts
Ensure auto-mode-alist is set appropriately
  • Loading branch information
phillord committed Nov 10, 2023
1 parent 39423d1 commit f96c176
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion rustic.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f96c176

Please sign in to comment.