Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
;;; treesit.el --- tree-sitter utilities -*- lexical-binding: t -*-
|
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
;; Copyright (C) 2021-2022 Free Software Foundation, Inc.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
2022-10-27 08:02:58 +02:00
|
|
|
|
|
|
|
;; This file is the Lisp counterpart of treesit.c. Together they
|
2022-10-18 13:21:55 -07:00
|
|
|
;; provide tree-sitter integration for Emacs. This file contains
|
|
|
|
;; convenient functions that are more idiomatic and flexible than the
|
|
|
|
;; exposed C API of tree-sitter. It also contains frameworks for
|
2022-10-27 08:02:58 +02:00
|
|
|
;; integrating tree-sitter with font-lock, indentation, activating and
|
|
|
|
;; deactivating tree-sitter, debugging tree-sitter, etc.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
2022-09-30 17:20:34 -07:00
|
|
|
(eval-when-compile (require 'subr-x)) ; For `string-join'.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(require 'cl-seq)
|
|
|
|
(require 'font-lock)
|
|
|
|
|
2022-10-28 16:38:37 -07:00
|
|
|
;;; Function declarations
|
|
|
|
|
|
|
|
(declare-function treesit-language-available-p "treesit.c")
|
|
|
|
(declare-function treesit-language-version "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-parser-p "treesit.c")
|
|
|
|
(declare-function treesit-node-p "treesit.c")
|
|
|
|
(declare-function treesit-compiled-query-p "treesit.c")
|
|
|
|
(declare-function treesit-query-p "treesit.c")
|
|
|
|
(declare-function treesit-query-language "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-node-parser "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-parser-create "treesit.c")
|
|
|
|
(declare-function treesit-parser-delete "treesit.c")
|
|
|
|
(declare-function treesit-parser-list "treesit.c")
|
|
|
|
(declare-function treesit-parser-buffer "treesit.c")
|
|
|
|
(declare-function treesit-parser-language "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-parser-root-node "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-parser-set-included-ranges "treesit.c")
|
|
|
|
(declare-function treesit-parser-included-ranges "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-node-type "treesit.c")
|
|
|
|
(declare-function treesit-node-start "treesit.c")
|
|
|
|
(declare-function treesit-node-end "treesit.c")
|
|
|
|
(declare-function treesit-node-string "treesit.c")
|
|
|
|
(declare-function treesit-node-parent "treesit.c")
|
|
|
|
(declare-function treesit-node-child "treesit.c")
|
|
|
|
(declare-function treesit-node-check "treesit.c")
|
|
|
|
(declare-function treesit-node-field-name-for-child "treesit.c")
|
|
|
|
(declare-function treesit-node-child-count "treesit.c")
|
|
|
|
(declare-function treesit-node-child-by-field-name "treesit.c")
|
|
|
|
(declare-function treesit-node-next-sibling "treesit.c")
|
|
|
|
(declare-function treesit-node-prev-sibling "treesit.c")
|
|
|
|
(declare-function treesit-node-first-child-for-pos "treesit.c")
|
|
|
|
(declare-function treesit-node-descendant-for-range "treesit.c")
|
|
|
|
(declare-function treesit-node-eq "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-pattern-expand "treesit.c")
|
|
|
|
(declare-function treesit-query-expand "treesit.c")
|
|
|
|
(declare-function treesit-query-compile "treesit.c")
|
|
|
|
(declare-function treesit-query-capture "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-search-subtree "treesit.c")
|
|
|
|
(declare-function treesit-search-forward "treesit.c")
|
|
|
|
(declare-function treesit-induce-sparse-tree "treesit.c")
|
|
|
|
|
|
|
|
(declare-function treesit-available-p "treesit.c")
|
|
|
|
|
2022-10-19 16:44:04 -07:00
|
|
|
;;; Custom options
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-18 13:24:37 -07:00
|
|
|
;; Tree-sitter always appear as treesit in symbols.
|
|
|
|
(defgroup treesit nil
|
|
|
|
"Incremental parser.
|
|
|
|
It is used to enhance major mode features like font-lock,
|
|
|
|
indent, imenu, etc."
|
2022-10-09 20:54:19 -07:00
|
|
|
:group 'tools
|
|
|
|
:version "29.1")
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-09-07 13:20:37 -07:00
|
|
|
(defcustom treesit-max-buffer-size (* 4 1024 1024)
|
2022-10-09 20:54:19 -07:00
|
|
|
"Maximum buffer size for enabling tree-sitter parsing (in bytes)."
|
|
|
|
:type 'integer
|
|
|
|
:version "29.1")
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
(defcustom treesit-settings '((t nil t))
|
|
|
|
"Tree-sitter toggle settings for major modes.
|
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
A list of (MODE ACTIVATE INHERIT) where MODE is a major mode, and
|
|
|
|
ACTIVATE can be one of the following:
|
2022-10-25 13:54:12 -07:00
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
`demand' Demand the use of tree-sitter, and warn if it can't
|
|
|
|
be activated.
|
|
|
|
t Enable tree-sitter if it is available.
|
|
|
|
nil Don't enable tree-sitter.
|
2022-10-25 13:54:12 -07:00
|
|
|
|
|
|
|
If INHERIT is t, the setting for MODE is inherited by all its
|
|
|
|
derived modes. For a derived mode, closer ancestor mode's
|
|
|
|
setting takes higher precedence.
|
|
|
|
|
|
|
|
A special MODE, t, is considered the ancestor of every mode, and
|
|
|
|
its INHERIT flag is ignored."
|
|
|
|
:type '(repeat
|
|
|
|
(list :tag "Setting"
|
|
|
|
(symbol :tag "Mode")
|
|
|
|
(choice :tag "Activate"
|
|
|
|
(const :tag "No" nil)
|
|
|
|
(const :tag "Yes" t)
|
|
|
|
(const :tag "Demand" demand))
|
|
|
|
(choice :tag "Inherit"
|
|
|
|
(const :tag "Yes" t)
|
|
|
|
(const :tag "No" nil))))
|
|
|
|
:version "29.1")
|
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
;;; Parser API supplement
|
|
|
|
|
|
|
|
(defun treesit-parse-string (string language)
|
|
|
|
"Parse STRING using a parser for LANGUAGE.
|
|
|
|
Return the root node of the syntax tree."
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert string)
|
|
|
|
(treesit-parser-root-node
|
2022-06-16 01:11:09 -07:00
|
|
|
(treesit-parser-create language))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-25 14:26:41 -07:00
|
|
|
(defvar-local treesit-language-at-point-function nil
|
|
|
|
"A function that returns the language at point.
|
|
|
|
This is used by `treesit-language-at', which is used by various
|
|
|
|
functions to determine which parser to use at point.
|
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
The function is called with one argument, the position of point.")
|
2022-10-25 14:26:41 -07:00
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
(defun treesit-language-at (position)
|
|
|
|
"Return the language at POSITION.
|
2022-10-25 14:26:41 -07:00
|
|
|
Assumes parser ranges are up-to-date."
|
|
|
|
(when treesit-language-at-point-function
|
2022-10-27 08:02:58 +02:00
|
|
|
(funcall treesit-language-at-point-function position)))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
;;; Node API supplement
|
|
|
|
|
|
|
|
(defun treesit-node-buffer (node)
|
2022-10-27 08:02:58 +02:00
|
|
|
"Return the buffer in which NODE belongs."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(treesit-parser-buffer
|
|
|
|
(treesit-node-parser node)))
|
|
|
|
|
|
|
|
(defun treesit-node-language (node)
|
|
|
|
"Return the language symbol that NODE's parser uses."
|
|
|
|
(treesit-parser-language
|
|
|
|
(treesit-node-parser node)))
|
|
|
|
|
2022-10-23 18:54:12 -07:00
|
|
|
(defun treesit-node-at (pos &optional parser-or-lang named strict)
|
2022-10-22 18:48:42 +03:00
|
|
|
"Return the smallest node that starts at or after buffer position POS.
|
2022-05-13 13:38:21 -07:00
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
\"Starts at or after POS\" means the start of the node is greater
|
|
|
|
than or equal to POS.
|
2022-10-22 18:48:42 +03:00
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
Return nil if none was found. If NAMED is non-nil, only look for
|
|
|
|
named node.
|
2022-05-13 13:38:21 -07:00
|
|
|
|
|
|
|
If PARSER-OR-LANG is nil, use the first parser in
|
2022-10-27 08:02:58 +02:00
|
|
|
`treesit-parser-list'; if PARSER-OR-LANG is a parser, use
|
2022-05-13 13:38:21 -07:00
|
|
|
that parser; if PARSER-OR-LANG is a language, find a parser using
|
2022-10-23 16:16:27 -07:00
|
|
|
that language in the current buffer, and use that.
|
|
|
|
|
2022-10-23 18:23:17 -07:00
|
|
|
If POS is after all the text in the buffer, i.e., there is no
|
|
|
|
node after POS, return the last leaf node in the parse tree, even
|
|
|
|
though that node is before POS. If STRICT is non-nil, return nil
|
|
|
|
in this case."
|
|
|
|
(let* ((root (if (treesit-parser-p parser-or-lang)
|
|
|
|
(treesit-parser-root-node parser-or-lang)
|
|
|
|
(treesit-buffer-root-node parser-or-lang)))
|
|
|
|
(node root)
|
|
|
|
next)
|
|
|
|
(when node
|
|
|
|
;; This is very fast so no need for C implementation.
|
|
|
|
(while (setq next (treesit-node-first-child-for-pos
|
|
|
|
node pos named))
|
|
|
|
(setq node next))
|
|
|
|
;; If we are at the end of buffer or after all the text, we will
|
|
|
|
;; end up with NODE = root node. For convenience, return the last
|
|
|
|
;; leaf node in the tree.
|
|
|
|
(if (treesit-node-eq node root)
|
|
|
|
(if strict
|
|
|
|
nil
|
|
|
|
(while (setq next (treesit-node-child node -1 named))
|
|
|
|
(setq node next))
|
|
|
|
node)
|
2022-10-23 18:54:12 -07:00
|
|
|
node))))
|
2022-05-13 13:38:21 -07:00
|
|
|
|
|
|
|
(defun treesit-node-on (beg end &optional parser-or-lang named)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"Return the smallest node covering BEG to END.
|
|
|
|
|
2022-05-13 13:38:21 -07:00
|
|
|
BEWARE! Calling this function on an empty line that is not
|
2022-10-27 08:02:58 +02:00
|
|
|
inside any top-level construct (function definition, etc.) most
|
2022-05-13 13:38:21 -07:00
|
|
|
probably will give you the root node, because the root node is
|
|
|
|
the smallest node that covers that empty line. You probably want
|
|
|
|
to use `treesit-node-at' instead.
|
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
Return nil if none was found. If NAMED is non-nil, only look for
|
|
|
|
named node.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
If PARSER-OR-LANG is nil, use the first parser in
|
2022-10-27 08:02:58 +02:00
|
|
|
`treesit-parser-list'; if PARSER-OR-LANG is a parser, use
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
that parser; if PARSER-OR-LANG is a language, find a parser using
|
|
|
|
that language in the current buffer, and use that."
|
|
|
|
(let ((root (if (treesit-parser-p parser-or-lang)
|
|
|
|
(treesit-parser-root-node parser-or-lang)
|
|
|
|
(treesit-buffer-root-node parser-or-lang))))
|
|
|
|
(treesit-node-descendant-for-range root beg (or end beg) named)))
|
|
|
|
|
2022-10-29 14:11:52 -07:00
|
|
|
(defun treesit-node-top-level (node &optional type)
|
|
|
|
"Return the top-level equivalent of NODE.
|
|
|
|
Specifically, return the highest parent of NODE that has the same
|
|
|
|
type as it. If no such parent exists, return nil.
|
|
|
|
|
|
|
|
If TYPE is non-nil, match each parent's type with TYPE as a
|
|
|
|
regexp, rather than using NODE's type."
|
|
|
|
(let ((type (or type (treesit-node-type node)))
|
|
|
|
(result nil))
|
|
|
|
(cl-loop for cursor = (treesit-node-parent node)
|
|
|
|
then (treesit-node-parent cursor)
|
|
|
|
while cursor
|
|
|
|
if (string-match-p type (treesit-node-type cursor))
|
|
|
|
do (setq result cursor))
|
|
|
|
result))
|
2022-10-26 18:06:07 -07:00
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(defun treesit-buffer-root-node (&optional language)
|
|
|
|
"Return the root node of the current buffer.
|
2022-10-27 08:02:58 +02:00
|
|
|
Use the first parser in `treesit-parser-list'.
|
|
|
|
|
|
|
|
If optional argument LANGUAGE is non-nil, use the first parser
|
|
|
|
for LANGUAGE."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(if-let ((parser
|
|
|
|
(or (if language
|
2022-11-04 09:58:08 -07:00
|
|
|
(treesit-parser-create language)
|
Change treesit-parser-list from variable to function
Effectively making the list internal. Now Emacs user cannot shoot
themselves in the foot by removing a parser from the list, make
chaanges to buffer and add that parser back to the list.
* doc/lispref/parsing.texi (Language Definitions, Using Parser)
(Retrieving Node, Multiple Languages): Change variable to function.
* lisp/treesit.el (treesit-language-at, treesit-node-on)
(treesit-buffer-root-node, treesit-indent, treesit-check-indent)
(treesit-search-forward, treesit-search-beginning)
(treesit-end-of-defun, treesit-inspect-mode): Change variable to
function.
* src/buffer.c (bset_ts_parser_list, reset_buffer, init_buffer_once):
Add ts_parser_list.
* src/buffer.h (struct buffer): Add ts_parser_list.
* src/treesit.c (ts_record_change, Ftreesit_parser_create): Use the
buffer field instead of the old buffer local variable.
(Ftreesit_parser_delete, Ftreesit_parser_list): New functions.
(syms_of_treesit): Remove treesit-parser-list.
* test/src/treesit-tests.el (treesit-basic-parsing): Use the new
function.
2022-06-16 17:55:07 -07:00
|
|
|
(or (car (treesit-parser-list))
|
2022-11-04 09:58:08 -07:00
|
|
|
(signal 'treesit-error
|
|
|
|
'("Buffer has no parser")))))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(treesit-parser-root-node parser)))
|
|
|
|
|
|
|
|
(defun treesit-filter-child (node pred &optional named)
|
2022-10-27 08:02:58 +02:00
|
|
|
"Return children of NODE that satisfies predicate PRED.
|
|
|
|
PRED is a function that takes one argument, the child node.
|
|
|
|
If optional argument NAMED is non-nil, only search for named
|
|
|
|
node."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(let ((child (treesit-node-child node 0 named))
|
|
|
|
result)
|
|
|
|
(while child
|
|
|
|
(when (funcall pred child)
|
|
|
|
(push child result))
|
|
|
|
(setq child (treesit-node-next-sibling child named)))
|
|
|
|
(reverse result)))
|
|
|
|
|
|
|
|
(defun treesit-node-text (node &optional no-property)
|
|
|
|
"Return the buffer (or string) content corresponding to NODE.
|
2022-10-27 08:02:58 +02:00
|
|
|
If optional argument NO-PROPERTY is non-nil, remove text
|
|
|
|
properties."
|
2022-09-24 19:24:06 -07:00
|
|
|
(when node
|
|
|
|
(with-current-buffer (treesit-node-buffer node)
|
|
|
|
(if no-property
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(treesit-node-start node)
|
|
|
|
(treesit-node-end node))
|
|
|
|
(buffer-substring
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(treesit-node-start node)
|
2022-09-24 19:24:06 -07:00
|
|
|
(treesit-node-end node))))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
(defun treesit-parent-until (node pred)
|
|
|
|
"Return the closest parent of NODE that satisfies PRED.
|
2022-10-27 08:02:58 +02:00
|
|
|
Return nil if none was found. PRED should be a function that
|
|
|
|
takes one argument, the parent node."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(let ((node (treesit-node-parent node)))
|
|
|
|
(while (and node (not (funcall pred node)))
|
|
|
|
(setq node (treesit-node-parent node)))
|
|
|
|
node))
|
|
|
|
|
|
|
|
(defun treesit-parent-while (node pred)
|
|
|
|
"Return the furthest parent of NODE that satisfies PRED.
|
2022-10-27 08:02:58 +02:00
|
|
|
Return nil if none was found. PRED should be a function that
|
|
|
|
takes one argument, the parent node."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(let ((last nil))
|
|
|
|
(while (and node (funcall pred node))
|
|
|
|
(setq last node
|
|
|
|
node (treesit-node-parent node)))
|
|
|
|
last))
|
|
|
|
|
2022-05-13 13:47:41 -07:00
|
|
|
(defalias 'treesit-traverse-parent #'treesit-parent-until)
|
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(defun treesit-node-children (node &optional named)
|
|
|
|
"Return a list of NODE's children.
|
|
|
|
If NAMED is non-nil, collect named child only."
|
|
|
|
(mapcar (lambda (idx)
|
|
|
|
(treesit-node-child node idx named))
|
|
|
|
(number-sequence
|
|
|
|
0 (1- (treesit-node-child-count node named)))))
|
|
|
|
|
|
|
|
(defun treesit-node-index (node &optional named)
|
|
|
|
"Return the index of NODE in its parent.
|
|
|
|
If NAMED is non-nil, count named child only."
|
|
|
|
(let ((count 0))
|
|
|
|
(while (setq node (treesit-node-prev-sibling node named))
|
|
|
|
(cl-incf count))
|
|
|
|
count))
|
|
|
|
|
|
|
|
(defun treesit-node-field-name (node)
|
|
|
|
"Return the field name of NODE as a child of its parent."
|
|
|
|
(when-let ((parent (treesit-node-parent node))
|
|
|
|
(idx (treesit-node-index node)))
|
|
|
|
(treesit-node-field-name-for-child parent idx)))
|
|
|
|
|
|
|
|
;;; Query API supplement
|
|
|
|
|
|
|
|
(defun treesit-query-string (string query language)
|
|
|
|
"Query STRING with QUERY in LANGUAGE.
|
|
|
|
See `treesit-query-capture' for QUERY."
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert string)
|
2022-06-16 01:11:09 -07:00
|
|
|
(let ((parser (treesit-parser-create language)))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(treesit-query-capture
|
|
|
|
(treesit-parser-root-node parser)
|
|
|
|
query))))
|
|
|
|
|
|
|
|
(defun treesit-query-range (source query &optional beg end)
|
|
|
|
"Query the current buffer and return ranges of captured nodes.
|
|
|
|
|
|
|
|
QUERY, SOURCE, BEG, END are the same as in
|
|
|
|
`treesit-query-in'. This function returns a list
|
|
|
|
of (START . END), where START and END specifics the range of each
|
|
|
|
captured node. Capture names don't matter."
|
|
|
|
(cl-loop for capture
|
2022-09-30 17:20:34 -07:00
|
|
|
in (treesit-query-capture source query beg end)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
for node = (cdr capture)
|
|
|
|
collect (cons (treesit-node-start node)
|
|
|
|
(treesit-node-end node))))
|
|
|
|
|
|
|
|
;;; Range API supplement
|
|
|
|
|
2022-11-04 01:31:56 -07:00
|
|
|
(defvar-local treesit-range-settings nil
|
|
|
|
"A list of range settings.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
Each element of the list is of the form (QUERY LANGUAGE).
|
2022-11-04 01:31:56 -07:00
|
|
|
When updating the range of each parser in the buffer,
|
2022-11-05 10:49:46 +02:00
|
|
|
`treesit-update-ranges' queries each QUERY, and sets LANGUAGE's
|
2022-11-04 01:31:56 -07:00
|
|
|
range to the range spanned by captured nodes. QUERY must be a
|
|
|
|
compiled query.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-04 01:31:56 -07:00
|
|
|
QUERY can also be a function, in which case it is called with 2
|
2022-11-05 10:49:46 +02:00
|
|
|
arguments, START and END. It should ensure parsers' ranges are
|
|
|
|
correct in the region between START and END.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
The exact form of each setting is considered internal and subject
|
2022-11-04 01:31:56 -07:00
|
|
|
to change. Use `treesit-range-rules' to set this variable.")
|
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
(defun treesit-range-rules (&rest query-specs)
|
2022-11-04 01:31:56 -07:00
|
|
|
"Produce settings for `treesit-range-settings'.
|
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
QUERY-SPECS contains a series of QUERY-SPEC of the form
|
2022-11-04 01:31:56 -07:00
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
:KEYWORD VALUE... QUERY
|
|
|
|
|
|
|
|
Each QUERY is a tree-sitter query in either the string,
|
|
|
|
s-expression or compiled form.
|
|
|
|
|
|
|
|
Each QUERY should be preceded by :KEYWORD VALUE pairs that
|
|
|
|
configures this query. For example,
|
2022-11-04 01:31:56 -07:00
|
|
|
|
|
|
|
(treesit-range-rules
|
|
|
|
:embed \\='javascript
|
|
|
|
:host \\='html
|
|
|
|
\\='((script_element (raw_text) @cap)))
|
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
The `:embed' keyword specifies the embedded language, and the
|
|
|
|
`:host' keyword specifies the host language. They are used in
|
|
|
|
this way: Emacs queries QUERY in the host language's parser,
|
|
|
|
computes the ranges spanned by the captured nodes, and applies
|
|
|
|
these ranges to parsers for the embedded language.
|
2022-11-04 01:31:56 -07:00
|
|
|
|
|
|
|
QUERY can also be a function that takes two arguments, START and
|
2022-11-05 16:52:38 -07:00
|
|
|
END. If QUERY is a function, it doesn't need :KEYWORD VALUE
|
|
|
|
pairs preceding it. This function should set the ranges for
|
|
|
|
parsers in the current buffer in the region between START and
|
|
|
|
END. It is OK for this function to set ranges in a larger region
|
|
|
|
that encompasses the region between START and END."
|
2022-11-04 01:31:56 -07:00
|
|
|
(let (host embed result)
|
2022-11-05 16:52:38 -07:00
|
|
|
(while query-specs
|
|
|
|
(pcase (pop query-specs)
|
|
|
|
(:host (let ((host-lang (pop query-specs)))
|
2022-11-04 01:31:56 -07:00
|
|
|
(unless (symbolp host-lang)
|
|
|
|
(signal 'treesit-error (list "Value of :host option should be a symbol" host-lang)))
|
|
|
|
(setq host host-lang)))
|
2022-11-05 16:52:38 -07:00
|
|
|
(:embed (let ((embed-lang (pop query-specs)))
|
2022-11-04 01:31:56 -07:00
|
|
|
(unless (symbolp embed-lang)
|
|
|
|
(signal 'treesit-error (list "Value of :embed option should be a symbol" embed-lang)))
|
|
|
|
(setq embed embed-lang)))
|
|
|
|
(query (if (functionp query)
|
|
|
|
(push (list query nil nil) result)
|
|
|
|
(when (null embed)
|
|
|
|
(signal 'treesit-error (list "Value of :embed option cannot be omitted")))
|
|
|
|
(when (null host)
|
|
|
|
(signal 'treesit-error (list "Value of :host option cannot be omitted")))
|
|
|
|
(push (list (treesit-query-compile host query)
|
|
|
|
embed host)
|
|
|
|
result))
|
|
|
|
(setq host nil embed nil))))
|
|
|
|
(nreverse result)))
|
|
|
|
|
|
|
|
(defun treesit--merge-ranges (old-ranges new-ranges start end)
|
2022-11-05 10:49:46 +02:00
|
|
|
"Merge OLD-RANGES and NEW-RANGES, discarding ranges between START and END.
|
|
|
|
OLD-RANGES and NEW-RANGES are lists of cons of the form (BEG . END). When
|
2022-11-04 01:31:56 -07:00
|
|
|
merging the two ranges, if a range in OLD-RANGES intersects with
|
|
|
|
another range in NEW-RANGES, discard the one in OLD-RANGES and
|
|
|
|
keep the one in NEW-RANGES. Also discard any range in OLD-RANGES
|
|
|
|
that intersects the region marked by START and END.
|
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
Return the merged list of ranges."
|
2022-11-04 01:31:56 -07:00
|
|
|
(let ((result nil))
|
|
|
|
(while (and old-ranges new-ranges)
|
|
|
|
(let ((new-beg (caar new-ranges))
|
|
|
|
(new-end (cdar new-ranges))
|
|
|
|
(old-beg (caar old-ranges))
|
|
|
|
(old-end (cdar old-ranges)))
|
|
|
|
(cond
|
|
|
|
;; Old range intersects with START-END, discard.
|
|
|
|
((and (< start old-end)
|
|
|
|
(< old-beg end))
|
|
|
|
(setq old-ranges (cdr old-ranges)))
|
|
|
|
;; New range and old range don't intersect, new comes
|
|
|
|
;; before, push new.
|
|
|
|
((<= new-end old-beg)
|
|
|
|
(push (car new-ranges) result)
|
|
|
|
(setq new-ranges (cdr new-ranges)))
|
|
|
|
;; New range and old range don't intersect, old comes
|
|
|
|
;; before, push old.
|
|
|
|
((<= old-end new-beg)
|
|
|
|
(push (car old-ranges) result)
|
|
|
|
(setq old-ranges (cdr old-ranges)))
|
|
|
|
(t ;; New and old range intersect, discard old.
|
|
|
|
(setq old-ranges (cdr old-ranges))))))
|
|
|
|
(let ((left-over (or new-ranges old-ranges)))
|
|
|
|
(dolist (range left-over)
|
|
|
|
(push range result)))
|
|
|
|
(nreverse result)))
|
|
|
|
|
|
|
|
(defun treesit-update-ranges (&optional beg end)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"Update the ranges for each language in the current buffer.
|
2022-11-05 10:49:46 +02:00
|
|
|
If BEG and END are non-nil, only update parser ranges in that
|
2022-11-04 01:31:56 -07:00
|
|
|
region."
|
|
|
|
;; When updating ranges, we want to avoid querying the whole buffer
|
|
|
|
;; which could be slow in very large buffers. Instead, we only
|
|
|
|
;; query for nodes that intersect with the region between BEG and
|
2022-11-05 10:49:46 +02:00
|
|
|
;; END. Also, we only update the ranges intersecting BEG and END;
|
2022-11-04 01:31:56 -07:00
|
|
|
;; outside of that region we inherit old ranges.
|
|
|
|
(dolist (setting treesit-range-settings)
|
|
|
|
(let ((query (nth 0 setting))
|
|
|
|
(language (nth 1 setting))
|
|
|
|
(beg (or beg (point-min)))
|
|
|
|
(end (or end (point-max))))
|
|
|
|
(if (functionp query) (funcall query beg end)
|
|
|
|
(let* ((host-lang (treesit-query-language query))
|
|
|
|
(parser (treesit-parser-create language))
|
|
|
|
(old-ranges (treesit-parser-included-ranges parser))
|
|
|
|
(new-ranges (treesit-query-range
|
|
|
|
host-lang query beg end))
|
|
|
|
(set-ranges (treesit--merge-ranges
|
|
|
|
old-ranges new-ranges beg end)))
|
2022-11-04 10:03:17 -07:00
|
|
|
(dolist (parser (treesit-parser-list))
|
|
|
|
(when (eq (treesit-parser-language parser)
|
|
|
|
language)
|
|
|
|
(treesit-parser-set-included-ranges
|
|
|
|
parser set-ranges))))))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-23 18:51:35 -07:00
|
|
|
(defun treesit-parser-range-on (parser beg &optional end)
|
|
|
|
"Check if PARSER's range covers the portion between BEG and END.
|
|
|
|
|
|
|
|
If it does, return the range covering that portion in the form
|
|
|
|
of (RANGE-BEG . RANGE-END), if not, return nil. If nil or
|
|
|
|
omitted, default END to BEG."
|
|
|
|
(let ((ranges (treesit-parser-included-ranges parser))
|
|
|
|
(end (or end beg)))
|
|
|
|
(if (null ranges)
|
|
|
|
(cons (point-min) (point-max))
|
|
|
|
(cl-loop for rng in ranges
|
|
|
|
if (<= (car rng) beg end (cdr rng))
|
|
|
|
return rng
|
|
|
|
finally return nil))))
|
|
|
|
|
2022-10-31 15:03:49 -07:00
|
|
|
;;; Fontification
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-04 13:28:46 -07:00
|
|
|
(define-error 'treesit-font-lock-error
|
|
|
|
"Generic tree-sitter font-lock error"
|
|
|
|
'treesit-error)
|
|
|
|
|
2022-10-13 14:44:42 -07:00
|
|
|
(defvar-local treesit-font-lock-feature-list nil
|
|
|
|
"A list of lists of feature symbols.
|
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
Use `treesit-font-lock-recompute-features' and
|
2022-11-01 00:25:47 -07:00
|
|
|
`font-lock-maximum-decoration' to configure enabled features.
|
|
|
|
|
2022-10-13 14:44:42 -07:00
|
|
|
Each sublist represents a decoration level.
|
|
|
|
`font-lock-maximum-decoration' controls which levels are
|
|
|
|
activated.
|
|
|
|
|
|
|
|
Inside each sublist are feature symbols, which corresponds to the
|
|
|
|
:feature value of a query defined in `treesit-font-lock-rules'.
|
|
|
|
Removing a feature symbol from this list disables the
|
|
|
|
corresponding query during font-lock.
|
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
Common feature names (for general programming languages) include
|
2022-10-13 14:44:42 -07:00
|
|
|
function-name, type, variable-name (LHS of assignments), builtin,
|
|
|
|
constant, keyword, string-interpolation, comment, doc, string,
|
|
|
|
operator, preprocessor, escape-sequence, key (in key-value
|
|
|
|
pairs). Major modes are free to subdivide or extend on these
|
|
|
|
common features.
|
|
|
|
|
|
|
|
For changes to this variable to take effect, run
|
|
|
|
`treesit-font-lock-recompute-features'.")
|
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(defvar-local treesit-font-lock-settings nil
|
|
|
|
"A list of SETTINGs for treesit-based fontification.
|
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
The exact format of each SETTING is considered internal. Use
|
|
|
|
`treesit-font-lock-rules' to set this variable.
|
2022-09-07 11:46:07 -07:00
|
|
|
|
2022-10-28 06:38:00 +02:00
|
|
|
Each SETTING has the form:
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-13 14:44:42 -07:00
|
|
|
(QUERY ENABLE FEATURE OVERRIDE)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-13 14:44:42 -07:00
|
|
|
QUERY must be a compiled query. See Info node `(elisp)Pattern
|
|
|
|
Matching' for how to write a query and compile it.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-13 14:44:42 -07:00
|
|
|
For SETTING to be activated for font-lock, ENABLE must be t. To
|
|
|
|
disable this SETTING, set ENABLE to nil.
|
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
FEATURE is the \"feature name\" of the query. Users can control
|
2022-10-13 14:44:42 -07:00
|
|
|
which features are enabled with `font-lock-maximum-decoration'
|
|
|
|
and `treesit-font-lock-feature-list'.
|
2022-10-04 13:28:46 -07:00
|
|
|
|
|
|
|
OVERRIDE is the override flag for this query. Its value can be
|
|
|
|
t, nil, append, prepend, keep. See more in
|
2022-10-13 14:44:42 -07:00
|
|
|
`treesit-font-lock-rules'.")
|
2022-09-07 11:46:07 -07:00
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
(defun treesit-font-lock-rules (&rest query-specs)
|
2022-09-07 11:46:07 -07:00
|
|
|
"Return a value suitable for `treesit-font-lock-settings'.
|
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
QUERY-SPECS is made of a series of QUERY-SPECs of the form
|
|
|
|
|
|
|
|
:KEYWORD VALUE... QUERY
|
|
|
|
|
|
|
|
QUERY is a tree-sitter query in either the string, s-expression
|
|
|
|
or compiled form. For each query, captured nodes are highlighted
|
2022-11-04 01:31:56 -07:00
|
|
|
with the capture name as its face.
|
2022-09-07 11:46:07 -07:00
|
|
|
|
|
|
|
Before each QUERY there could be :KEYWORD VALUE pairs that
|
|
|
|
configure the query (and only that query). For example,
|
|
|
|
|
|
|
|
(treesit-font-lock-rules
|
2022-09-24 19:39:10 -07:00
|
|
|
:language \\='javascript
|
2022-10-04 13:28:46 -07:00
|
|
|
:override t
|
2022-10-13 14:44:42 -07:00
|
|
|
:feature\\='constant
|
2022-09-24 19:39:10 -07:00
|
|
|
\\='((true) @font-lock-constant-face
|
2022-09-07 11:46:07 -07:00
|
|
|
(false) @font-lock-constant-face)
|
2022-09-24 19:39:10 -07:00
|
|
|
:language \\='html
|
2022-10-13 14:44:42 -07:00
|
|
|
:feature \\='script
|
2022-09-07 11:46:07 -07:00
|
|
|
\"(script_element) @font-lock-builtin-face\")
|
|
|
|
|
2022-10-13 14:44:42 -07:00
|
|
|
For each QUERY, a :language keyword and a :feature keyword is
|
2022-10-28 06:38:00 +02:00
|
|
|
required. Each query's :feature is a symbol summarizing what does
|
2022-10-13 14:44:42 -07:00
|
|
|
the query fontify. It is used to allow users to enable/disable
|
|
|
|
certain features. See `treesit-font-lock-kind-list' for more.
|
|
|
|
Other keywords include:
|
2022-10-04 13:28:46 -07:00
|
|
|
|
2022-10-28 06:38:00 +02:00
|
|
|
KEYWORD VALUE DESCRIPTION
|
|
|
|
:override nil If the region already has a face,
|
|
|
|
discard the new face.
|
|
|
|
t Always apply the new face.
|
|
|
|
`append' Append the new face to existing ones.
|
|
|
|
`prepend' Prepend the new face to existing ones.
|
|
|
|
`keep' Fill-in regions without an existing face.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
Capture names in QUERY should be face names like
|
|
|
|
`font-lock-keyword-face'. The captured node will be fontified
|
2022-11-02 17:03:03 -07:00
|
|
|
with that face.
|
|
|
|
|
|
|
|
Capture names can also be function names, in which case the
|
2022-11-05 10:49:46 +02:00
|
|
|
function will be called with the following argument list:
|
2022-11-02 17:03:03 -07:00
|
|
|
|
|
|
|
(NODE OVERRIDE START END &rest _)
|
|
|
|
|
|
|
|
where NODE is the tree-sitter node object, OVERRIDE is the
|
2022-11-05 10:49:46 +02:00
|
|
|
override option of that rule, and START and END specify the region
|
2022-11-02 17:03:03 -07:00
|
|
|
to be fontified. This function should accept more arguments as
|
2022-11-05 10:49:46 +02:00
|
|
|
optional arguments for future extensibility, and it shouldn't
|
|
|
|
fontify text outside the region given by START and END.
|
2022-11-02 11:26:38 -07:00
|
|
|
|
|
|
|
If a capture name is both a face and a function, the face takes
|
2022-10-31 15:03:49 -07:00
|
|
|
priority. If a capture name is not a face name nor a function
|
2022-11-05 16:52:38 -07:00
|
|
|
name, it is ignored."
|
2022-10-28 16:38:37 -07:00
|
|
|
;; Other tree-sitter function don't tend to be called unless
|
|
|
|
;; tree-sitter is enabled, which means tree-sitter must be compiled.
|
|
|
|
;; But this function is usually call in `defvar' which runs
|
|
|
|
;; regardless whether tree-sitter is enabled. So we need this
|
|
|
|
;; guard.
|
|
|
|
(when (treesit-available-p)
|
|
|
|
(let (;; Tracks the current :language/:override/:toggle/:level value
|
|
|
|
;; that following queries will apply to.
|
|
|
|
current-language current-override
|
|
|
|
current-feature
|
|
|
|
;; The list this function returns.
|
|
|
|
(result nil))
|
2022-11-05 16:52:38 -07:00
|
|
|
(while query-specs
|
|
|
|
(let ((token (pop query-specs)))
|
2022-10-28 16:38:37 -07:00
|
|
|
(pcase token
|
|
|
|
;; (1) Process keywords.
|
|
|
|
(:language
|
2022-11-05 16:52:38 -07:00
|
|
|
(let ((lang (pop query-specs)))
|
2022-10-28 16:38:37 -07:00
|
|
|
(when (or (not (symbolp lang)) (null lang))
|
|
|
|
(signal 'treesit-font-lock-error
|
|
|
|
`("Value of :language should be a symbol"
|
|
|
|
,lang)))
|
|
|
|
(setq current-language lang)))
|
|
|
|
(:override
|
2022-11-05 16:52:38 -07:00
|
|
|
(let ((flag (pop query-specs)))
|
2022-10-28 16:38:37 -07:00
|
|
|
(when (not (memq flag '(t nil append prepend keep)))
|
|
|
|
(signal 'treesit-font-lock-error
|
|
|
|
`("Value of :override should be one of t, nil, append, prepend, keep"
|
|
|
|
,flag))
|
|
|
|
(signal 'wrong-type-argument
|
|
|
|
`((or t nil append prepend keep)
|
|
|
|
,flag)))
|
|
|
|
(setq current-override flag)))
|
|
|
|
(:feature
|
2022-11-05 16:52:38 -07:00
|
|
|
(let ((var (pop query-specs)))
|
2022-10-28 16:38:37 -07:00
|
|
|
(when (or (not (symbolp var))
|
|
|
|
(memq var '(t nil)))
|
|
|
|
(signal 'treesit-font-lock-error
|
|
|
|
`("Value of :feature should be a symbol"
|
|
|
|
,var)))
|
|
|
|
(setq current-feature var)))
|
|
|
|
;; (2) Process query.
|
|
|
|
((pred treesit-query-p)
|
|
|
|
(when (null current-language)
|
2022-10-07 01:21:09 -07:00
|
|
|
(signal 'treesit-font-lock-error
|
2022-10-28 16:38:37 -07:00
|
|
|
`("Language unspecified, use :language keyword to specify a language for this query" ,token)))
|
|
|
|
(when (null current-feature)
|
2022-10-07 01:21:09 -07:00
|
|
|
(signal 'treesit-font-lock-error
|
2022-10-28 16:38:37 -07:00
|
|
|
`("Feature unspecified, use :feature keyword to specify the feature name for this query" ,token)))
|
|
|
|
(if (treesit-compiled-query-p token)
|
|
|
|
(push `(,current-language token) result)
|
|
|
|
(push `(,(treesit-query-compile current-language token)
|
|
|
|
t
|
|
|
|
,current-feature
|
|
|
|
,current-override)
|
|
|
|
result))
|
|
|
|
;; Clears any configurations set for this query.
|
|
|
|
(setq current-language nil
|
|
|
|
current-override nil
|
|
|
|
current-feature nil))
|
|
|
|
(_ (signal 'treesit-font-lock-error
|
|
|
|
`("Unexpected value" ,token))))))
|
|
|
|
(nreverse result))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-30 20:56:21 -07:00
|
|
|
;; `font-lock-fontify-region-function' has the LOUDLY argument, but
|
|
|
|
;; `jit-lock-functions' doesn't pass that argument. So even if we set
|
|
|
|
;; `font-lock-verbose' to t, if jit-lock is enabled (and it's almost
|
|
|
|
;; always is), we don't get debug messages. So we add our own.
|
2022-10-31 14:26:03 -07:00
|
|
|
(defvar treesit--font-lock-verbose nil
|
2022-10-30 20:56:21 -07:00
|
|
|
"If non-nil, print debug messages when fontifying.")
|
|
|
|
|
2022-11-01 00:25:47 -07:00
|
|
|
(defun treesit-font-lock-recompute-features (&optional add-list remove-list)
|
2022-10-13 14:44:42 -07:00
|
|
|
"Enable/disable font-lock settings according to decoration level.
|
2022-11-01 00:25:47 -07:00
|
|
|
|
|
|
|
First compute the enabled features according to
|
2022-11-05 10:49:46 +02:00
|
|
|
`treesit-font-lock-feature-list' and `font-lock-maximum-decoration',
|
|
|
|
then, if ADD-LIST or REMOVE-LIST are not omitted, further add and
|
|
|
|
remove features accordingly.
|
2022-11-01 00:25:47 -07:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
ADD-LIST and REMOVE-LIST are each a list of feature symbols. The
|
|
|
|
same feature symbol cannot appear in both lists; the function
|
|
|
|
signals the `treesit-font-lock-error' error if so."
|
2022-11-01 00:25:47 -07:00
|
|
|
(when-let ((intersection (cl-intersection add-list remove-list)))
|
|
|
|
(signal 'treesit-font-lock-error
|
|
|
|
(list "ADD-LIST and REMOVE-LIST contain the same feature"
|
|
|
|
intersection)))
|
2022-10-13 14:44:42 -07:00
|
|
|
(let* ((level (font-lock-value-in-major-mode
|
|
|
|
font-lock-maximum-decoration))
|
2022-11-01 00:25:47 -07:00
|
|
|
(base-features (cl-loop
|
|
|
|
for idx = 0 then (1+ idx)
|
|
|
|
for features in treesit-font-lock-feature-list
|
|
|
|
if (or (eq level t)
|
|
|
|
(>= level (1+ idx)))
|
|
|
|
append features))
|
|
|
|
(features (cl-set-difference (cl-union base-features add-list)
|
|
|
|
remove-list)))
|
2022-10-13 14:44:42 -07:00
|
|
|
(cl-loop for idx = 0 then (1+ idx)
|
|
|
|
for setting in treesit-font-lock-settings
|
|
|
|
for feature = (nth 2 setting)
|
|
|
|
;; Set the ENABLE flag for the setting.
|
|
|
|
do (setf (nth 1 (nth idx treesit-font-lock-settings))
|
|
|
|
(if (memq feature features) t nil)))))
|
|
|
|
|
2022-10-31 15:03:49 -07:00
|
|
|
(defun treesit-fontify-with-override (start end face override)
|
|
|
|
"Apply FACE to the region between START and END.
|
|
|
|
OVERRIDE can be nil, t, `append', `prepend', or `keep'.
|
|
|
|
See `treesit-font-lock-rules' for their semantic."
|
|
|
|
(pcase override
|
|
|
|
('nil (unless (text-property-not-all
|
|
|
|
start end 'face nil)
|
|
|
|
(put-text-property start end 'face face)))
|
|
|
|
('t (put-text-property start end 'face face))
|
|
|
|
('append (font-lock-append-text-property
|
|
|
|
start end 'face face))
|
|
|
|
('prepend (font-lock-prepend-text-property
|
|
|
|
start end 'face face))
|
|
|
|
('keep (font-lock-fillin-text-property
|
|
|
|
start end 'face face))
|
|
|
|
(_ (signal 'treesit-font-lock-error
|
|
|
|
(list
|
|
|
|
"Unrecognized value of :override option"
|
|
|
|
override)))))
|
|
|
|
|
2022-11-02 16:31:25 -07:00
|
|
|
(defun treesit--set-nonsticky (start end sym &optional remove)
|
|
|
|
"Set `rear-nonsticky' property between START and END.
|
|
|
|
Set the proeprty to a list containing SYM. If there is already a
|
|
|
|
list, add SYM to that list. If REMOVE is non-nil, remove SYM
|
|
|
|
instead."
|
|
|
|
(let* ((prop (get-text-property start 'rear-nonsticky))
|
|
|
|
(new-prop
|
|
|
|
(pcase prop
|
|
|
|
((pred listp) ; PROP is a list or nil.
|
|
|
|
(if remove
|
|
|
|
(remove sym prop)
|
|
|
|
;; We should make sure PORP doesn't contain SYM, but
|
|
|
|
;; whatever.
|
|
|
|
(cons sym prop)))
|
|
|
|
;; PROP is t.
|
|
|
|
(_ (if remove
|
|
|
|
nil
|
|
|
|
(list sym))))))
|
|
|
|
(if (null new-prop)
|
|
|
|
(remove-text-properties start end '(rear-nonsticky nil))
|
|
|
|
(put-text-property start end 'rear-nonsticky new-prop))))
|
|
|
|
|
|
|
|
;; This post-processing tries to deal with the following scenario:
|
2022-11-05 10:49:46 +02:00
|
|
|
;; User inserts "/*" in a buffer under C mode, then goes down the
|
|
|
|
;; buffer and inserts "*/". Before the user inserts "*/", tree-sitter
|
|
|
|
;; cannot construct a comment node and the parse tree is incomplete,
|
|
|
|
;; and we can't fontify the comment. But once the user inserts the
|
|
|
|
;; "*/", the parse-tree is complete and we want to refontify the whole
|
|
|
|
;; comment, and possibly text after comment (the "/*" could damage the
|
|
|
|
;; parse tree enough that makes tree-sitter unable to produce
|
|
|
|
;; reasonable information for text after it).
|
2022-11-02 16:31:25 -07:00
|
|
|
;;
|
|
|
|
;; So we set jit-lock-context-unfontify-pos to comment start, and
|
|
|
|
;; jit-lock-context will refontify text after that position in a
|
|
|
|
;; timer. Refontifying those text will end up calling this function
|
|
|
|
;; again, and we don't want to fall into infinite recursion. So we
|
2022-11-05 10:49:46 +02:00
|
|
|
;; mark the end of the comment with a text property, to be able to
|
|
|
|
;; distinguish between initial and follow-up invocation of this
|
2022-11-02 16:31:25 -07:00
|
|
|
;; function.
|
|
|
|
(defun treesit-font-lock-contextual-post-process
|
|
|
|
(node start end &optional verbose)
|
2022-11-05 10:49:46 +02:00
|
|
|
"Post-process contextual syntax NODE for fontification between START and END.
|
|
|
|
NODE is a comment or string node, START and END specify the region
|
2022-11-02 16:31:25 -07:00
|
|
|
being fontified.
|
|
|
|
|
|
|
|
If VERBOSE is non-nil, print debugging information."
|
|
|
|
(let* ((node-start (treesit-node-start node))
|
|
|
|
(node-end (treesit-node-end node))
|
|
|
|
(node-end-1 (max (point-min) (1- node-end)))
|
|
|
|
(prop-sym 'treesit-context-refontify-in-progress))
|
|
|
|
(when verbose
|
|
|
|
(message "Contextual: region: %s-%s, node: %s-%s"
|
|
|
|
start end node-start node-end))
|
2022-11-03 19:37:55 -07:00
|
|
|
(when (and (< node-start start) (<= node-end end))
|
2022-11-02 16:31:25 -07:00
|
|
|
(if (get-text-property node-end-1 prop-sym)
|
|
|
|
;; We are called from a refontification by jit-lock-context,
|
|
|
|
;; caused by a previous call to this function.
|
|
|
|
(progn (when verbose
|
|
|
|
(message "Contextual: in progress"))
|
|
|
|
(remove-text-properties
|
|
|
|
node-end-1 node-end `(,prop-sym nil))
|
|
|
|
(treesit--set-nonsticky node-end-1 node-end prop-sym t))
|
|
|
|
;; We are called from a normal fontification.
|
|
|
|
(when verbose
|
|
|
|
(message "Contextual: initial"))
|
|
|
|
(setq jit-lock-context-unfontify-pos node-start)
|
|
|
|
(put-text-property node-end-1 node-end prop-sym t)
|
|
|
|
(treesit--set-nonsticky node-end-1 node-end prop-sym)))))
|
|
|
|
|
|
|
|
;; Some details worth explaining:
|
|
|
|
;;
|
|
|
|
;; 1. When we apply face to a node, we clip the face into the
|
|
|
|
;; currently fontifying region, this way we don't overwrite faces
|
|
|
|
;; applied by regexp-based font-lock. The clipped part will be
|
|
|
|
;; fontified fine when Emacs fontifies the region containing it.
|
|
|
|
;;
|
2022-10-04 13:28:46 -07:00
|
|
|
(defun treesit-font-lock-fontify-region
|
|
|
|
(start end &optional loudly)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"Fontify the region between START and END.
|
2022-10-27 08:02:58 +02:00
|
|
|
If LOUDLY is non-nil, display some debugging information."
|
2022-10-31 14:26:03 -07:00
|
|
|
(when (or loudly treesit--font-lock-verbose)
|
2022-10-30 20:56:21 -07:00
|
|
|
(message "Fontifying region: %s-%s" start end))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(treesit-update-ranges start end)
|
|
|
|
(font-lock-unfontify-region start end)
|
|
|
|
(dolist (setting treesit-font-lock-settings)
|
2022-10-13 14:44:42 -07:00
|
|
|
(let* ((query (nth 0 setting))
|
|
|
|
(enable (nth 1 setting))
|
|
|
|
(override (nth 3 setting))
|
|
|
|
(language (treesit-query-language query)))
|
2022-10-31 15:27:40 -07:00
|
|
|
;; Why root node rather than (treesit-node-on start end)? If
|
|
|
|
;; you insert an ending quote into a buffer, jit-lock only wants
|
|
|
|
;; to fontify that single quote, and (treesit-node-on start end)
|
|
|
|
;; will give you that quote node. We want to capture the string
|
|
|
|
;; and apply string face to it, but querying on the quote node
|
|
|
|
;; will not give us the string node.
|
|
|
|
(when-let ((root (treesit-buffer-root-node language))
|
2022-10-13 14:44:42 -07:00
|
|
|
;; Only activate if ENABLE flag is t.
|
|
|
|
(activate (eq t enable)))
|
2022-10-07 01:21:09 -07:00
|
|
|
(ignore activate)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(let ((captures (treesit-query-capture
|
2022-10-31 15:27:40 -07:00
|
|
|
root query start end))
|
2022-10-04 13:28:46 -07:00
|
|
|
(inhibit-point-motion-hooks t))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(with-silent-modifications
|
|
|
|
(dolist (capture captures)
|
|
|
|
(let* ((face (car capture))
|
|
|
|
(node (cdr capture))
|
2022-11-02 16:31:25 -07:00
|
|
|
(node-start (treesit-node-start node))
|
|
|
|
(node-end (treesit-node-end node)))
|
2022-10-04 13:28:46 -07:00
|
|
|
(cond
|
2022-11-02 16:31:25 -07:00
|
|
|
((eq face 'contextual)
|
|
|
|
(treesit-font-lock-contextual-post-process
|
|
|
|
node start end
|
|
|
|
(or loudly treesit--font-lock-verbose)))
|
2022-10-04 13:28:46 -07:00
|
|
|
((facep face)
|
2022-11-02 16:31:25 -07:00
|
|
|
(treesit-fontify-with-override
|
|
|
|
(max node-start start) (min node-end end)
|
|
|
|
face override))
|
2022-10-04 13:28:46 -07:00
|
|
|
((functionp face)
|
2022-11-02 17:03:03 -07:00
|
|
|
(funcall face node override start end)))
|
2022-10-01 20:25:25 -07:00
|
|
|
;; Don't raise an error if FACE is neither a face nor
|
|
|
|
;; a function. This is to allow intermediate capture
|
|
|
|
;; names used for #match and #eq.
|
2022-10-31 14:26:03 -07:00
|
|
|
(when (or loudly treesit--font-lock-verbose)
|
2022-11-01 00:26:15 -07:00
|
|
|
(message "Fontifying text from %d to %d, Face: %s, Node: %s"
|
|
|
|
start end face (treesit-node-type node))))))))))
|
2022-10-30 20:56:21 -07:00
|
|
|
`(jit-lock-bounds ,start . ,end))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
;;; Indent
|
|
|
|
|
2022-11-04 09:56:38 -07:00
|
|
|
(define-error 'treesit-indent-error
|
|
|
|
"Generic tree-sitter indentation error"
|
|
|
|
'treesit-error)
|
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(defvar treesit--indent-verbose nil
|
|
|
|
"If non-nil, log progress when indenting.")
|
|
|
|
|
2022-10-25 14:27:23 -07:00
|
|
|
(defvar-local treesit-simple-indent-rules nil
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"A list of indent rule settings.
|
|
|
|
Each indent rule setting should be (LANGUAGE . RULES),
|
|
|
|
where LANGUAGE is a language symbol, and RULES is a list of
|
|
|
|
|
|
|
|
(MATCHER ANCHOR OFFSET).
|
|
|
|
|
|
|
|
MATCHER determines whether this rule applies, ANCHOR and OFFSET
|
|
|
|
together determines which column to indent to.
|
|
|
|
|
|
|
|
A MATCHER is a function that takes three arguments (NODE PARENT
|
|
|
|
BOL). BOL is the point where we are indenting: the beginning of
|
|
|
|
line content, the position of the first non-whitespace character.
|
|
|
|
NODE is the largest (highest-in-tree) node starting at that
|
|
|
|
point. PARENT is the parent of NODE.
|
|
|
|
|
|
|
|
If MATCHER returns non-nil, meaning the rule matches, Emacs then
|
|
|
|
uses ANCHOR to find an anchor, it should be a function that takes
|
|
|
|
the same argument (NODE PARENT BOL) and returns a point.
|
|
|
|
|
|
|
|
Finally Emacs computes the column of that point returned by ANCHOR
|
|
|
|
and adds OFFSET to it, and indents to that column.
|
|
|
|
|
|
|
|
For MATCHER and ANCHOR, Emacs provides some convenient presets.
|
|
|
|
See `treesit-simple-indent-presets'.")
|
|
|
|
|
|
|
|
(defvar treesit-simple-indent-presets
|
2022-10-29 14:50:25 -07:00
|
|
|
(list (cons 'match
|
|
|
|
(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-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.
|
|
|
|
(cons 'n-p-gp
|
|
|
|
(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))))))))
|
|
|
|
(cons 'no-node (lambda (node &rest _) (null node)))
|
|
|
|
(cons 'parent-is (lambda (type)
|
|
|
|
(lambda (_n parent &rest _)
|
2022-10-28 17:56:05 -07:00
|
|
|
(string-match-p
|
2022-10-29 14:50:25 -07:00
|
|
|
type (treesit-node-type parent)))))
|
|
|
|
|
|
|
|
(cons 'node-is (lambda (type)
|
|
|
|
(lambda (node &rest _)
|
|
|
|
(string-match-p
|
|
|
|
type (or (treesit-node-type node) "")))))
|
|
|
|
(cons 'field-is (lambda (name)
|
|
|
|
(lambda (node &rest _)
|
|
|
|
(string-match-p
|
|
|
|
name (or (treesit-node-field-name node) "")))))
|
|
|
|
;; TODO: Document.
|
|
|
|
(cons 'catch-all (lambda (&rest _) t))
|
|
|
|
|
|
|
|
(cons 'query (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))))
|
|
|
|
(cons 'first-sibling (lambda (_n parent &rest _)
|
|
|
|
(treesit-node-start
|
|
|
|
(treesit-node-child parent 0))))
|
|
|
|
;; TODO: Document.
|
|
|
|
(cons 'nth-sibling (lambda (n &optional named)
|
|
|
|
(lambda (_n parent &rest _)
|
|
|
|
(treesit-node-start
|
|
|
|
(treesit-node-child parent n named)))))
|
|
|
|
(cons 'parent (lambda (_n parent &rest _)
|
|
|
|
(treesit-node-start parent)))
|
|
|
|
;; TODO: Document.
|
|
|
|
(cons 'grand-parent
|
|
|
|
(lambda (_n parent &rest _)
|
|
|
|
(treesit-node-start (treesit-node-parent parent))))
|
|
|
|
(cons 'parent-bol (lambda (_n parent &rest _)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (treesit-node-start parent))
|
|
|
|
(back-to-indentation)
|
|
|
|
(point))))
|
|
|
|
(cons 'prev-sibling (lambda (node &rest _)
|
|
|
|
(treesit-node-start
|
|
|
|
(treesit-node-prev-sibling node))))
|
|
|
|
(cons 'no-indent (lambda (_n _p bol &rest _) bol))
|
|
|
|
(cons 'prev-line (lambda (_n _p bol &rest _)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char bol)
|
|
|
|
(forward-line -1)
|
|
|
|
(skip-chars-forward " \t"))))
|
|
|
|
;; TODO: Document.
|
|
|
|
(cons 'and (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)))))
|
|
|
|
(cons '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)))))
|
|
|
|
(cons 'not (lambda (fn)
|
|
|
|
(lambda (node parent bol &rest _)
|
|
|
|
(debug)
|
|
|
|
(not (funcall fn node parent bol)))))
|
|
|
|
(cons 'list (lambda (&rest fns)
|
|
|
|
(lambda (node parent bol &rest _)
|
|
|
|
(mapcar (lambda (fn)
|
|
|
|
(funcall fn node parent bol))
|
|
|
|
fns)))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"A list of presets.
|
|
|
|
These presets that can be used as MATHER and ANCHOR in
|
|
|
|
`treesit-simple-indent-rules'.
|
|
|
|
|
|
|
|
MATCHER:
|
|
|
|
|
|
|
|
\(match NODE-TYPE PARENT-TYPE NODE-FIELD NODE-INDEX-MIN NODE-INDEX-MAX)
|
|
|
|
|
|
|
|
NODE-TYPE checks for node's type, PARENT-TYPE checks for
|
|
|
|
parent's type, NODE-FIELD checks for the filed name of node
|
|
|
|
in the parent, NODE-INDEX-MIN and NODE-INDEX-MAX checks for
|
|
|
|
the node's index in the parent. Therefore, to match the
|
|
|
|
first child where parent is \"argument_list\", use
|
|
|
|
|
|
|
|
(match nil \"argument_list\" nil nil 0 0).
|
|
|
|
|
2022-10-27 16:50:20 -07:00
|
|
|
NODE-TYPE, PARENT-TYPE, and NODE-FIELD are regexps.
|
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
no-node
|
|
|
|
|
|
|
|
Matches the case where node is nil, i.e., there is no node
|
|
|
|
that starts at point. This is the case when indenting an
|
|
|
|
empty line.
|
|
|
|
|
|
|
|
\(parent-is TYPE)
|
|
|
|
|
2022-10-27 16:50:20 -07:00
|
|
|
Check that the parent's type matches regexp TYPE.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
\(node-is TYPE)
|
|
|
|
|
2022-10-27 16:50:20 -07:00
|
|
|
Checks that the node's type matches regexp TYPE.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
\(query QUERY)
|
|
|
|
|
|
|
|
Queries the parent node with QUERY, and checks if the node
|
|
|
|
is captured (by any capture name).
|
|
|
|
|
|
|
|
ANCHOR:
|
|
|
|
|
|
|
|
first-sibling
|
|
|
|
|
|
|
|
Find the first child of the parent.
|
|
|
|
|
|
|
|
parent
|
|
|
|
|
|
|
|
Find the parent.
|
|
|
|
|
|
|
|
parent-bol
|
|
|
|
|
|
|
|
Find the beginning of non-space characters on the line where
|
|
|
|
the parent is on.
|
|
|
|
|
|
|
|
prev-sibling
|
|
|
|
|
|
|
|
Find node's previous sibling.
|
|
|
|
|
|
|
|
no-indent
|
|
|
|
|
|
|
|
Do nothing.
|
|
|
|
|
|
|
|
prev-line
|
|
|
|
|
2022-09-30 16:54:42 -07:00
|
|
|
The first non-whitespace charater on the previous line.")
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-10-26 18:31:43 -07:00
|
|
|
(defun treesit--simple-indent-eval (exp)
|
|
|
|
"Evaluate EXP.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
If EXP is an application and the function is a key in
|
2022-10-26 18:31:43 -07:00
|
|
|
`treesit-simple-indent-presets', use the corresponding value as
|
|
|
|
the function."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
;; We don't want to match uncompiled lambdas, so make sure this cons
|
|
|
|
;; is not a function. We could move the condition functionp
|
|
|
|
;; forward, but better be explicit.
|
2022-10-26 18:31:43 -07:00
|
|
|
(cond ((and (consp exp) (not (functionp exp)))
|
|
|
|
(apply (treesit--simple-indent-eval (car exp))
|
|
|
|
(mapcar #'treesit--simple-indent-eval
|
|
|
|
(cdr exp))))
|
|
|
|
;; Presets override functions, so this condition comes before
|
|
|
|
;; `functionp'.
|
|
|
|
((alist-get exp treesit-simple-indent-presets)
|
|
|
|
(alist-get exp treesit-simple-indent-presets))
|
|
|
|
((functionp exp) exp)
|
|
|
|
((symbolp exp)
|
|
|
|
(if (null exp)
|
|
|
|
exp
|
|
|
|
;; Matchers only return lambdas, anchors only return
|
|
|
|
;; integer, so we should never see a variable.
|
2022-11-04 09:56:38 -07:00
|
|
|
(signal 'treesit-indent-error
|
2022-11-05 10:49:46 +02:00
|
|
|
(list "Couldn't find the preset corresponding to expression"
|
|
|
|
exp))))
|
2022-10-26 18:31:43 -07:00
|
|
|
(t exp)))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
;; This variable might seem unnecessary: why split
|
|
|
|
;; `treesit-indent' and `treesit-simple-indent' into two
|
|
|
|
;; functions? We add this variable in between because later we might
|
|
|
|
;; add more powerful indentation engines, and that new engine can
|
|
|
|
;; probably share `treesit-indent'. It is also useful, suggested
|
|
|
|
;; by Stefan M, to have a function that figures out how much to indent
|
|
|
|
;; but doesn't actually performs the indentation, because we might
|
|
|
|
;; want to know where will a node indent to if we put it at some other
|
|
|
|
;; location, and use that information to calculate the actual
|
|
|
|
;; indentation. And `treesit-simple-indent' is that function. I
|
|
|
|
;; forgot the example Stefan gave, but it makes a lot of sense.
|
|
|
|
(defvar treesit-indent-function #'treesit-simple-indent
|
|
|
|
"Function used by `treesit-indent' to do some of the work.
|
|
|
|
|
|
|
|
This function is called with
|
|
|
|
|
|
|
|
(NODE PARENT BOL &rest _)
|
|
|
|
|
|
|
|
and returns
|
|
|
|
|
|
|
|
(ANCHOR . OFFSET).
|
|
|
|
|
|
|
|
BOL is the position of the beginning of the line; NODE is the
|
|
|
|
\"largest\" node that starts at BOL; PARENT is its parent; ANCHOR
|
|
|
|
is a point (not a node), and OFFSET is a number. Emacs finds the
|
|
|
|
column of ANCHOR and adds OFFSET to it as the final indentation
|
|
|
|
of the current line.")
|
|
|
|
|
2022-10-28 17:54:43 -07:00
|
|
|
(defun treesit--indent-1 ()
|
|
|
|
"Indent the current line.
|
2022-10-29 09:04:35 -07:00
|
|
|
Return (ANCHOR . OFFSET). This function is used by
|
|
|
|
`treesit-indent' and `treesit-indent-region'."
|
2022-10-28 17:54:43 -07:00
|
|
|
;; Basically holds the common part between the two indent function.
|
|
|
|
(let* ((bol (save-excursion
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(forward-line 0)
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
(point)))
|
|
|
|
(smallest-node
|
2022-10-25 14:26:41 -07:00
|
|
|
(cond ((null (treesit-parser-list)) nil)
|
|
|
|
((eq 1 (length (treesit-parser-list)))
|
2022-10-29 09:43:50 -07:00
|
|
|
(treesit-node-at bol nil nil t))
|
2022-10-25 14:26:41 -07:00
|
|
|
((treesit-language-at (point))
|
|
|
|
(treesit-node-at bol (treesit-language-at (point))))
|
|
|
|
(t (treesit-node-at bol))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(node (treesit-parent-while
|
|
|
|
smallest-node
|
|
|
|
(lambda (node)
|
|
|
|
(eq bol (treesit-node-start node))))))
|
2022-10-29 09:04:35 -07:00
|
|
|
(let*
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
((parser (if smallest-node
|
|
|
|
(treesit-node-parser smallest-node)
|
|
|
|
nil))
|
|
|
|
;; NODE would be nil if BOL is on a whitespace. In that case
|
|
|
|
;; we set PARENT to the "node at point", which would
|
|
|
|
;; encompass the whitespace.
|
|
|
|
(parent (cond ((and node parser)
|
|
|
|
(treesit-node-parent node))
|
2022-10-29 09:43:50 -07:00
|
|
|
(t (treesit-node-on bol bol)))))
|
2022-10-29 09:04:35 -07:00
|
|
|
(funcall treesit-indent-function node parent bol))))
|
2022-10-28 17:54:43 -07:00
|
|
|
|
|
|
|
(defun treesit-indent ()
|
|
|
|
"Indent according to the result of `treesit-indent-function'."
|
2022-11-04 01:31:56 -07:00
|
|
|
(treesit-update-ranges (line-beginning-position)
|
|
|
|
(line-end-position))
|
2022-10-29 14:49:31 -07:00
|
|
|
;; We don't return 'noindent even if no rules match, because
|
|
|
|
;; `indent-for-tab-command' tries to indent itself when we return
|
|
|
|
;; 'noindent, which leads to wrong indentation at times.
|
2022-10-29 09:43:50 -07:00
|
|
|
(pcase-let* ((`(,anchor . ,offset) (treesit--indent-1)))
|
2022-10-29 14:49:31 -07:00
|
|
|
(when (and anchor offset)
|
|
|
|
(let ((col (+ (save-excursion
|
|
|
|
(goto-char anchor)
|
|
|
|
(current-column))
|
|
|
|
offset))
|
|
|
|
(delta (- (point-max) (point))))
|
|
|
|
(indent-line-to col)
|
|
|
|
;; Now point is at the end of indentation. If we started
|
|
|
|
;; from within the line, go back to where we started.
|
|
|
|
(when (> (- (point-max) delta) (point))
|
|
|
|
(goto-char (- (point-max) delta)))))))
|
2022-10-29 09:04:35 -07:00
|
|
|
|
|
|
|
(defvar treesit--indent-region-batch-size 400
|
2022-10-28 17:54:43 -07:00
|
|
|
"How many lines of indent value do we precompute.
|
|
|
|
In `treesit-indent-region' we indent in batches: precompute
|
|
|
|
indent for each line, apply them in one go, let parser reparse,
|
|
|
|
and do it again. This way the parser don't need to unnecessarily
|
|
|
|
reparse after indenting every single line.")
|
|
|
|
|
|
|
|
(defun treesit-indent-region (beg end)
|
|
|
|
"Indent the region between BEG and END.
|
|
|
|
Similar to `treesit-indent', but indent a region instead."
|
2022-11-04 01:31:56 -07:00
|
|
|
(treesit-update-ranges beg end)
|
2022-10-29 09:04:35 -07:00
|
|
|
(let* ((meta-len 2)
|
|
|
|
(vector-len (* meta-len treesit--indent-region-batch-size))
|
|
|
|
;; This vector saves the indent meta for each line in the
|
|
|
|
;; batch. It is a vector of [ANCHOR OFFSET BOL DELTA], where
|
|
|
|
;; BOL is the position of BOL of that line, and DELTA =
|
|
|
|
;; DESIRED-INDENT - CURRENT-INDENT.
|
|
|
|
(meta-vec (make-vector vector-len 0))
|
|
|
|
(lines-left-to-move 0)
|
|
|
|
(end (copy-marker end t))
|
|
|
|
(idx 0)
|
|
|
|
(starting-pos 0)
|
|
|
|
(announce-progress (> (- end beg) 80000)))
|
2022-10-28 17:54:43 -07:00
|
|
|
(save-excursion
|
|
|
|
(goto-char beg)
|
2022-10-29 09:04:35 -07:00
|
|
|
;; First pass. Go through each line and compute the
|
|
|
|
;; indentation.
|
2022-10-28 17:54:43 -07:00
|
|
|
(while (and (eq lines-left-to-move 0) (< (point) end))
|
2022-10-29 09:04:35 -07:00
|
|
|
(setq idx 0
|
2022-10-28 17:54:43 -07:00
|
|
|
starting-pos (point))
|
|
|
|
(while (and (eq lines-left-to-move 0)
|
|
|
|
(< idx treesit--indent-region-batch-size)
|
|
|
|
(< (point) end))
|
2022-10-29 09:04:35 -07:00
|
|
|
(pcase-let* ((`(,anchor . ,offset) (treesit--indent-1))
|
|
|
|
(marker (aref meta-vec (* idx meta-len))))
|
|
|
|
;; Set ANCHOR.
|
|
|
|
(when anchor
|
|
|
|
(if (markerp marker)
|
|
|
|
(move-marker marker anchor)
|
|
|
|
(setf (aref meta-vec (* idx meta-len))
|
|
|
|
(copy-marker anchor t))))
|
|
|
|
;; SET OFFSET.
|
|
|
|
(setf (aref meta-vec (+ 1 (* idx meta-len))) offset))
|
2022-10-28 17:54:43 -07:00
|
|
|
(cl-incf idx)
|
|
|
|
(setq lines-left-to-move (forward-line 1)))
|
|
|
|
;; Now IDX = last valid IDX + 1.
|
|
|
|
(goto-char starting-pos)
|
2022-10-29 09:04:35 -07:00
|
|
|
;; Second pass, go to each line and apply the indentation.
|
|
|
|
(dotimes (jdx idx)
|
|
|
|
(let ((anchor (aref meta-vec (* jdx meta-len)))
|
|
|
|
(offset (aref meta-vec (+ 1 (* jdx meta-len)))))
|
|
|
|
(when offset
|
|
|
|
(let ((col (save-excursion
|
|
|
|
(goto-char anchor)
|
|
|
|
(+ offset (current-column)))))
|
|
|
|
(indent-line-to col))))
|
|
|
|
(forward-line 1))
|
2022-10-28 17:54:43 -07:00
|
|
|
(when announce-progress
|
|
|
|
(message "Indenting region...%s%%"
|
2022-10-29 09:04:35 -07:00
|
|
|
(/ (* (- (point) beg) 100) (- end beg)))))
|
|
|
|
;; Delete markers.
|
|
|
|
(dotimes (idx treesit--indent-region-batch-size)
|
|
|
|
(let ((marker (aref meta-vec (* idx meta-len))))
|
|
|
|
(when (markerp marker)
|
|
|
|
(move-marker marker nil))))
|
|
|
|
(move-marker end nil))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
(defun treesit-simple-indent (node parent bol)
|
|
|
|
"Calculate indentation according to `treesit-simple-indent-rules'.
|
|
|
|
|
|
|
|
BOL is the position of the first non-whitespace character on the
|
|
|
|
current line. NODE is the largest node that starts at BOL,
|
|
|
|
PARENT is NODE's parent.
|
|
|
|
|
|
|
|
Return (ANCHOR . OFFSET) where ANCHOR is a node, OFFSET is the
|
|
|
|
indentation offset, meaning indent to align with ANCHOR and add
|
|
|
|
OFFSET."
|
|
|
|
(if (null parent)
|
2022-10-29 14:49:31 -07:00
|
|
|
(progn (when treesit--indent-verbose
|
|
|
|
(message "PARENT is nil, not indenting"))
|
|
|
|
(cons nil nil))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(let* ((language (treesit-node-language parent))
|
|
|
|
(rules (alist-get language
|
|
|
|
treesit-simple-indent-rules)))
|
|
|
|
(cl-loop for rule in rules
|
|
|
|
for pred = (nth 0 rule)
|
|
|
|
for anchor = (nth 1 rule)
|
|
|
|
for offset = (nth 2 rule)
|
2022-10-26 18:31:43 -07:00
|
|
|
if (treesit--simple-indent-eval
|
|
|
|
(list pred node parent bol))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
do (when treesit--indent-verbose
|
|
|
|
(message "Matched rule: %S" rule))
|
|
|
|
and
|
2022-10-26 18:31:43 -07:00
|
|
|
return
|
|
|
|
(let ((anchor-pos
|
|
|
|
(treesit--simple-indent-eval
|
|
|
|
(list anchor node parent bol))))
|
2022-10-27 16:44:33 -07:00
|
|
|
(cons anchor-pos offset))
|
|
|
|
finally return
|
|
|
|
(progn (when treesit--indent-verbose
|
|
|
|
(message "No matched rule"))
|
|
|
|
(cons nil nil))))))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
(defun treesit-check-indent (mode)
|
|
|
|
"Check current buffer's indentation against a major mode MODE.
|
|
|
|
|
|
|
|
Pop up a diff buffer showing the difference. Correct
|
|
|
|
indentation (target) is in green, current indentation is in red."
|
|
|
|
(interactive "CTarget major mode: ")
|
|
|
|
(let ((source-buf (current-buffer)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-buffer-substring source-buf)
|
|
|
|
(funcall mode)
|
|
|
|
(indent-region (point-min) (point-max))
|
|
|
|
(diff-buffers source-buf (current-buffer)))))
|
|
|
|
|
2022-05-13 16:39:29 -07:00
|
|
|
;;; Search
|
2022-05-13 14:00:56 -07:00
|
|
|
|
2022-09-24 19:35:11 -07:00
|
|
|
(defun treesit-search-forward-goto
|
2022-10-23 18:29:02 -07:00
|
|
|
(node predicate &optional start backward all)
|
2022-10-23 14:56:17 -07:00
|
|
|
"Search forward for a node and move to its end position.
|
2022-09-24 19:35:11 -07:00
|
|
|
|
2022-10-27 08:02:58 +02:00
|
|
|
Stop at the first node after NODE that matches PREDICATE.
|
2022-09-24 20:42:03 -07:00
|
|
|
PREDICATE can be either a regexp that matches against each node's
|
2022-10-01 20:29:35 -07:00
|
|
|
type case-insensitively, or a function that takes a node and
|
|
|
|
returns nil/non-nil for match/no match.
|
2022-09-24 19:35:11 -07:00
|
|
|
|
|
|
|
If a node matches, move to that node and return the node,
|
2022-10-23 14:56:17 -07:00
|
|
|
otherwise return nil. If START is non-nil, stop at the
|
|
|
|
beginning rather than the end of a node.
|
2022-09-24 19:35:11 -07:00
|
|
|
|
2022-10-23 18:29:02 -07:00
|
|
|
This function guarantees that the matched node it returns makes
|
|
|
|
progress in terms of buffer position: the start/end position of
|
|
|
|
the returned node is always greater than that of NODE.
|
|
|
|
|
2022-10-23 14:56:17 -07:00
|
|
|
BACKWARD and ALL are the same as in `treesit-search-forward'."
|
2022-10-26 15:34:02 -07:00
|
|
|
(when-let* ((start-pos (if start
|
|
|
|
(treesit-node-start node)
|
|
|
|
(treesit-node-end node)))
|
|
|
|
(current-pos start-pos))
|
2022-10-23 14:56:17 -07:00
|
|
|
;; When searching forward and stopping at beginnings, or search
|
|
|
|
;; backward stopping at ends, it is possible to "roll back" in
|
|
|
|
;; position. Take three nodes N1, N2, N3 as an example, if we
|
|
|
|
;; start at N3, search for forward for beginning, and N1 matches,
|
2022-10-23 18:29:02 -07:00
|
|
|
;; we would stop at beg of N1, which is backwards! So we skip N1
|
|
|
|
;; and keep going.
|
2022-10-23 14:56:17 -07:00
|
|
|
;;
|
|
|
|
;; |<--------N1------->|
|
|
|
|
;; |<--N2-->| |<--N3-->|
|
2022-09-24 20:42:03 -07:00
|
|
|
(while (and node (if backward
|
2022-10-26 15:34:02 -07:00
|
|
|
(>= current-pos start-pos)
|
|
|
|
(<= current-pos start-pos)))
|
2022-09-24 20:42:03 -07:00
|
|
|
(setq node (treesit-search-forward
|
2022-10-23 14:56:17 -07:00
|
|
|
node predicate backward all))
|
2022-10-26 15:34:02 -07:00
|
|
|
(setq current-pos (if start
|
|
|
|
(treesit-node-start node)
|
|
|
|
(treesit-node-end node))))
|
|
|
|
(cond
|
|
|
|
;; When there is a match and match made progress, go to the
|
|
|
|
;; result position.
|
|
|
|
((and node
|
|
|
|
(if backward
|
|
|
|
(< current-pos (point))
|
|
|
|
(> current-pos (point))))
|
|
|
|
(goto-char current-pos)))
|
2022-09-24 19:35:11 -07:00
|
|
|
node))
|
2022-05-13 14:00:56 -07:00
|
|
|
|
2022-10-19 16:44:04 -07:00
|
|
|
;;; Navigation
|
|
|
|
|
|
|
|
(defvar-local treesit-defun-type-regexp nil
|
|
|
|
"A regexp that matches the node type of defun nodes.
|
|
|
|
For example, \"(function|class)_definition\".
|
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
This is used by `treesit-beginning-of-defun' and friends.")
|
2022-10-19 16:44:04 -07:00
|
|
|
|
|
|
|
(defun treesit-beginning-of-defun (&optional arg)
|
|
|
|
"Tree-sitter `beginning-of-defun' function.
|
2022-10-27 08:02:58 +02:00
|
|
|
ARG is the same as in `beginning-of-defun'."
|
2022-10-23 18:47:02 -07:00
|
|
|
(let ((arg (or arg 1))
|
|
|
|
(node (treesit-node-at (point))))
|
2022-10-19 16:44:04 -07:00
|
|
|
(if (> arg 0)
|
|
|
|
;; Go backward.
|
|
|
|
(while (and (> arg 0)
|
2022-10-23 18:47:02 -07:00
|
|
|
(setq node (treesit-search-forward-goto
|
|
|
|
node treesit-defun-type-regexp t t)))
|
2022-10-29 14:11:52 -07:00
|
|
|
(setq node (or (treesit-node-top-level
|
|
|
|
node treesit-defun-type-regexp)
|
|
|
|
node))
|
2022-10-19 16:44:04 -07:00
|
|
|
(setq arg (1- arg)))
|
|
|
|
;; Go forward.
|
|
|
|
(while (and (< arg 0)
|
2022-10-23 18:47:02 -07:00
|
|
|
(setq node (treesit-search-forward-goto
|
2022-10-26 15:34:02 -07:00
|
|
|
node treesit-defun-type-regexp)))
|
2022-10-29 14:11:52 -07:00
|
|
|
(setq node (or (treesit-node-top-level
|
|
|
|
node treesit-defun-type-regexp)
|
|
|
|
node))
|
2022-10-23 18:47:02 -07:00
|
|
|
(setq arg (1+ arg))))
|
2022-10-26 15:34:02 -07:00
|
|
|
(when node
|
|
|
|
(goto-char (treesit-node-start node))
|
|
|
|
t)))
|
2022-10-19 16:44:04 -07:00
|
|
|
|
|
|
|
(defun treesit-end-of-defun ()
|
|
|
|
"Tree-sitter `end-of-defun' function."
|
2022-10-23 18:47:02 -07:00
|
|
|
;; Why not simply get the largest node at point: when point is at
|
|
|
|
;; (point-min), that gives us the root node.
|
2022-10-29 14:11:52 -07:00
|
|
|
(let* ((node (treesit-node-at (point)))
|
|
|
|
(top (or (treesit-node-top-level
|
|
|
|
node
|
|
|
|
treesit-defun-type-regexp)
|
|
|
|
node)))
|
|
|
|
(goto-char (treesit-node-end top))))
|
2022-10-19 16:44:04 -07:00
|
|
|
|
|
|
|
;;; Imenu
|
|
|
|
|
|
|
|
(defvar-local treesit-imenu-function nil
|
|
|
|
"Tree-sitter version of `imenu-create-index-function'.
|
|
|
|
|
|
|
|
Set this variable to a function and `treesit-mode' will bind it
|
|
|
|
to `imenu-create-index-function'.")
|
|
|
|
|
|
|
|
;;; Activating tree-sitter
|
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
(defun treesit--setting-for-mode (mode settings)
|
|
|
|
"Get the setting for MODE in SETTINGS.
|
|
|
|
MODE is a major mode symbol. SETTINGS should be `treesit-settings'."
|
|
|
|
;; A setting for exactly this MODE. The shape is (FLAG INHERIT).
|
|
|
|
(let ((self (alist-get mode settings))
|
|
|
|
;; Fallback setting, shape is (FLAG INHERIT).
|
|
|
|
(fallback (alist-get t settings))
|
|
|
|
;; Settings for ancestor modes of MODE. Its shape is
|
|
|
|
;; ((MODE . FLAG)...)
|
|
|
|
(applicable (cl-loop for setting in settings
|
|
|
|
for m = (nth 0 setting)
|
|
|
|
for flag = (nth 1 setting)
|
|
|
|
for inherit = (nth 2 setting)
|
|
|
|
if (and (not (eq m t))
|
|
|
|
(not (eq m mode))
|
|
|
|
inherit
|
|
|
|
(provided-mode-derived-p mode m))
|
|
|
|
collect (cons m flag))))
|
|
|
|
(cond
|
|
|
|
(self (car self))
|
|
|
|
((null applicable) (car fallback))
|
|
|
|
(t
|
|
|
|
;; After sort, the most specific setting is at the top.
|
|
|
|
(setq applicable
|
|
|
|
(cl-sort applicable
|
|
|
|
(lambda (a b)
|
|
|
|
;; Major mode inheritance has a total ordering
|
|
|
|
;; right?
|
|
|
|
(provided-mode-derived-p (car a) (car b)))))
|
|
|
|
(cdar applicable)))))
|
|
|
|
|
|
|
|
(defun treesit-ready-p (mode language &optional quiet)
|
2022-11-05 10:49:46 +02:00
|
|
|
"Check whether tree-sitter is ready to be used for MODE and LANGUAGE.
|
|
|
|
|
|
|
|
LANGUAGE is the language symbol to check for availability.
|
|
|
|
It can also be a list of language symbols.
|
2022-10-25 13:54:12 -07:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
This function checks the user setting in `treesit-settings'. If the
|
|
|
|
user has set `demand' for MODE, and tree-sitter is not ready, emit a
|
|
|
|
warning and return nil. If the user has chosen to activate tree-sitter
|
|
|
|
for MODE and tree-sitter is ready, return non-nil. If QUIET is t, don't
|
|
|
|
emit warning in either case; if quiet is `message', display a message
|
2022-10-25 13:54:12 -07:00
|
|
|
instead of emitting warning.
|
|
|
|
|
|
|
|
If MODE is nil, don't check for user setting and assume the
|
2022-11-05 10:49:46 +02:00
|
|
|
setting is t."
|
2022-10-25 13:54:12 -07:00
|
|
|
(let ((language-list (if (consp language)
|
|
|
|
language
|
|
|
|
(list language)))
|
|
|
|
(activate (if mode
|
|
|
|
(treesit--setting-for-mode mode treesit-settings)
|
|
|
|
t))
|
|
|
|
msg)
|
2022-10-19 16:44:04 -07:00
|
|
|
;; Check for each condition and set MSG.
|
2022-10-25 13:54:12 -07:00
|
|
|
(if (null activate)
|
|
|
|
nil
|
|
|
|
(catch 'term
|
|
|
|
(when (not (treesit-available-p))
|
|
|
|
(setq msg "tree-sitter library is not compiled with Emacs")
|
|
|
|
(throw 'term nil))
|
|
|
|
(when (> (buffer-size) treesit-max-buffer-size)
|
|
|
|
(setq msg "buffer larger than `treesit-max-buffer-size'")
|
|
|
|
(throw 'term nil))
|
|
|
|
(dolist (lang language-list)
|
|
|
|
(pcase-let ((`(,available . ,err)
|
|
|
|
(treesit-language-available-p lang t)))
|
|
|
|
(when (not available)
|
|
|
|
(setq msg (format "language definition for %s is unavailable (%s): %s"
|
|
|
|
lang (nth 0 err)
|
|
|
|
(string-join
|
|
|
|
(mapcar (lambda (x) (format "%s" x))
|
|
|
|
(cdr err))
|
|
|
|
" ")))
|
|
|
|
(throw 'term nil)))))
|
|
|
|
;; Decide if all conditions met and whether emit a warning.
|
|
|
|
(if (not msg)
|
|
|
|
t
|
|
|
|
(when (eq activate 'demand)
|
|
|
|
(setq msg (concat "Cannot activate tree-sitter, because " msg))
|
|
|
|
(pcase quiet
|
|
|
|
('nil (display-warning 'treesit msg))
|
|
|
|
('message (message "%s" msg))))
|
|
|
|
nil))))
|
|
|
|
|
|
|
|
(defun treesit-major-mode-setup ()
|
2022-10-19 16:44:04 -07:00
|
|
|
"Activate tree-sitter to power major-mode features.
|
|
|
|
|
2022-10-25 13:54:12 -07:00
|
|
|
If `treesit-font-lock-settings' is non-nil, setup fontification and
|
|
|
|
enable `font-lock-mode'.
|
|
|
|
|
|
|
|
If `treesit-simple-indent-rules' is non-nil, setup indentation.
|
|
|
|
|
|
|
|
If `treesit-defun-type-regexp' is non-nil, setup
|
|
|
|
`beginning/end-of-defun' functions."
|
|
|
|
;; Font-lock.
|
|
|
|
(when treesit-font-lock-settings
|
|
|
|
;; `font-lock-mode' wouldn't setup properly if
|
|
|
|
;; `font-lock-defaults' is nil, see `font-lock-specified-p'.
|
2022-10-30 23:59:56 -07:00
|
|
|
(setq-local font-lock-defaults
|
|
|
|
'( nil nil nil nil
|
|
|
|
(font-lock-fontify-syntactically-function
|
|
|
|
. treesit-font-lock-fontify-region)))
|
2022-10-25 13:54:12 -07:00
|
|
|
(font-lock-mode 1)
|
|
|
|
(treesit-font-lock-recompute-features))
|
|
|
|
;; Indent.
|
|
|
|
(when treesit-simple-indent-rules
|
2022-10-28 17:54:43 -07:00
|
|
|
(setq-local indent-line-function #'treesit-indent)
|
|
|
|
(setq-local indent-region-function #'treesit-indent-region))
|
2022-10-25 13:54:12 -07:00
|
|
|
;; Navigation.
|
|
|
|
(when treesit-defun-type-regexp
|
|
|
|
(setq-local beginning-of-defun-function #'treesit-beginning-of-defun)
|
|
|
|
(setq-local end-of-defun-function #'treesit-end-of-defun)))
|
2022-10-19 16:44:04 -07:00
|
|
|
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
;;; Debugging
|
|
|
|
|
|
|
|
(defvar-local treesit--inspect-name nil
|
2022-10-27 08:02:58 +02:00
|
|
|
"Used by `treesit-inspect-mode' to show node name in mode-line.")
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
(defun treesit-inspect-node-at-point (&optional arg)
|
|
|
|
"Show information of the node at point.
|
|
|
|
If called interactively, show in echo area, otherwise set
|
|
|
|
`treesit--inspect-name' (which will appear in the mode-line
|
|
|
|
if `treesit-inspect-mode' is enabled). Uses the first parser
|
2022-10-27 08:02:58 +02:00
|
|
|
in `treesit-parser-list'."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(interactive "p")
|
|
|
|
;; NODE-LIST contains all the node that starts at point.
|
|
|
|
(let* ((node-list
|
|
|
|
(cl-loop for node = (treesit-node-at (point))
|
|
|
|
then (treesit-node-parent node)
|
|
|
|
while node
|
|
|
|
if (eq (treesit-node-start node)
|
|
|
|
(point))
|
|
|
|
collect node))
|
|
|
|
(largest-node (car (last node-list)))
|
|
|
|
(parent (treesit-node-parent largest-node))
|
|
|
|
;; node-list-acending contains all the node bottom-up, then
|
|
|
|
;; the parent.
|
|
|
|
(node-list-acending
|
|
|
|
(if (null largest-node)
|
|
|
|
;; If there are no nodes that start at point, just show
|
|
|
|
;; the node at point and its parent.
|
|
|
|
(list (treesit-node-at (point))
|
|
|
|
(treesit-node-parent
|
|
|
|
(treesit-node-at (point))))
|
|
|
|
(append node-list (list parent))))
|
|
|
|
(name ""))
|
|
|
|
;; We draw nodes like (parent field-name: (node)) recursively,
|
|
|
|
;; so it could be (node1 field-name: (node2 field-name: (node3))).
|
|
|
|
(dolist (node node-list-acending)
|
|
|
|
(setq
|
|
|
|
name
|
|
|
|
(concat
|
|
|
|
(if (treesit-node-field-name node)
|
|
|
|
(format " %s: " (treesit-node-field-name node))
|
|
|
|
" ")
|
|
|
|
(if (treesit-node-check node 'named) "(" "\"")
|
2022-11-04 10:50:55 -07:00
|
|
|
(propertize (or (treesit-node-type node) "N/A")
|
|
|
|
'face
|
|
|
|
(if (treesit-node-eq node largest-node)
|
|
|
|
'bold nil))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
name
|
|
|
|
(if (treesit-node-check node 'named) ")" "\""))))
|
|
|
|
(setq treesit--inspect-name name)
|
|
|
|
(force-mode-line-update)
|
|
|
|
(when arg
|
|
|
|
(if node-list
|
|
|
|
(message "%s" treesit--inspect-name)
|
|
|
|
(message "No node at point")))))
|
|
|
|
|
|
|
|
(define-minor-mode treesit-inspect-mode
|
2022-11-05 10:49:46 +02:00
|
|
|
"Minor mode that displays in the mode-line the node which starts at point.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
When this mode is enabled, the mode-line displays
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
PARENT FIELD-NAME: (NODE FIELD-NAME: (CHILD (...)))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 16:52:38 -07:00
|
|
|
where NODE, CHILD, etc, are nodes which begin at point. PARENT
|
|
|
|
is the parent of NODE. NODE is displayed in bold typeface.
|
|
|
|
FIELD-NAMEs are field names of NODE and CHILD, etc (see Info
|
|
|
|
node `(elisp)Language Definitions', heading \"Field names\").
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
|
|
|
If no node starts at point, i.e., point is in the middle of a
|
2022-11-05 10:49:46 +02:00
|
|
|
node, then the mode line displays the earliest node that spans point,
|
|
|
|
and its immediate parent.
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
|
2022-11-05 10:49:46 +02:00
|
|
|
This minor mode doesn't create parsers on its own. It uses the first
|
|
|
|
parser in `treesit-parser-list'."
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
:lighter nil
|
|
|
|
(if treesit-inspect-mode
|
|
|
|
(progn
|
|
|
|
(add-hook 'post-command-hook
|
|
|
|
#'treesit-inspect-node-at-point 0 t)
|
|
|
|
(add-to-list 'mode-line-misc-info
|
|
|
|
'(:eval treesit--inspect-name)))
|
|
|
|
(remove-hook 'post-command-hook
|
|
|
|
#'treesit-inspect-node-at-point t)
|
|
|
|
(setq mode-line-misc-info
|
|
|
|
(remove '(:eval treesit--inspect-name)
|
|
|
|
mode-line-misc-info))))
|
|
|
|
|
2022-06-14 14:30:39 -07:00
|
|
|
(defun treesit-query-validate (language query)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"Check if QUERY is valid for LANGUAGE.
|
2022-10-27 08:02:58 +02:00
|
|
|
If QUERY is invalid, display the query in a popup buffer, jump
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
to the offending pattern and highlight the pattern."
|
2022-06-14 14:30:39 -07:00
|
|
|
(cl-assert (or (consp query) (stringp query)))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(let ((buf (get-buffer-create "*tree-sitter check query*")))
|
|
|
|
(with-temp-buffer
|
2022-06-16 01:11:09 -07:00
|
|
|
(treesit-parser-create language)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(condition-case err
|
2022-09-30 17:20:34 -07:00
|
|
|
(progn (treesit-query-capture language query)
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(message "QUERY is valid"))
|
|
|
|
(treesit-query-error
|
|
|
|
(with-current-buffer buf
|
|
|
|
(let* ((data (cdr err))
|
|
|
|
(message (nth 0 data))
|
|
|
|
(start (nth 1 data)))
|
|
|
|
(erase-buffer)
|
2022-09-20 18:02:16 -07:00
|
|
|
(insert (treesit-query-expand query))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(goto-char start)
|
|
|
|
(search-forward " " nil t)
|
|
|
|
(put-text-property start (point) 'face 'error)
|
|
|
|
(message "%s" (buffer-substring start (point)))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(insert (format "%s: %d\n" message start))
|
|
|
|
(forward-char start)))
|
|
|
|
(pop-to-buffer buf))))))
|
|
|
|
|
|
|
|
;;; Etc
|
|
|
|
|
|
|
|
(declare-function find-library-name "find-func.el")
|
2022-10-10 20:20:19 +02:00
|
|
|
(defun treesit--check-manual-coverage ()
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
"Print tree-sitter functions missing from the manual in message buffer."
|
|
|
|
(interactive)
|
|
|
|
(require 'find-func)
|
|
|
|
(let ((functions-in-source
|
|
|
|
(with-temp-buffer
|
2022-10-10 20:20:19 +02:00
|
|
|
(insert-file-contents (find-library-name "treesit"))
|
Add tree-sitter intergration
* configure.ac (HAVE_TREE_SITTER, TREE_SITTER_OBJ): New variables.
(DYNAMIC_LIB_SUFFIX): new variable, I copied code from MODULES_SUFFIX
so the diff looks this way.
* doc/lispref/elisp.texi (Top): Add tree-sitter manual.
* doc/lispref/modes.texi (Font Lock Mode): mention tree-sitter.
(Parser-based Font Lock): New section.
(Auto-Indentation): Mention tree-sitter.
(Parser-based Indentation): New section.
* doc/lispref/parsing.texi (Parsing Program Source): New chapter.
* lisp/emacs-lisp/cl-preloaded.el (cl--typeof-types): Add
treesit-parser and treesit-node type.
* lisp/treesit.el: New file.
* src/Makefile.in (TREE_SITTER_LIBS, TREE_SITTER_FLAGS,
TREE_SITTER_OBJ): New variables.
* src/alloc.c:
(cleanup_vector): Add cleanup code for treesit-parser and
treesit-node.
* src/casefiddle.c (casify_region): Notify tree-sitter parser of
buffer change.
* src/data.c (Ftype_of): Add treesit-parser and treesit-node type
(Qtreesit_parser, Qtreesit_node): New symbol.
* src/emacs.c (main): Add symbols in treesit.c.
* src/eval.c (define_error): Move the function to here.
* src/insdel.c (insert_1_both, insert_from_string_1, insert_from_gap,
insert_from_buffer_1, replace_range, del_range_2): Notify tree-sitter
parser of buffer change.
* src/json.c (define_error): Move this function out.
* src/lisp.h (DEFINE_GDB_SYMBOL_BEGIN): Add treesit-parser and
treesit-node.
* src/lread.c (Vdynamic_library_suffixes): New variable.
* src/print.c (print_vectorlike): Add code for printing
treesit-parser and treesit-node.
* src/treesit.c: New file.
* src/treesit.h: New file.
* test/src/treesit-tests.el: New file.
2022-03-12 22:10:06 -08:00
|
|
|
(cl-remove-if
|
|
|
|
(lambda (name) (string-match "treesit--" name))
|
|
|
|
(cl-sort
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(cl-loop while (re-search-forward
|
|
|
|
"^(defun \\([^ ]+\\)" nil t)
|
|
|
|
collect (match-string-no-properties 1)))
|
|
|
|
#'string<))))
|
|
|
|
(functions-in-manual
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents (expand-file-name
|
|
|
|
"doc/lispref/parsing.texi"
|
|
|
|
source-directory))
|
|
|
|
(insert-file-contents (expand-file-name
|
|
|
|
"doc/lispref/modes.texi"
|
|
|
|
source-directory))
|
|
|
|
(cl-sort
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(cl-loop while (re-search-forward
|
|
|
|
"^@defun \\([^ ]+\\)" nil t)
|
|
|
|
collect (match-string-no-properties 1)))
|
|
|
|
#'string<))))
|
|
|
|
(message "Missing: %s"
|
|
|
|
(string-join
|
|
|
|
(cl-remove-if
|
|
|
|
(lambda (name) (member name functions-in-manual))
|
|
|
|
functions-in-source)
|
|
|
|
"\n"))))
|
|
|
|
|
|
|
|
(provide 'treesit)
|
|
|
|
|
|
|
|
;;; treesit.el ends here
|