1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-08 15:30:40 -08:00
Commit graph

566 commits

Author SHA1 Message Date
Yuan Fu
316bdc334c
Add manual for treesit-traverse-forward and friends
* doc/lispref/parsing.texi (Retrieving Node): Add manual entry for
treesit-traverse-depth-first, treesit-traverse-breadth-first,
treesit-traverse-forward.
* lisp/treesit.el (treesit-traverse-forward): Fix docstring.
2022-06-14 15:49:44 -07:00
Yuan Fu
a7288594f4
Change treesit-check-query and mention it in documentation
* doc/lispref/parsing.texi (Pattern Matching): Mention it.
* lisp/treesit.el (treesit-check-query): Rename to
treesit-query-validate.
* src/treesit.c (Ftreesit_query_capture, Ftreesit_query_compile):
Mention it.
2022-06-14 14:30:39 -07:00
Yuan Fu
e171ef933f
Support compiled queries in treesit-query-capture
Last commit added this new type, this commit adds functionalities.
treesit.el only has documentation changes.

* lisp/treesit.el (treesit-query-in, treesit-font-lock-settings,
treesit-defun-query): Update docstring.
* src/treesit.c (make_ts_query): New function.
(Ftreesit_query_compile): New function.
(Ftreesit_query_capture): Remove code that creates a query object and
instead either use make_ts_query or use the give compiled query.  Free
the query object conditonally.
(syms_of_treesit): New symbol.
2022-06-14 11:50:24 -07:00
Yuan Fu
8aa04aac65
; * lisp/treesit.el (treesit-defun-query): Improve docstring. 2022-06-13 14:20:40 -07:00
Yuan Fu
b3de8850e0
Use the up-only parameter in treesit navigation functions
* lisp/treesit.el(treesit-inspect-node-at-point,
treesit-end-of-defun): Set up-only to t.
2022-06-13 14:20:40 -07:00
Yuan Fu
c62473c31a
Add depth control for treesit traverse functions
* lisp/treesit.el (treesit-traverse-depth-first,
treesit-traverse-forward): Add depth parameter.
(treesit-search-forward, treesit-search-beginning,
treesit-search-end): Add up-only parameter.
2022-06-13 14:20:40 -07:00
Yuan Fu
a73f2b9990
Fix treesit-search-forward
Move the check for movement

    (if (> arg 0)
        ;; Make sure we moved forward.
        (> (funcall pos-fn node) starting-point)
      ;; Make sure we moved backward.
      (< (funcall pos-fn node) starting-point))

into cl-loop:

    if (treesit-node-eq cap-node node)

becomes

    if (and (treesit-node-eq cap-node node)
            (if (> arg 0)
                ;; Make sure we moved forward.
                (> (funcall pos-fn node)
                   starting-point)
              ;; Make sure we moved backward.
              (< (funcall pos-fn node)
                 starting-point)))

* lisp/treesit.el (treesit-search-forward): Move the check.
2022-06-13 14:20:25 -07:00
Yuan Fu
1dd8ddee12
Rename treesit-traverse-forward-depth-first
* lisp/treesit.el (treesit-traverse-forward): Rename to
'treesit-traverse-forward'.
(treesit-traverse-forward, treesit-search-forward): Use
the new name.
2022-06-11 20:24:38 -07:00
Theodor Thornhill
35e2786c93
Fix typo and argument in treesit-beginning-of-defun, etc
* lisp/treesit.el (treesit-beginning-of-defun, treesit-end-of-defun):
Fix typo, add shield for argument.
2022-05-19 19:06:12 -07:00
Yuan Fu
74f8572f6c
; * lisp/treesit.el (treesit-node-at): Fix typo. 2022-05-14 08:57:23 -07:00
Yuan Fu
b2b57eda04
Extract out treesit-search-forward
* lisp/treesit.el (treesit-search-forward, treesit-search-beginning,
treesit-search-end): New functions.
(treesit-traverse-defun): Remove function.
(treesit-beginning-of-defun, treesit-end-of-defun): Replace
'treesit-traverse-defun' with 'treesit-search-forward' and fiends.
* test/src/treesit-tests.el: Add reminder for tests.
2022-05-13 16:41:50 -07:00
Yuan Fu
750090fd07
* lisp/treesit.el (treesit-node-at): Add check for nil node. 2022-05-13 16:34:26 -07:00
Yuan Fu
d8c9b9c0fb
Add defun navigation
* lisp/treesit.el (treesit-defun-query): New variable.
(treesit-traverse-defun, treesit-beginning-of-defun,
treesit-end-of-defun): New functions.
* test/src/treesit-tests.el: Add reminders for tests.
2022-05-13 14:37:24 -07:00
Yuan Fu
d94c7076df
New node traversal functions
* lisp/treesit.el (treesit-traverse-parent): New alias.
(treesit-traverse-depth-first, treesit--traverse-breadth-first-1,
treesit-traverse-breadth-first, treesit-next-sibling-or-up,
treesit-traverse-forward-depth-first): New functions.
* test/src/treesit-tests.el (treesit-node-supplemental): Add reminders
for tests.
2022-05-13 14:37:24 -07:00
Yuan Fu
78df03329d
Redefine treesit-node-at
The old 'treesit-node-at' becomes 'treesit-node-on'.  The new
'treesit-node-at' has slightly different semantics.  Now
'treesit-node-on' gets the smallest node covering a range and
'treesit-node-at' gets the smallest node after a position.

The reason of change can be found in the docstring of
'treesit-node-on' (the BEWARE part): its result can be sometimes
surprising/unexpected.

* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* lisp/treesit.el (treesit-node-at): Change to new definition.
(treesit-node-on): Inherits the old definition of
'treesit-node-at'.  Parameter END is now mandatory.
(treesit-language-at, treesit-node-field-name): Use the new '-on'
function.
(treesit-font-lock-fontify-region, treesit-simple-indent-presets,
treesit-indent): Use the new '-at' function.
* test/src/treesit-tests.el (treesit-node-supplemental): Update tests.
2022-05-13 14:36:37 -07:00
Yuan Fu
84847cad82
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-05-07 01:11:39 -07:00