doomemacs/modules/tools/tree-sitter/autoload.el
Jeetaditya Chatterjee 8e68cd5ffd feat(tree-sitter): conditionally enable ts-hl-mode
Based on the new variable `+tree-sitter-hl-enabled-modes`

This allows for people to use tree sitters tools without having
to use it for highlighting.
Useful because some modes (such as web-mode and its derivatives) do a
better job than the tree sitter alternative in this respect.
2022-08-08 18:37:20 +02:00

35 lines
1.5 KiB
EmacsLisp

;;; tools/tree-sitter/autoload.el -*- lexical-binding: t; -*-
;;;###autodef (fset 'tree-sitter! #'ignore)
(defun tree-sitter! ()
"Dispatch to turn on tree sitter.
Used as a hook function which turns on `tree-sitter-mode'
and selectively turn on `tree-sitter-hl-mode'.
according to `+tree-sitter-hl-enabled-modes'"
(turn-on-tree-sitter-mode)
;; conditionally enable `tree-sitter-hl-mode'
(let ((mode (bound-and-true-p tree-sitter-hl-mode)))
(when-let (mode (if (pcase +tree-sitter-hl-enabled-modes
(`(not . ,modes) (not (memq major-mode modes)))
((and `(,_ . ,_) modes) (memq major-mode modes))
(bool bool))
(unless mode +1)
(if mode -1)))
(tree-sitter-hl-mode mode))))
;; HACK: Remove and refactor when `use-package' eager macro expansion is solved or `use-package!' is removed
;;;###autoload
(defun +tree-sitter-get-textobj (group &optional query)
"A wrapper around `evil-textobj-tree-sitter-get-textobj' to
prevent eager expansion."
(eval `(evil-textobj-tree-sitter-get-textobj ,group ,query)))
;;;###autoload
(defun +tree-sitter-goto-textobj (group &optional previous end query)
"Thin wrapper that returns the symbol of a named function, used in keybindings."
(let ((sym (intern (format "+goto%s%s-%s" (if previous "-previous" "") (if end "-end" "") group))))
(fset sym (lambda ()
(interactive)
(evil-textobj-tree-sitter-goto-textobj group previous end query)))
sym))