emacs-diffs
[Top][All Lists]
Advanced

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

feature/tree-sitter f46eb3d3ca 2/2: Byte-compile treesit-simple-indent-p


From: Yuan Fu
Subject: feature/tree-sitter f46eb3d3ca 2/2: Byte-compile treesit-simple-indent-presets
Date: Fri, 28 Oct 2022 22:24:06 -0400 (EDT)

branch: feature/tree-sitter
commit f46eb3d3ca759ab3944cedda1339a6d1760298cd
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Byte-compile treesit-simple-indent-presets
    
    * lisp/treesit.el (treesit-simple-indent-presets): Byte-compile these
    functions.
---
 lisp/treesit.el | 213 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 115 insertions(+), 98 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 9c4d453534..264935f185 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -696,114 +696,131 @@ For MATCHER and ANCHOR, Emacs provides some convenient 
presets.
 See `treesit-simple-indent-presets'.")
 
 (defvar treesit-simple-indent-presets
-  '((match . (lambda
-               (&optional node-type parent-type node-field
-                          node-index-min node-index-max)
-               `(lambda (node parent bol &rest _)
-                  (and (or (null ,node-type)
-                           (string-match-p
-                            ,node-type (or (treesit-node-type node) "")))
-                       (or (null ,parent-type)
-                           (string-match-p
-                            ,parent-type (treesit-node-type parent)))
-                       (or (null ,node-field)
-                           (string-match-p
-                            ,node-field
-                            (or (treesit-node-field-name node) "")))
-                       (or (null ,node-index-min)
-                           (>= (treesit-node-index node t)
-                               ,node-index-min))
-                       (or (null ,node-index-max)
-                           (<= (treesit-node-index node t)
-                               ,node-index-max))))))
-    ;; TODO: Document if genuinely useful.
-    (n-p-gp . (lambda (node-t parent-t grand-parent-t)
-                `(lambda (node parent bol &rest _)
-                   (and (or (null ,node-t)
+  `((match . ,(byte-compile
+               (lambda
+                 (&optional node-type parent-type node-field
+                            node-index-min node-index-max)
+                 (lambda (node parent &rest _)
+                   (and (or (null node-type)
                             (string-match-p
-                             ,node-t (or (treesit-node-type node) "")))
-                        (or (null ,parent-t)
+                             node-type (or (treesit-node-type node) "")))
+                        (or (null parent-type)
                             (string-match-p
-                             ,parent-t (treesit-node-type parent)))
-                        (or (null ,grand-parent-t)
+                             parent-type (treesit-node-type parent)))
+                        (or (null node-field)
                             (string-match-p
-                             ,grand-parent-t
-                             (treesit-node-type
-                              (treesit-node-parent parent))))))))
-    (no-node . (lambda (node parent bol &rest _) (null node)))
-    (parent-is . (lambda (type)
-                   `(lambda (node parent bol &rest _)
-                      (string-match-p
-                       ,type (treesit-node-type parent)))))
-
-    (node-is . (lambda (type)
-                 `(lambda (node parent bol &rest _)
-                    (string-match-p
-                     ,type (or (treesit-node-type node) "")))))
-    (field-is . (lambda (name)
-                  `(lambda (node parent bol &rest _)
+                             node-field
+                             (or (treesit-node-field-name node) "")))
+                        (or (null node-index-min)
+                            (>= (treesit-node-index node t)
+                                node-index-min))
+                        (or (null node-index-max)
+                            (<= (treesit-node-index node t)
+                                node-index-max)))))))
+    ;; TODO: Document if genuinely useful.
+    (n-p-gp . ,(byte-compile
+                (lambda (node-t parent-t grand-parent-t)
+                  (lambda (node parent &rest _)
+                    (and (or (null node-t)
+                             (string-match-p
+                              node-t (or (treesit-node-type node) "")))
+                         (or (null ,parent-t)
+                             (string-match-p
+                              parent-t (treesit-node-type parent)))
+                         (or (null ,grand-parent-t)
+                             (string-match-p
+                              grand-parent-t
+                              (treesit-node-type
+                               (treesit-node-parent parent)))))))))
+    (no-node . ,(byte-compile
+                 (lambda (node &rest _) (null node))))
+    (parent-is . ,(byte-compile
+                   (lambda (type)
+                     (lambda (_n parent &rest _)
+                       (string-match-p
+                        type (treesit-node-type parent))))))
+
+    (node-is . ,(byte-compile
+                 (lambda (type)
+                   (lambda (node &rest _)
                      (string-match-p
-                      ,name (or (treesit-node-field-name node) "")))))
+                      type (or (treesit-node-type node) ""))))))
+    (field-is . ,(byte-compile
+                  (lambda (name)
+                    (lambda (node &rest _)
+                      (string-match-p
+                       name (or (treesit-node-field-name node) ""))))))
     ;; TODO: Document.
-    (catch-all . (lambda (&rest _) t))
-
-    (query . (lambda (pattern)
-               `(lambda (node parent bol &rest _)
-                  (cl-loop for capture
-                           in (treesit-query-capture
-                               parent ,pattern)
-                           if (treesit-node-eq node (cdr capture))
-                           return t
-                           finally return nil))))
-    (first-sibling . (lambda (node parent bol &rest _)
-                       (treesit-node-start
-                        (treesit-node-child parent 0))))
+    (catch-all . ,(byte-compile (lambda (&rest _) t)))
+
+    (query . ,(byte-compile
+               (lambda (pattern)
+                 (lambda (node parent &rest _)
+                   (cl-loop for capture
+                            in (treesit-query-capture
+                                parent pattern)
+                            if (treesit-node-eq node (cdr capture))
+                            return t
+                            finally return nil)))))
+    (first-sibling . ,(byte-compile
+                       (lambda (_n parent &rest _)
+                         (treesit-node-start
+                          (treesit-node-child parent 0)))))
     ;; TODO: Document.
-    (nth-sibling . (lambda (n &optional named)
-                     `(lambda (node parent bol &rest _)
-                        (treesit-node-start
-                         (treesit-node-child parent ,n ,named)))))
-    (parent . (lambda (node parent bol &rest _)
-                (treesit-node-start parent)))
+    (nth-sibling . ,(byte-compile
+                     (lambda (n &optional named)
+                       (lambda (_n parent &rest _)
+                         (treesit-node-start
+                          (treesit-node-child parent n named))))))
+    (parent . ,(byte-compile
+                (lambda (_n parent &rest _)
+                  (treesit-node-start parent))))
     ;; TODO: Document.
-    (grand-parent . (lambda (node parent bol &rest _)
-                      (treesit-node-start (treesit-node-parent parent))))
-    (parent-bol . (lambda (node parent bol &rest _)
-                    (save-excursion
-                      (goto-char (treesit-node-start parent))
-                      (back-to-indentation)
-                      (point))))
-    (prev-sibling . (lambda (node parent bol &rest _)
-                      (treesit-node-start
-                       (treesit-node-prev-sibling node))))
-    (no-indent . (lambda (node parent bol &rest _) bol))
-    (prev-line . (lambda (node parent bol &rest _)
-                   (save-excursion
-                     (goto-char bol)
-                     (forward-line -1)
-                     (skip-chars-forward " \t"))))
+    (grand-parent . ,(byte-compile
+                      (lambda (_n parent &rest _)
+                        (treesit-node-start (treesit-node-parent parent)))))
+    (parent-bol . ,(byte-compile
+                    (lambda (_n parent &rest _)
+                      (save-excursion
+                        (goto-char (treesit-node-start parent))
+                        (back-to-indentation)
+                        (point)))))
+    (prev-sibling . ,(byte-compile
+                      (lambda (node &rest _)
+                        (treesit-node-start
+                         (treesit-node-prev-sibling node)))))
+    (no-indent . ,(byte-compile (lambda (_n _p bol &rest _) bol)))
+    (prev-line . ,(byte-compile (lambda (_n _p bol &rest _)
+                                  (save-excursion
+                                    (goto-char bol)
+                                    (forward-line -1)
+                                    (skip-chars-forward " \t")))))
     ;; TODO: Document.
-    (and . (lambda (&rest fns)
-             `(lambda (node parent bol &rest _)
-                (cl-reduce (lambda (a b) (and a b))
+    (and . ,(byte-compile
+             (lambda (&rest fns)
+               (lambda (node parent bol &rest _)
+                 (cl-reduce (lambda (a b) (and a b))
+                            (mapcar (lambda (fn)
+                                      (funcall fn node parent bol))
+                                    fns))))))
+    (or . ,(byte-compile
+            (lambda (&rest fns)
+              (lambda (node parent bol &rest _)
+                (cl-reduce (lambda (a b) (or a b))
                            (mapcar (lambda (fn)
                                      (funcall fn node parent bol))
-                                   ',fns)))))
-    (or . (lambda (&rest fns)
-            `(lambda (node parent bol &rest _)
-               (cl-reduce (lambda (a b) (or a b))
-                          (mapcar (lambda (fn)
-                                    (funcall fn node parent bol))
-                                  ',fns)))))
-    (not . (lambda (fn)
-             `(lambda (node parent bol &rest _)
-                (debug)
-                (not (funcall ,fn node parent bol)))))
-    (list . (lambda (&rest fns)
-              `(lambda (node parent bol &rest _)
-                 (mapcar (lambda (fn)
-                           (funcall fn node parent bol))
-                         ',fns)))))
+                                   fns))))))
+    (not . ,(byte-compile
+             (lambda (fn)
+               (lambda (node parent bol &rest _)
+                 (debug)
+                 (not (funcall fn node parent bol))))))
+    (list . ,(byte-compile
+              (lambda (&rest fns)
+                (lambda (node parent bol &rest _)
+                  (mapcar (lambda (fn)
+                            (funcall fn node parent bol))
+                          fns))))))
   "A list of presets.
 These presets that can be used as MATHER and ANCHOR in
 `treesit-simple-indent-rules'.



reply via email to

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