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
This commit is contained in:
parent
8a27eb99be
commit
862e7980d8
4 changed files with 152 additions and 0 deletions
55
modules/tools/tree-sitter/README.org
Normal file
55
modules/tools/tree-sitter/README.org
Normal file
|
@ -0,0 +1,55 @@
|
|||
#+TITLE: tools/tree-sitter
|
||||
#+DATE: August 17, 2021
|
||||
#+SINCE: 3.0.0
|
||||
#+STARTUP: inlineimages nofold
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#maintainers][Maintainers]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#plugins][Plugins]]
|
||||
- [[#hacks][Hacks]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#features][Features]]
|
||||
- [[#configuration][Configuration]]
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
|
||||
* Description
|
||||
Add [[https://tree-sitter.github.io/tree-sitter/][tree-sitter]] support to doom:
|
||||
|
||||
#+begin_quote
|
||||
Tree sitter is a parser generator tool and an incremental parsing library. It
|
||||
can build a concrete syntax tree for a source file and efficiently update the
|
||||
syntax tree as the source file is edited.
|
||||
#+end_quote
|
||||
|
||||
|
||||
+ include better syntax highlighting of supported code
|
||||
+ add structural text objects to manipulate functions statements and other code
|
||||
structures
|
||||
|
||||
** Maintainers
|
||||
- @jeetelongname
|
||||
|
||||
** Module Flags
|
||||
This module provides no flags.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/emacs-tree-sitter/elisp-tree-sitter][tree-sitter]]
|
||||
+ [[https://github.com/emacs-tree-sitter/tree-sitter-langs][tree-sitter-langs]]
|
||||
+ [[https://github.com/meain/evil-textobj-tree-sitter][evil-textobj-tree-sitter]]* (=:editor evil +everywhere=)
|
||||
|
||||
** TODO Hacks
|
||||
# A list of internal modifications to included packages; omit if unneeded
|
||||
|
||||
* Prerequisites
|
||||
This module has no prerequisites.
|
||||
|
||||
* TODO Features
|
||||
# An in-depth list of features, how to use them, and their dependencies.
|
||||
|
||||
* TODO Configuration
|
||||
# How to configure this module, including common problems and how to address them.
|
||||
|
||||
* TODO Troubleshooting
|
||||
# Common issues and their solution, or places to look for help.
|
32
modules/tools/tree-sitter/config.el
Normal file
32
modules/tools/tree-sitter/config.el
Normal file
|
@ -0,0 +1,32 @@
|
|||
;;; 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")))
|
13
modules/tools/tree-sitter/packages.el
Normal file
13
modules/tools/tree-sitter/packages.el
Normal file
|
@ -0,0 +1,13 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; tools/tree-sitter/packages.el
|
||||
|
||||
(package! tree-sitter
|
||||
;; :ignore (null (bound-and-true-p module-file-suffix))
|
||||
:pin "c7a1c34549cad41a3618c6f17e0e9dabd3e98fe1")
|
||||
(package! tree-sitter-langs
|
||||
;; :ignore (null (bound-and-true-p module-file-suffix))
|
||||
:pin "e7b8db7c4006c04a4bc1fc6865ec31f223843192")
|
||||
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
(package! evil-textobj-tree-sitter
|
||||
:pin "f20598676f99e6fa33759d9807e94f42271c0dfb"))
|
52
modules/tools/tree-sitter/test.js
Normal file
52
modules/tools/tree-sitter/test.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
// this is a test file i am useing to test functionallity with treesitter
|
||||
|
||||
// blocks
|
||||
x = 10
|
||||
|
||||
// calls
|
||||
call();
|
||||
|
||||
// class
|
||||
class Car {
|
||||
constructor(name, year) {
|
||||
this.name = name;
|
||||
this.year = year;
|
||||
}
|
||||
age(x) {
|
||||
return x - this.year;
|
||||
}
|
||||
}
|
||||
|
||||
// comments
|
||||
/*
|
||||
* multiline my dude
|
||||
* a poem
|
||||
* roses are red
|
||||
* violets are blue
|
||||
* there is a man behind you
|
||||
* and he had an axe with him to
|
||||
*/
|
||||
|
||||
|
||||
// conditional
|
||||
if (x == 1) {
|
||||
doStuff();
|
||||
} else {
|
||||
x = new Car.age(2020)
|
||||
}
|
||||
|
||||
|
||||
// function
|
||||
function name(arg) {
|
||||
doStuff(arg);
|
||||
}
|
||||
|
||||
const arrowFunc = arg => {
|
||||
dosStuff(arg);
|
||||
}
|
||||
|
||||
// loop
|
||||
for (let i = 0; i <= 10; i++) {
|
||||
doStuff(i);
|
||||
}
|
||||
// param
|
Loading…
Add table
Add a link
Reference in a new issue