doomemacs/modules/tools/tree-sitter/config.el
Jeetaditya Chatterjee 862e7980d8
module: add :tools tree-sitter
This module installs 'tree-sitter' and 'tree-sitter-langs' as well as
the 'evil-textobj-treesitter' and configures them.

This module is based on the prototype module that @hlissner has started
and I am just fleshing out that work.

It also comes with a README file

Fix: #4151
2022-05-22 21:25:57 +01:00

32 lines
1.5 KiB
EmacsLisp

;;; tools/tree-sitter/config.el -*- lexical-binding: t; -*-
(use-package! tree-sitter
:when (bound-and-true-p module-file-suffix)
:hook (prog-mode . tree-sitter-mode)
:hook (tree-sitter-after-on . tree-sitter-hl-mode)
:config
(require 'tree-sitter-langs)
(setq tree-sitter-debug-jump-buttons t
tree-sitter-debug-highlight-jump-region t)
(defadvice! doom-tree-sitter-fail-gracefully-a (orig-fn &rest args)
"Don't break with errors when current major mode lacks tree-sitter support."
:around #'tree-sitter-mode
(condition-case e
(apply orig-fn args)
(error
(unless (string-match-p (concat "^Cannot find shared library\\|"
"^No language registered\\|"
"cannot open shared object file")
(error-message-string e))
(signal (car e) (cadr e)))))))
(use-package! evil-textobj-tree-sitter
:after tree-sitter
:config
(map!
:textobj "f" (evil-textobj-tree-sitter-get-textobj "function.inner") (evil-textobj-tree-sitter-get-textobj "function.outer") ;; redef
:textobj "C" (evil-textobj-tree-sitter-get-textobj "class.inner") (evil-textobj-tree-sitter-get-textobj "class.outer")
:textobj "c" nil (evil-textobj-tree-sitter-get-textobj "comment.outer")
:textobj "i" (evil-textobj-tree-sitter-get-textobj "conditional.inner") (evil-textobj-tree-sitter-get-textobj "conditional.outer")
:textobj "l" (evil-textobj-tree-sitter-get-textobj "loop.inner") (evil-textobj-tree-sitter-get-textobj "loop.outer")))