Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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