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

113 commits

Author SHA1 Message Date
Yuan Fu
f17ca55a0a
Remove treesit-settings
Remove it since we are using separate major modes for tree-sitter and
native variant now.

* doc/lispref/parsing.texi (Tree-sitter major modes): Update manual.
* lisp/treesit.el (treesit-settings): Remove option.
(treesit--setting-for-mode): Remove function.
(treesit-ready-p): Don't check for user preference in treesit-settings.
2022-11-19 18:54:39 -08:00
Yuan Fu
ac9bc819bc
Fix tree-sitter comment indentation for C-like languages
The goal is to indent like this:

/* comment
   comment  --> This line aligns with the beginning of the first line
 */         --> This line aligns with the opening comment token

* lisp/treesit.el (treesit-comment-start)
(treesit-comment-end): New variables.
(treesit-simple-indent-presets): New preset comment-end,
comment-start, comment-start-skip

* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles)
(c-ts-mode)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--indent-rules)
(java-ts-mode)
* lisp/progmodes/js.el (js--treesit-indent-rules)
(js-ts-mode)
* lisp/progmodes/ts-mode.el (ts-mode--indent-rules)
(ts-mode): Add identical indent rules to each mode, and set identical
treesit-comment-start/end's.

* doc/lispref/modes.texi (Parser-based Indentation)
* doc/lispref/parsing.texi (Tree-sitter major modes): Update manual.
2022-11-19 18:36:08 -08:00
Eli Zaretskii
62e37ecc40 Fix documentation of recent treesit changes
* src/treesit.c (Ftreesit_parser_notifiers)
(Ftreesit_parser_add_notifier, Ftreesit_parser_remove_notifier):
Doc string fixes.

