Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree-sitter support for Emacs 29+ #282

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
21 changes: 21 additions & 0 deletions er-basic-expansions.el
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,26 @@ period and marks next symbol."
er/mark-defun)
er/try-expand-list))

(when (and (>= emacs-major-version 29)
(treesit-available-p))
(defun er/mark-ts-node ()
"Mark tree sitter node around or after point."
(interactive)
(when (treesit-language-at (point))
(let* ((node (if (use-region-p)
(treesit-node-on (region-beginning) (region-end))
(treesit-node-at (point))))
(node-start (treesit-node-start node))
(node-end (treesit-node-end node)))
;; when the node fits the region exactly, try its parent node instead
(when (and (= (region-beginning) node-start)
(= (region-end) node-end))
(when-let ((node (treesit-node-parent node)))
(setq node-start (treesit-node-start node)
node-end (treesit-node-end node))))
(goto-char node-start)
(set-mark node-end))))
(setq er/try-expand-list (append er/try-expand-list '(er/mark-ts-node))))

(provide 'er-basic-expansions)
;;; er-basic-expansions.el ends here