Yuan Fu
4489450f37
In end-of-defun, terminate early if no further defun exists
...
Before this change, end-of-defun calls end-of-defun-function even if
point is not necessarily at the beginning of a defun (contrary to what
end-of-defun-function's docstring claims). Now it terminates early
and doesn't call end-of-defun-function.
* lisp/emacs-lisp/lisp.el (beginning-of-defun-raw): Update docstring
clarifying the return value.
(end-of-defun): Terminate early if beginning-of-defun-raw returns nil.
2022-11-10 15:00:29 -08:00
Yuan Fu
98ed6db34f
; Fix docstring graph alignment in Ftreesit_search_forward
...
* src/treesit.c (Ftreesit_search_forward): Replace tabs with spaces.
2022-11-10 14:16:25 -08:00
Yuan Fu
2ec403f777
Utilize new face font-lock-escape-face in python-mode
...
* lisp/progmodes/python.el (python--treesit-settings): Use
font-lock-escape-face rather than font-lock-constant-face.
2022-11-10 10:34:57 -08:00
Yuan Fu
c5e3b99467
Accept older versions of tree-sitter library
...
* configure.ac: Accept a tree-sitter library as long as it provides
ts_set_allocator.
2022-11-10 10:25:29 -08:00
Robert Pluim
ab4edbf60e
; * lisp/font-lock.el (font-lock-bracket-face): Improve docstring
2022-11-10 12:46:03 +01:00
Robert Pluim
a5a047a07f
; * lisp/treesit.el (treesit-font-lock-rules): Improve docstring
2022-11-10 12:45:14 +01:00
Eli Zaretskii
f5084ed197
; * etc/NEWS: Fix last change.
2022-11-10 13:04:42 +02:00
Randy Taylor
e06953b02a
Add more font-lock faces (Bug#58940)
...
* lisp/font-lock.el (font-lock-bracket-face, font-lock-delimiter-face,
font-lock-escape-face, font-lock-number-face,
font-lock-misc-punctuation-face, font-lock-operator-face,
font-lock-property-face, font-lock-punctuation-face): Define new
faces.
* lisp/cus-theme.el (custom-theme--listed-faces): Add them to the
list.
* doc/lispref/modes.texi (Faces for Font Lock): Document them.
* etc/NEWS: Mention them.
2022-11-10 13:03:41 +02:00
Yuan Fu
77cb95c851
; Revert back to requiring tree-sitter v0.0 for now
2022-11-10 00:31:10 -08:00
Yuan Fu
eecc2d45b9
; Update tree-sitter HTML manuals in admin/notes
...
* admin/notes/tree-sitter/html-manual/Language-Definitions.html
* admin/notes/tree-sitter/html-manual/Multiple-Languages.html
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Indentation.html
* admin/notes/tree-sitter/html-manual/Retrieving-Node.html: Update.
2022-11-09 15:51:13 -08:00
Yuan Fu
663d768d44
* configure.ac: Change required tree-sitter version to 0.20.2.
2022-11-09 15:51:13 -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
Yuan Fu
a7042fa051
New function fast_c_string_match and fast_c_string_match_internal
...
Generalize fast_c_string_match_ignore_case into
fast_c_string_match_internal. And Make fast_c_string and
fast_c_string_match_ignore_case use fast_c_string_match_internal.
* src/lisp.h (fast_c_string_match_internal)
(fast_c_string_match): New declaration.
(fast_c_string_match_ignore_case): Change to thin wrapper.
* src/search.c (fast_c_string_match_internal): New function.
2022-11-09 15:51:13 -08:00
Yuan Fu
2332c3eb55
Add tree-sitter shortdoc
...
* lisp/treesit.el (treesit--generate-shortdoc-examples): New function.
(treesit): New shortdoc group.
2022-11-09 15:51:13 -08:00
Yuan Fu
077c664052
; Fix treesit-query-range docstring
...
* lisp/treesit.el (treesit-query-range): Change signature, change
reference of treesit-query-in to that of treesit-query-capture.
2022-11-09 15:51:12 -08:00
Yuan Fu
2b4d46f99b
Mimic existing python-mode beg/end-of-defun behavior better
...
* lisp/progmodes/python.el (python-treesit-beginning-of-defun)
(python-treesit-end-of-defun): New functions.
* lisp/progmodes/python.el (python-mode): Use custom beg/end-of-defun
functions.
2022-11-09 15:51:12 -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
07292b1344
; Improve docstring of treesit-simple-indent-presets
...
* lisp/treesit.el (treesit-simple-indent-presets): Improve docstring.
2022-11-07 02:27:59 -08:00
Yuan Fu
1bed1f0b8e
Add tree-sitter indent preset "point-min"
...
* doc/lispref/modes.texi (Parser-based Indentation): Update manual.
* lisp/treesit.el (treesit-simple-indent-presets): Add preset. Update
docstring.
2022-11-07 02:00:04 -08:00
Yuan Fu
98f5b74808
Add treesit--indent-rules-optimize
...
* lisp/treesit.el (treesit--indent-rules-optimize): New function.
(treesit-major-mode-setup): Optimize indent rules when setting up for
major mode.
2022-11-07 01:59:21 -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
9fbbb23552
Fix incorrect tree-sitter fontification
...
* lisp/treesit.el (treesit-font-lock-fontify-region): If the captured
node is outside of the region between START and END, don't fontify it.
Wrap fontification code in a when form.
2022-11-05 19:00:17 -07:00
Yuan Fu
076a258101
Allow tree-sitter indent offset to be a variable
...
* doc/lispref/modes.texi (Parser-based Indentation): Update manual.
* lisp/progmodes/js.el (js--treesit-indent-rules): Change all
occurance of ,js-indent-level to js-indent-level.
* lisp/progmodes/ts-mode.el (ts-mode--indent-rules): Change all
occurance of ,ts-mode-indent-offset to ts-mode-indent-offset.
* lisp/treesit.el (treesit-simple-indent-rules): Change docstring.
(treesit-simple-indent): Allow offset to be a variable.
2022-11-05 18:32:01 -07:00
Yuan Fu
f847ecc40b
Don't indent empty lines in treesit-indent-region
...
* lisp/treesit.el (treesit-indent-region): Wrap the old code in an if
form that checks whether we are at an empty line. Add comments.
2022-11-05 17:56:24 -07:00
Yuan Fu
b471f7f614
Make treesit-language-at work in more situations
...
; * lisp/treesit.el (treesit-language-at): Return sometime sensible
even if treesit-language-at-point-function is nil.
2022-11-05 17:41:10 -07: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
951dd2a4d9
; * lisp/treesit.el (treesit-inspect-node-at-point): Minor fix.
2022-11-04 10:50:55 -07:00
Yuan Fu
c924b6afb6
; * lisp/treesit.el (treesit-ready-p): Fix typo.
2022-11-04 10:16:33 -07:00
Yuan Fu
ce9e720413
; Minor improvement in treesit-inspect-mode
...
* lisp/treesit.el (treesit-inspect-node-at-point): Show the current
node in bold.
(treesit-inspect-mode): Update docstring.
2022-11-04 10:15:42 -07:00
Yuan Fu
e0e3299c01
; * lisp/treesit.el (treesit-update-ranges): Update all parsers.
2022-11-04 10:03:17 -07:00
Yuan Fu
784f53a215
; Replace error with signal in treesit.el
...
(or (treesit-parser-create language)
(error "Cannot find a parser for %s" language))
is turned into
(treesit-parser-create language)
because treesit-parser-create never returns nil. (We used to use
treesit-get-parser which don't create parser automatically.)
* lisp/treesit.el (treesit-buffer-root-node): Replace error with signal.
2022-11-04 10:01:51 -07:00
Yuan Fu
673a55780d
; Remove unused tree-sitter functions
...
They didn't turn out to be very useful.
* lisp/treesit.el (treesit-set-ranges)
(treesit-get-ranges): Remove functions.
2022-11-04 09:57:32 -07:00
Yuan Fu
8ad4c4009e
Add treesit-indent-error
...
* lisp/treesit.el (treesit-indent-error): New error.
(treesit--simple-indent-eval): Signal treesit-indent-error.
2022-11-04 09:57:11 -07: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
f6dc55f516
; * lisp/progmodes/js.el (js--fontify-template-string): Fix typo.
2022-11-04 01:18:59 -07:00
Yuan Fu
b86deb617b
Fix treesit-parser-set-included-ranges
...
Track whether a parser has ranges set ourselves. See comment in
Ftreesit_parser_included_ranges for detail.
* src/treesit.c (make_treesit_parser): Initialize has_range.
(Ftreesit_parser_set_included_ranges): Set has_range. Fill docstring.
(Ftreesit_parser_included_ranges): Check has_range.
* src/treesit.h (Lisp_TS_Parser): Add has_range.
2022-11-03 22:14:50 -07:00
Yuan Fu
c5f24f76eb
; * src/treesit.c: Minor comment change.
2022-11-03 19:39:43 -07:00
Yuan Fu
b028d4f7df
; Tree-sitter: Don't refontify if entity contained in the region
...
* lisp/treesit.el (treesit-font-lock-contextual-post-process): Only
refontify when NODE-START < region START.
2022-11-03 19:37:55 -07:00
Yuan Fu
e3663d0e9c
Add contextual tree-sitter font-lock to ts-mode and js-mode
...
* lisp/progmodes/js.el (js--treesit-font-lock-settings)
* lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): Capture
commend and strings. Add empty lines.
2022-11-03 11:53:49 -07:00
Yuan Fu
f9f9b43df5
Minor change to tree-sitter imenu function of js-mode
...
If someone don’t like the labels, they can set them to empty strings.
* lisp/progmodes/js.el (js--treesit-imenu-type-alist): Add space.
(js--treesit-imenu-label): Remove space.
2022-11-03 11:44:35 -07:00
Yuan Fu
5416ae5990
; Update guides in /admin/notes/tree-sitter
...
* admin/notes/tree-sitter/html-manual/Language-Definitions.html
* admin/notes/tree-sitter/html-manual/Multiple-Languages.html
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Indentation.html
* admin/notes/tree-sitter/html-manual/Parsing-Program-Source.html
* admin/notes/tree-sitter/html-manual/Pattern-Matching.html
* admin/notes/tree-sitter/html-manual/Retrieving-Node.html
* admin/notes/tree-sitter/html-manual/Tree_002dsitter-C-API.html
* admin/notes/tree-sitter/html-manual/Using-Parser.html
* admin/notes/tree-sitter/starter-guide: Update to reflect changes
made recently.
2022-11-03 11:43:44 -07:00
Po Lu
9909652849
More style fixes to tree-sitter code
...
* src/treesit.c (treesit_node_uptodate_p):
* src/treesit.h: Fix coding style.
2022-11-03 19:14:16 +08:00
Po Lu
6b91ea5a61
Minor fixes to last tree-sitter change
...
* src/treesit.c (treesit_find_override_name): Initialize
variable.
(Ftreesit_query_expand): Revert change to behavior.
2022-11-03 19:13:33 +08:00
Po Lu
bd8e19e1e2
Stylistic changes to tree-sitter code
...
* src/treesit.c (treesit_find_override_name)
(treesit_load_language_push_for_each_suffix, treesit_load_language)
(Ftreesit_langauge_available_p, treesit_record_change)
(make_treesit_parser, make_treesit_node, make_treesit_query)
(Ftreesit_parser_create, Ftreesit_parser_delete, Ftreesit_parser_list)
(treesit_check_range_argument, Ftreesit_parser_included_ranges)
(Ftreesit_node_start, Ftreesit_node_end, Ftreesit_node_check)
(Ftreesit_node_child_by_field_name, Ftreesit_pattern_expand)
(Ftreesit_query_expand, treesit_predicates_for_pattern)
(treesit_predicate_capture_name_to_text, treesit_predicate_equal)
(treesit_predicate_match, treesit_eval_predicates)
(Ftreesit_query_capture, treesit_search_dfs, treesit_build_sparse_tree)
(syms_of_treesit): Use FOR_EACH_TAIL (or FOR_EACH_TAIL_SAFE where not
obviously safe), and check list heads and tails correctly; fix coding
style of various constructs, especially:
variable =
mumble (frob (bar), (foo () + bar ()) + (baz () + quux ()))
which should actually be
variable
= mumble (frob (bar), (foo () + bar ()) + (baz () + quux ()))
and
foo =
mumble (frob (bar), 0)
+ (foo () + bar ())
+ (baz () + quux ())
which should actually be
foo = (mumble (frob (bar), 0)
+ (foo () + bar ())
+ (baz () + quux ()))
* src/treesit.h: Make declaration coding style consistent.
2022-11-03 19:13:33 +08:00
Yuan Fu
88d54756d4
Check for outdated tree-sitter node when printing
...
* src/print.c (print_vectorlike): Check for outdated node.
* src/treesit.c (treesit_check_node): Use the new function.
(treesit_node_uptodate_p): New function.
* src/treesit.h: Declare new function.
2022-11-02 17:47:14 -07:00
Yuan Fu
32e87f09c8
; * src/print.c (print_vectorlike): Fix comment for tree-sitter.
2022-11-02 17:23:29 -07:00