emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tree-sitter integration on feature/tree-sitter


From: Theodor Thornhill
Subject: Re: Tree-sitter integration on feature/tree-sitter
Date: Mon, 09 May 2022 23:33:49 +0200

>
> I have some comments below, I haven’t tested the patch yet.
>

Thank you!

> +(defvar js-treesit-font-lock-settings-1
> +  '((javascript
> +     (
> +      ((identifier) @font-lock-constant-face
> +       (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face))
>
> I would use treesit-expand-query to “expand” the sexp query to string,
> so Emacs don’t need to re-expand it every time treesit-query-capture
> is called. I don’t know how much it speed things up, but hey its free.
>

Great, I did not know of this.  I'll try it out.

> +(defun js-treesit-move-to-node (fn)
> +  (when-let ((found-node (treesit-parent-until
> +                          (treesit-node-at (point) (point) 'javascript)
> +                          (lambda (parent)
> +                            (let ((parent-type (treesit-node-type parent)))
> +                              (or (equal "function_declaration" parent-type)
> +                                  ;;; More declarations here
> +                                  ))))))
> +    (goto-char (funcall fn found-node))))
> +
> +(defun js-treesit-beginning-of-defun (&optional arg)
> +  (js-treesit-move-to-node #'treesit-node-start))
> +
> +(defun js-treesit-end-of-defun (&optional arg)
> +  (js-treesit-move-to-node #'treesit-node-end))
>
> Maybe I could extract this into treesit.el, so major modes can specify
> simply the node name for a function definition and get function
> traversal for free.
>

Yeah!  My plan was to use `M-a` and `M-e` for siblings and `C-M-a` and
`C-M-e` for beginning/end-of-defun.  Some way of supplying "defun-nodes"
and make treesit handle the rest would be awesome.

> +(defcustom js-use-treesit-p nil
> +  "Use tree sitter for font locking, indentation and navigation"
> +  :version "29.1"
> +  :type 'boolean
> +  :safe 'booleanp)
>
> Maybe I should ditch treesit-disble-list and let major modes define
> their controlling variables like this?

Makes sense. The advantage with this is that you can decide more
granularly where you want to inject tree-sitter in the major mode
initialization phase, I guess?

>
> I also cc’d maintainer of js.el, since I don’t know anything about js.el.
>

Great!  I don't think this is "done", per se, but at least it is
something useful to look at, hopefully.

Theodor



reply via email to

[Prev in Thread] Current Thread [Next in Thread]