diff options
| author | Yuan Fu | 2022-10-28 17:56:05 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-10-28 17:56:05 -0700 |
| commit | f46eb3d3ca759ab3944cedda1339a6d1760298cd (patch) | |
| tree | b671d93c81605e63fb5dcf7f1bf32b5ce6be3f4a | |
| parent | 0c7a7df98e1fb0bc156707b379e4147fac97359a (diff) | |
| download | emacs-f46eb3d3ca759ab3944cedda1339a6d1760298cd.tar.gz emacs-f46eb3d3ca759ab3944cedda1339a6d1760298cd.zip | |
Byte-compile treesit-simple-indent-presets
* lisp/treesit.el (treesit-simple-indent-presets): Byte-compile these
functions.
| -rw-r--r-- | lisp/treesit.el | 213 |
1 files changed, 115 insertions, 98 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index 9c4d4535342..264935f1854 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -696,114 +696,131 @@ For MATCHER and ANCHOR, Emacs provides some convenient presets. | |||
| 696 | See `treesit-simple-indent-presets'.") | 696 | See `treesit-simple-indent-presets'.") |
| 697 | 697 | ||
| 698 | (defvar treesit-simple-indent-presets | 698 | (defvar treesit-simple-indent-presets |
| 699 | '((match . (lambda | 699 | `((match . ,(byte-compile |
| 700 | (&optional node-type parent-type node-field | 700 | (lambda |
| 701 | node-index-min node-index-max) | 701 | (&optional node-type parent-type node-field |
| 702 | `(lambda (node parent bol &rest _) | 702 | node-index-min node-index-max) |
| 703 | (and (or (null ,node-type) | 703 | (lambda (node parent &rest _) |
| 704 | (string-match-p | 704 | (and (or (null node-type) |
| 705 | ,node-type (or (treesit-node-type node) ""))) | ||
| 706 | (or (null ,parent-type) | ||
| 707 | (string-match-p | ||
| 708 | ,parent-type (treesit-node-type parent))) | ||
| 709 | (or (null ,node-field) | ||
| 710 | (string-match-p | ||
| 711 | ,node-field | ||
| 712 | (or (treesit-node-field-name node) ""))) | ||
| 713 | (or (null ,node-index-min) | ||
| 714 | (>= (treesit-node-index node t) | ||
| 715 | ,node-index-min)) | ||
| 716 | (or (null ,node-index-max) | ||
| 717 | (<= (treesit-node-index node t) | ||
| 718 | ,node-index-max)))))) | ||
| 719 | ;; TODO: Document if genuinely useful. | ||
| 720 | (n-p-gp . (lambda (node-t parent-t grand-parent-t) | ||
| 721 | `(lambda (node parent bol &rest _) | ||
| 722 | (and (or (null ,node-t) | ||
| 723 | (string-match-p | 705 | (string-match-p |
| 724 | ,node-t (or (treesit-node-type node) ""))) | 706 | node-type (or (treesit-node-type node) ""))) |
| 725 | (or (null ,parent-t) | 707 | (or (null parent-type) |
| 726 | (string-match-p | 708 | (string-match-p |
| 727 | ,parent-t (treesit-node-type parent))) | 709 | parent-type (treesit-node-type parent))) |
| 728 | (or (null ,grand-parent-t) | 710 | (or (null node-field) |
| 729 | (string-match-p | 711 | (string-match-p |
| 730 | ,grand-parent-t | 712 | node-field |
| 731 | (treesit-node-type | 713 | (or (treesit-node-field-name node) ""))) |
| 732 | (treesit-node-parent parent)))))))) | 714 | (or (null node-index-min) |
| 733 | (no-node . (lambda (node parent bol &rest _) (null node))) | 715 | (>= (treesit-node-index node t) |
| 734 | (parent-is . (lambda (type) | 716 | node-index-min)) |
| 735 | `(lambda (node parent bol &rest _) | 717 | (or (null node-index-max) |
| 736 | (string-match-p | 718 | (<= (treesit-node-index node t) |
| 737 | ,type (treesit-node-type parent))))) | 719 | node-index-max))))))) |
| 738 | 720 | ;; TODO: Document if genuinely useful. | |
| 739 | (node-is . (lambda (type) | 721 | (n-p-gp . ,(byte-compile |
| 740 | `(lambda (node parent bol &rest _) | 722 | (lambda (node-t parent-t grand-parent-t) |
| 741 | (string-match-p | 723 | (lambda (node parent &rest _) |
| 742 | ,type (or (treesit-node-type node) ""))))) | 724 | (and (or (null node-t) |
| 743 | (field-is . (lambda (name) | 725 | (string-match-p |
| 744 | `(lambda (node parent bol &rest _) | 726 | node-t (or (treesit-node-type node) ""))) |
| 727 | (or (null ,parent-t) | ||
| 728 | (string-match-p | ||
| 729 | parent-t (treesit-node-type parent))) | ||
| 730 | (or (null ,grand-parent-t) | ||
| 731 | (string-match-p | ||
| 732 | grand-parent-t | ||
| 733 | (treesit-node-type | ||
| 734 | (treesit-node-parent parent))))))))) | ||
| 735 | (no-node . ,(byte-compile | ||
| 736 | (lambda (node &rest _) (null node)))) | ||
| 737 | (parent-is . ,(byte-compile | ||
| 738 | (lambda (type) | ||
| 739 | (lambda (_n parent &rest _) | ||
| 740 | (string-match-p | ||
| 741 | type (treesit-node-type parent)))))) | ||
| 742 | |||
| 743 | (node-is . ,(byte-compile | ||
| 744 | (lambda (type) | ||
| 745 | (lambda (node &rest _) | ||
| 745 | (string-match-p | 746 | (string-match-p |
| 746 | ,name (or (treesit-node-field-name node) ""))))) | 747 | type (or (treesit-node-type node) "")))))) |
| 748 | (field-is . ,(byte-compile | ||
| 749 | (lambda (name) | ||
| 750 | (lambda (node &rest _) | ||
| 751 | (string-match-p | ||
| 752 | name (or (treesit-node-field-name node) "")))))) | ||
| 747 | ;; TODO: Document. | 753 | ;; TODO: Document. |
| 748 | (catch-all . (lambda (&rest _) t)) | 754 | (catch-all . ,(byte-compile (lambda (&rest _) t))) |
| 749 | 755 | ||
| 750 | (query . (lambda (pattern) | 756 | (query . ,(byte-compile |
| 751 | `(lambda (node parent bol &rest _) | 757 | (lambda (pattern) |
| 752 | (cl-loop for capture | 758 | (lambda (node parent &rest _) |
| 753 | in (treesit-query-capture | 759 | (cl-loop for capture |
| 754 | parent ,pattern) | 760 | in (treesit-query-capture |
| 755 | if (treesit-node-eq node (cdr capture)) | 761 | parent pattern) |
| 756 | return t | 762 | if (treesit-node-eq node (cdr capture)) |
| 757 | finally return nil)))) | 763 | return t |
| 758 | (first-sibling . (lambda (node parent bol &rest _) | 764 | finally return nil))))) |
| 759 | (treesit-node-start | 765 | (first-sibling . ,(byte-compile |
| 760 | (treesit-node-child parent 0)))) | 766 | (lambda (_n parent &rest _) |
| 767 | (treesit-node-start | ||
| 768 | (treesit-node-child parent 0))))) | ||
| 761 | ;; TODO: Document. | 769 | ;; TODO: Document. |
| 762 | (nth-sibling . (lambda (n &optional named) | 770 | (nth-sibling . ,(byte-compile |
| 763 | `(lambda (node parent bol &rest _) | 771 | (lambda (n &optional named) |
| 764 | (treesit-node-start | 772 | (lambda (_n parent &rest _) |
| 765 | (treesit-node-child parent ,n ,named))))) | 773 | (treesit-node-start |
| 766 | (parent . (lambda (node parent bol &rest _) | 774 | (treesit-node-child parent n named)))))) |
| 767 | (treesit-node-start parent))) | 775 | (parent . ,(byte-compile |
| 776 | (lambda (_n parent &rest _) | ||
| 777 | (treesit-node-start parent)))) | ||
| 768 | ;; TODO: Document. | 778 | ;; TODO: Document. |
| 769 | (grand-parent . (lambda (node parent bol &rest _) | 779 | (grand-parent . ,(byte-compile |
| 770 | (treesit-node-start (treesit-node-parent parent)))) | 780 | (lambda (_n parent &rest _) |
| 771 | (parent-bol . (lambda (node parent bol &rest _) | 781 | (treesit-node-start (treesit-node-parent parent))))) |
| 772 | (save-excursion | 782 | (parent-bol . ,(byte-compile |
| 773 | (goto-char (treesit-node-start parent)) | 783 | (lambda (_n parent &rest _) |
| 774 | (back-to-indentation) | 784 | (save-excursion |
| 775 | (point)))) | 785 | (goto-char (treesit-node-start parent)) |
| 776 | (prev-sibling . (lambda (node parent bol &rest _) | 786 | (back-to-indentation) |
| 777 | (treesit-node-start | 787 | (point))))) |
| 778 | (treesit-node-prev-sibling node)))) | 788 | (prev-sibling . ,(byte-compile |
| 779 | (no-indent . (lambda (node parent bol &rest _) bol)) | 789 | (lambda (node &rest _) |
| 780 | (prev-line . (lambda (node parent bol &rest _) | 790 | (treesit-node-start |
| 781 | (save-excursion | 791 | (treesit-node-prev-sibling node))))) |
| 782 | (goto-char bol) | 792 | (no-indent . ,(byte-compile (lambda (_n _p bol &rest _) bol))) |
| 783 | (forward-line -1) | 793 | (prev-line . ,(byte-compile (lambda (_n _p bol &rest _) |
| 784 | (skip-chars-forward " \t")))) | 794 | (save-excursion |
| 795 | (goto-char bol) | ||
| 796 | (forward-line -1) | ||
| 797 | (skip-chars-forward " \t"))))) | ||
| 785 | ;; TODO: Document. | 798 | ;; TODO: Document. |
| 786 | (and . (lambda (&rest fns) | 799 | (and . ,(byte-compile |
| 787 | `(lambda (node parent bol &rest _) | 800 | (lambda (&rest fns) |
| 788 | (cl-reduce (lambda (a b) (and a b)) | 801 | (lambda (node parent bol &rest _) |
| 802 | (cl-reduce (lambda (a b) (and a b)) | ||
| 803 | (mapcar (lambda (fn) | ||
| 804 | (funcall fn node parent bol)) | ||
| 805 | fns)))))) | ||
| 806 | (or . ,(byte-compile | ||
| 807 | (lambda (&rest fns) | ||
| 808 | (lambda (node parent bol &rest _) | ||
| 809 | (cl-reduce (lambda (a b) (or a b)) | ||
| 789 | (mapcar (lambda (fn) | 810 | (mapcar (lambda (fn) |
| 790 | (funcall fn node parent bol)) | 811 | (funcall fn node parent bol)) |
| 791 | ',fns))))) | 812 | fns)))))) |
| 792 | (or . (lambda (&rest fns) | 813 | (not . ,(byte-compile |
| 793 | `(lambda (node parent bol &rest _) | 814 | (lambda (fn) |
| 794 | (cl-reduce (lambda (a b) (or a b)) | 815 | (lambda (node parent bol &rest _) |
| 795 | (mapcar (lambda (fn) | 816 | (debug) |
| 796 | (funcall fn node parent bol)) | 817 | (not (funcall fn node parent bol)))))) |
| 797 | ',fns))))) | 818 | (list . ,(byte-compile |
| 798 | (not . (lambda (fn) | 819 | (lambda (&rest fns) |
| 799 | `(lambda (node parent bol &rest _) | 820 | (lambda (node parent bol &rest _) |
| 800 | (debug) | 821 | (mapcar (lambda (fn) |
| 801 | (not (funcall ,fn node parent bol))))) | 822 | (funcall fn node parent bol)) |
| 802 | (list . (lambda (&rest fns) | 823 | fns)))))) |
| 803 | `(lambda (node parent bol &rest _) | ||
| 804 | (mapcar (lambda (fn) | ||
| 805 | (funcall fn node parent bol)) | ||
| 806 | ',fns))))) | ||
| 807 | "A list of presets. | 824 | "A list of presets. |
| 808 | These presets that can be used as MATHER and ANCHOR in | 825 | These presets that can be used as MATHER and ANCHOR in |
| 809 | `treesit-simple-indent-rules'. | 826 | `treesit-simple-indent-rules'. |