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: Yuan Fu
Subject: Re: Tree-sitter integration on feature/tree-sitter
Date: Mon, 9 May 2022 14:10:36 -0700


> On May 9, 2022, at 5:23 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: monnier@iro.umontreal.ca, casouri@gmail.com, emacs-devel@gnu.org
>> Date: Mon, 09 May 2022 14:20:13 +0200
>> 
>> Did you get to look at the patch I sent? Should these efforts, when
>> their form is discovered be applied to this branch going forward? Or
>> should we wait until it lands on master?  I can look into more modes,
>> like css and others, but I'm a little wary of touching C, as they have a
>> lot of lineage and opinions and isn't my expertise.
>> 
>> Also I'm sure that bugs will be found when it is used, so I'm in favour
>> of applying the modes to this branch, if only to discover how best to
>> use tree sitter.
> 
> I'll leave it to Yuan's decision.  I didn't yet have time to build the
> branch, and without that I don't want to apply changes I cannot test.
> 
> Thanks.

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

+(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.

+(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.

+(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?

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

Yuan


reply via email to

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