* doc/lispref/parsing.texi (Accessing Node Information): Fix
wording and punctuation.
(Using Parser): Improve indexing and wording.
2022-11-17 15:03:40 +02:00
Yuan Fu
639821d49a
Allow checking for outdated nodes in tree-sitter
Now you can run (treesit-node-check node 'outdated).

* doc/lispref/parsing.texi (Accessing Node Information): Update
manual.
* src/treesit.c (Ftreesit_node_check): Add new property 'outdated'.
* test/src/treesit-tests.el (treesit-node-check): Add tests.
2022-11-16 14:40:41 -08:00
Yuan Fu
75b65b3f67
; Add documentation for tree-sitter parser after-change notifiers
* doc/lispref/parsing.texi (Using Parser): Update manual.
* lisp/treesit.el (treesit): Add shordocs.
* src/treesit.c: Augment docstrings.
2022-11-16 14:40:40 -08:00
Yuan Fu
306e49285a
Add treesit-explore-mode
This mode is basically the tree-sitter playground[1] in Emacs:
displays the syntax tree with the source side-by-side, kept in sync in
real-time.

[1] https://tree-sitter.github.io/tree-sitter/playground

* doc/lispref/parsing.texi (Language Definitions): Mention in manual.
* lisp/treesit.el (treesit--explorer-buffer)
(treesit--explorer-source-buffer)
(treesit--explorer-language)
(treesit--explorer-refresh-timer)
(treesit--explorer-highlight-overlay)
(treesit--explorer-last-node): New variables.
* lisp/treesit.el (treesit--explorer--nodes-to-highlight)
(treesit--explorer-refresh)
(treesit--explorer-post-command)
(treesit--explorer-jump)
(treesit--explorer-highlight-node)
(treesit--explorer-draw-node): New functions.
(treesit--explorer-tree-mode)
(treesit-explore-mode): New modes.
2022-11-16 14:40:37 -08:00
Yuan Fu
3a0c94ac0b
Remove feature that checks whether tree-sitter node "has changes"
First of all, we signal error on using an outdated node, so if a node
has changes, calling treesit-node-check would only raise an error.
Besides, in order to properly answer whether a node has changed, we
would have to update the node as the buffer is edited, which we don't
do right now.

* doc/lispref/parsing.texi (Accessing Node Information): Remove
relevant manual text.
* src/treesit.c (Ftreesit_node_check): Remove docstring mentions,
remove the branch for "has-changes".
(syms_of_treesit): Remove has-changes.
2022-11-14 00:51:54 -08:00
Eli Zaretskii
faf44e2c61 Fix recent changes in documentation
* lisp/treesit.el (treesit-node-at): Doc fix.

* doc/lispref/parsing.texi (Language Definitions): Add
cross-reference.
(Retrieving Nodes): Renamed from "Retrieving Node"; all references
changed.
(Retrieving Nodes): Fix wording and markup.
2022-11-12 10:57:56 +02:00
Yuan Fu
5cd3db73be
Improve treesit-node-at
* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* lisp/treesit.el (treesit-node-at): Change semantic.  It tries to
return the node that a user would expect in various circumstances.
* test/src/treesit-tests.el (treesit-node-at): New test.
2022-11-11 20:04:38 -08:00
Yuan Fu
838fc77254
Make tree-sitter node type match case-sensitive
* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* src/treesit.c (treesit_traverse_match_predicate): Change to
fast_c_string_match.
(Ftreesit_search_subtree)
(Ftreesit_search_forward)
(Ftreesit_induce_sparse_tree): Update docstring.
2022-11-09 15:51:13 -08:00
Eli Zaretskii
5858921f40 ; Minor improvements in wording of tree-sitter docs
* doc/lispref/parsing.texi (Multiple Languages):
* doc/lispref/modes.texi (Parser-based Font Lock): Improve
wording.
2022-11-09 15:35:51 +02:00
Yuan Fu
29418f954e
; Improve tree-sitter documentation
* doc/lispref/modes.texi (Parser-based Font Lock)
* doc/lispref/parsing.texi (Multiple Languages)
* lisp/treesit.el (treesit-range-rules)
(treesit-font-lock-rules): Improve phrasing around queries and keyword
and values.
2022-11-08 10:39:53 -08:00
Yuan Fu
1ae314dfda
; Documentation fixes for tree-sitter
* doc/lispref/parsing.texi (Multiple Languages): Resolve the FIXME.
2022-11-07 01:27:49 -08:00
Eli Zaretskii
488a6efe32 ; More documentation improvements for treesit
* lisp/treesit.el (treesit-language-at, treesit-range-rules)
(treesit-font-lock-rules): Doc fixes.

* doc/lispref/parsing.texi (Multiple Languages):
* doc/lispref/modes.texi (Parser-based Font Lock): Fix wording.
2022-11-06 11:59:27 +02:00
Yuan Fu
5fbb7a126d
; Fix documentation for tree-sitter
* doc/lispref/modes.texi (Parser-based Font Lock): Fix the signature
style.
* doc/lispref/parsing.texi (Language Definitions): Rephrase the
section, remove documentation for deleted functions, fix signature
style.
* lisp/treesit.el (treesit-range-rules)
(treesit-font-lock-rules): Change ARGS to QUERY-SPECS, fix docstring.
* lisp/treesit.el (treesit-inspect-mode): Fix docstring.
2022-11-05 17:41:06 -07:00
Eli Zaretskii
d4e8c90b66 ; Minor fixes to documentation
* lisp/treesit.el (treesit-ready-p, treesit-inspect-mode)
(treesit-range-settings, treesit-range-rules)
(treesit--merge-ranges, treesit-update-ranges)
(treesit-font-lock-rules, treesit-font-lock-feature-list)
(treesit-font-lock-contextual-post-process)
(treesit-font-lock-recompute-features): Doc fixes.
* lisp/progmodes/js.el (js--fontify-template-string): Doc fix.

* doc/lispref/modes.texi (Parser-based Indentation):
* doc/lispref/positions.texi (List Motion):
* doc/lispref/parsing.texi (Tree-sitter major modes):
* doc/lispref/parsing.texi (Multiple Languages): Fix wording and
markup.
2022-11-05 10:49:46 +02:00
Eli Zaretskii
243ee7b244 ; Fix minor issues with Tree-sitter documentation in ELisp manual
* doc/lispref/parsing.texi (Multiple Languages): Add @end example.

* doc/lispref/Makefile.in (srcs): Add $(srcdir)/parsing.texi.
2022-11-05 09:14:25 +02:00
Yuan Fu
d9d66764e2
Revise tree-sitter facility for multi-language buffers
* doc/lispref/parsing.texi (Multiple Languages): Extend and update
manual.
* lisp/treesit.el (treesit-range-functions): Remove variable.
(treesit-range-settings): New variable.
(treesit-range-rules): New function.
(treesit--merge-ranges): New function.
(treesit-update-ranges): Use treesit-range-settings instead of
treesit-range-functions.
(treesit-font-lock-rules): Fix docstring.
(treesit-indent)
(treesit-indent-region): Only update ranges in a region.
* test/src/treesit-tests.el (treesit-range): New test.
2022-11-04 09:39:57 -07:00
Yuan Fu
ccd2509ed3
Don't print buffer when printing tree-sitter node and parser
Additionally, print node's position in buffer.

* doc/lispref/parsing.texi (Retrieving Node): Reflect this change in
manual.
* src/print.c (print_vectorlike): Remove printing of buffer, add
printing of node position.
2022-11-01 12:54:56 -07:00
Yuan Fu
4ef50ccd3f
; Explain the BEG and END argument in treesit-query-capture better
* doc/lispref/parsing.texi (Pattern Matching): Update manual.
* src/treesit.c (Ftreesit_query_capture): Update docstring.
2022-10-31 15:35:52 -07:00
Yuan Fu
da87895df2
Add treesit-node-top-level
Merge treesit-node-top-level-p and treesit--find-top-level-match into
treesit-node-top-level.

* doc/lispref/parsing.texi (Retrieving Node): Add manual entry for it.
* lisp/progmodes/js.el (js--treesit-imenu-1): Replace
treesit-node-top-level-p with treesit-node-top-level.
* lisp/treesit.el (treesit-node-top-level-p)
(treesit--find-top-level-match): Remove functions.
(treesit-node-top-level): New function.
* lisp/treesit.el (treesit-beginning-of-defun)
(treesit-end-of-defun): Replace treesit--find-top-level-match with
treesit-node-top-level.
2022-10-29 14:47:05 -07:00
Yuan Fu
baacad1771
Reflect recent change in tree-sitter manual sections
* doc/lispref/modes.texi (Parser-based Font Lock):
treesit-font-lock-enable is replaced by treesit-major-mode-setup.
* doc/lispref/modes.texi (Parser-based Indentation): Mention
treesit-major-mode-setup,
* doc/lispref/parsing.texi (Tree-sitter major modes): Remove
treesit-mode and global-treesit-mode, explain setup guideline.
2022-10-29 14:47:01 -07:00
Stefan Kangas
e7b09065da Minor copy-edits in tree-sitter docs
* doc/lispref/parsing.texi (Parsing Program Source): Improve wording.
2022-10-27 14:05:00 +02:00
Stefan Kangas
77e6a704ac ; Fix typos and formatting in tree-sitter docs
* doc/lispref/parsing.texi (Parsing Program Source): Fix typos and
formatting.
2022-10-27 14:03:52 +02:00
Stefan Kangas
092776c7eb ; Update copyright years
* doc/lispref/parsing.texi:
* src/treesit.h:
* test/src/treesit-tests.el: Update copyright years.
2022-10-27 12:15:32 +02:00
Yuan Fu
e5043db2f1
Fix treesit-language-at
* lisp/treesit.el (treesit-language-at-point-function): New local
variable.
(treesit-language-at): Change to use
treesit-language-at-point-function rather than trying each parser
one-by-one.
* doc/lispref/parsing.texi (Multiple Languages): Update manual.
2022-10-25 14:26:41 -07:00
Yuan Fu
6cf2a9c55d
Make treesit-search-forward-goto accept a NODE argument
With NODE argument we can do

(setq node (treesit-search-forward-goto node))

And we can choose what node to pass to it (maybe we want to pass it
the largest node at point, rather than the smallest node, and in case
of multiple parsers, we can choose which parser to use).

* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* lisp/treesit.el (treesit-search-forward-goto): Accept a NODE
argument.
2022-10-23 18:29:02 -07:00
Yuan Fu
524d10c86b
Make treesit-node-at return the last leaf node at EOB
* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* lisp/treesit.el (treesit-node-at): Add a (when node) form just to be
explicit, return the last leaf node if there is no node after POS.
2022-10-23 18:23:17 -07:00
Yuan Fu
591759d508
Make treesit-node-child and fiends accept negative index
* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* src/treesit.c (Ftreesit_node_child)
(Ftreesit_node_field_name_for_child): Accept and process negative
index.
2022-10-23 18:05:10 -07:00
Yuan Fu
fa9bede36c
Change function signiture of treesit search functions
Justification: We want to make the SIDE argument in
treesit-search-forward-goto optional, so I changed it to START.
It makes more sense for BACKWARD to follow START so two common
case, search for end forward and beginning backwards are

(treesit-search-forward-goto node pred)
(treesit-search-forward-goto node pred t t)

Then since we swapped BACKWARD and ALL for
treesit-search-forward-goto, it's best to swap them for
treesit-search-forward and treesit-search-subtree, too.  And BACKWARD
will probably be used more frequently than ALL anyway.

* doc/lispref/parsing.texi (Retrieving Node): Resolve FIXME and update
function signitures.
* lisp/treesit.el (treesit-search-forward-goto): Change SIDE to
START, swap BACKWARD and ALL.
(treesit-beginning-of-defun)
(treesit-end-of-defun): Update use of treesit-search-forward-goto
* src/treesit.c (Ftreesit_search_subtree)
(Ftreesit_search_forward): Swap BACKWARD and ALL.
2022-10-23 15:19:00 -07:00
Yuan Fu
6a2399c55e
; Resolve FIXME's in tree-sitter manual sections
* doc/lispref/modes.texi (Parser-based Indentation):
* doc/lispref/parsing.texi (Retrieving Node): Resolve FIXME's.
* src/treesit.c: Update tree graph in docstring.
2022-10-23 14:30:14 -07:00
Eli Zaretskii
31f7543099 ; Minor copyedits of tree-sitter stuff in ELisp manual
* doc/lispref/parsing.texi (Pattern Matching):
* doc/lispref/modes.texi (Parser-based Font Lock)
(Parser-based Indentation): Fix wording and typos.
2022-10-23 11:14:18 +03:00
Yuan Fu
57b904f4ba
Fix infinite loop in treesit-search-forward-goto
* lisp/treesit.el (treesit-search-forward-goto): Remove UP argument.
* src/treesit.c (treesit_traverse_child_helper): New function.
(treesit_search_forward): Remove UP_ONLY and SKIP_START argument.
Don't traverse subtree of START.  And after we've found the next
sibling/parent, go down to the first leaf node.  Also change recursion
to loop.
(Ftreesit_search_forward): Change docstring, remove UP argument.
2022-10-22 22:50:56 -07:00
Yuan Fu
773cce640f
Resolve FIXME's in tree-sitter manual sections
Pattern vs query: a query consists of many patterns.  I tightened up
the use of pattern vs query in the manual, now there shouldn't be
ambiguities.

* doc/lispref/modes.texi (Parser-based Font Lock):
* doc/lispref/parsing.texi (Language Definitions): Resolve FIXME's.
2022-10-22 18:50:08 -07:00
Eli Zaretskii
6f28810f6b Clean up tree-sitter sections of the ELisp manual
* doc/lispref/parsing.texi (Parsing Program Source):
* doc/lispref/modes.texi (Font Lock Mode)
(Parser-based Font Lock): Fix wording, punctuation, and markup.
Add index entries.

* lisp/treesit.el (treesit-node-at, treesit-language-at): Rename
argument POINT to POS.
2022-10-22 18:48:42 +03:00
Yuan Fu
4c328daf01
Add a new section to tree-sitter's manual node
* doc/lispref/parsing.texi (Parsing Program Source): New section
Tree-sitter major modes.
2022-10-18 14:24:22 -07:00
Yuan Fu
bb8a46e559
Update tree-sitter manual to reflect the previous commit
* doc/lispref/modes.texi: Update manual to reflect previous change:
remove :toggle and :level, add :feature.  Document new variables and
functions.
* doc/lispref/parsing.texi: Add the missing closing bracket in
@code{(t . nil)}.
2022-10-13 15:09:51 -07:00
Yuan Fu
f0e9085a17
* doc/lispref/parsing.texi: Add manual for treesit-query-language. 2022-10-13 14:40:38 -07:00
Yuan Fu
0b3f785c4a
Better signal data for treesit-load-language-error
* src/treesit.c (ts_load_language): Better formatted signal data,
(Ftreesit_langauge_available_p): Optionally return the signal data if
language not available.
* doc/lispref/parsing.texi: Document the signal data in detail.
2022-10-12 10:38:35 -07:00
Yuan Fu
9f7c359f40
Add note on tree-sitter's naming convention
* admin/notes/tree-sitter/starter-guide: Add note.
* doc/lispref/parsing.texi: Add note.
2022-10-09 17:20:26 -07:00
Yuan Fu
7a4380b905
; * doc/lispref/parsing.texi (Language Definitions): Fix typo. 2022-10-04 13:30:56 -07:00
Yuan Fu
96d44c4321
Add treesit-language-version
* doc/lispref/parsing.texi (Language Definitions): Update manual.
* src/treesit.c (Ftreesit_language_version): New function
2022-10-04 13:30:56 -07:00
Yuan Fu
10f96a8c57
Improve documentation of tree-sitter search functions
* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* src/treesit.c (treesit-search-subtree)
(treesit-search-forwardn)
(treesit-induce-sparse-tree): Mention case-insensitivity.
* lisp/treesit.el (treesit-simple-indent): Mention case-insensitivity.
2022-10-04 13:30:56 -07:00
Yuan Fu
6a3caeab58
Remove treesit-query-in
Because treesit-query-capture can now do everything it does.

* doc/lispref/parsing.texi (Pattern Matching): Update manual.
* lisp/treesit.el (treesit-query-in): Remove function.
* src/treesit.c (Ftreesit_query_capture): Accept parser and language
symbol as NODE.
2022-10-04 13:30:52 -07:00
Yuan Fu
6e60d46418
Fix tree-sitter manuals
* doc/lispref/modes.texi: Fix typos, reword, etc.
* doc/lispref/parsing.texi: Fix typos, reword, etc.
2022-09-30 16:51:21 -07:00
Yuan Fu
ef6e18a6b9
Improve treesit-search-forward-goto
* doc/lispref/parsing.texi (Retrieving Node): Update manual.
* lisp/treesit.el (treesit-search-forward-goto): Instead of taking a
node, use the node at point, and make sure we make progress.
2022-09-24 21:11:31 -07:00
Yuan Fu
eba6582436
Add the treesit-search functions that supplant the removed ones
The signatures also changed.

treesit-traverse-depth-first   -> treesit-search-subtree
treesit-traverse-breadth-first ->
treesit-traverse-forward       -> treesit-search-forward
treesit-search-forward         -> treesit-search-forward-goto
treesit-search-beginning/end   -> treesit-search-forward-goto
                               -> treesit-induce-sparse-tree

* doc/lispref/parsing.texi (Retrieving Node): Add relevant manual
sections.
* lisp/treesit.el (treesit-search-forward-goto): New function.
* src/treesit.c (ts_traverse_sibling_helper)
(ts_traverse_match_predicate)
(ts_search_dfs)
(ts_search_forward)
(treesit-search-subtree)
(treesit-search-forward)
(ts_build_sparse_tree)
(Ftreesit_induce_sparse_tree): Add functions.
* test/src/treesit-tests.el (treesit-node-supplemental): Add comments.
2022-09-24 21:11:30 -07:00
Yuan Fu
c957832cbf
Remove treesit-traverse functions
Remove before adding the replacements.

* doc/lispref/parsing.texi (Retrieving Node): Remove relevant sections.
* lisp/treesit.el (treesit-traverse-depth-first)
(treesit--traverse-breadth-first-1)
(treesit-traverse-breadth-first)
(treesit-next-sibling-or-up)
(treesit-traverse-forward)
(treesit-search-forward)
(treesit-search-beginning):
(treesit-search-end): Remove functions.
(treesit-defun-query): Remove variable.
(treesit-beginning-of-defun)
(treesit-end-of-defun): Remove functions.
* test/src/treesit-tests.el: Remove comments.
2022-09-24 21:11:30 -07:00
Yuan Fu
914f68da05
; Minor tree-sitter manual fix
* doc/lispref/parsing.texi (Retrieving Node): Remove the quote.
2022-09-24 21:11:29 -07:00
Yuan Fu
1d3234988a
Add node-only parameter to treesit-query-capture
* doc/lispref/parsing.texi (Pattern Matching): Mention the new
parameter.
* lisp/treesit.el (treesit-query-in): Add node-only.
* src/treesit.c (Ftreesit_query_capture): Add node-only.
2022-09-08 12:52:25 -07:00