]> git.eshelyaron.com Git - emacs.git/log
emacs.git
2 years ago* lisp/treesit.el (treesit-node-top-level-p): New argument TYPE.
Yuan Fu [Thu, 27 Oct 2022 01:31:07 +0000 (18:31 -0700)]
* lisp/treesit.el (treesit-node-top-level-p): New argument TYPE.

2 years agoGeneralize js--treesit-imenu-top-level-p
Yuan Fu [Thu, 27 Oct 2022 01:06:07 +0000 (18:06 -0700)]
Generalize js--treesit-imenu-top-level-p

* lisp/progmodes/js.el (js--treesit-imenu-top-level-p): Move.
(js--treesit-font-lock-settings): Fix usage.
* lisp/treesit.el (treesit-node-top-level-p): Move to here.

2 years agoAdd tree-sitter navigation support to python-mode
Yuan Fu [Wed, 26 Oct 2022 22:38:40 +0000 (15:38 -0700)]
Add tree-sitter navigation support to python-mode

* lisp/progmodes/python.el (python-mode): Set
treesit-defun-type-regexp.

2 years agoAdd tree-sitter imenu support for js-mode and ts-mode
Yuan Fu [Wed, 26 Oct 2022 22:36:15 +0000 (15:36 -0700)]
Add tree-sitter imenu support for js-mode and ts-mode

js-mode's current imenu is pretty plain and incomplete, so I took the
liberty to add a bit more flair to it.

* lisp/progmodes/js.el (js--treesit-imenu-type-alist): New variable.
(js--treesit-imenu-top-level-p)
(js--treesit-imenu-label)
(js--treesit-imenu-1)
(js--treesit-imenu): New functions.

2 years agoFix tree-sitter navigation
Yuan Fu [Wed, 26 Oct 2022 22:34:02 +0000 (15:34 -0700)]
Fix tree-sitter navigation

* lisp/treesit.el (treesit-search-forward-goto): Track current
position with a local variable instead of (point).  Clean up the
condition forms.
(treesit-beginning-of-defun): Fix traverse direction.

2 years ago* src/treesit.c (treesit_search_dfs): Fix traverse algorithm.
Yuan Fu [Wed, 26 Oct 2022 05:48:30 +0000 (22:48 -0700)]
* src/treesit.c (treesit_search_dfs): Fix traverse algorithm.

2 years ago; * src/treesit.c (treesit_search_forward): Fix comment.
Yuan Fu [Wed, 26 Oct 2022 03:28:40 +0000 (20:28 -0700)]
; * src/treesit.c (treesit_search_forward): Fix comment.

2 years ago* src/treesit.c (treesit_search_forward): Fix traverses algorithm.
Yuan Fu [Wed, 26 Oct 2022 02:49:03 +0000 (19:49 -0700)]
* src/treesit.c (treesit_search_forward): Fix traverses algorithm.

2 years agoDon't disable parse cache in tree-sitter activated js-mode
Yuan Fu [Wed, 26 Oct 2022 02:46:58 +0000 (19:46 -0700)]
Don't disable parse cache in tree-sitter activated js-mode

* lisp/progmodes/js.el (js-mode): Move parse cache setup back.

2 years ago* lisp/treesit.el (treesit-simple-indent-rules): Make buffer-local.
Yuan Fu [Tue, 25 Oct 2022 21:27:23 +0000 (14:27 -0700)]
* lisp/treesit.el (treesit-simple-indent-rules): Make buffer-local.

2 years agoFix treesit-language-at
Yuan Fu [Tue, 25 Oct 2022 21:26:41 +0000 (14:26 -0700)]
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.

2 years agoNew tree-sitter toggle scheme
Yuan Fu [Tue, 25 Oct 2022 20:54:12 +0000 (13:54 -0700)]
New tree-sitter toggle scheme

This version: central variable, everything controlled by
treesit-settings.  Major mode sets up tree-sitter/non-tree-sitter
in a conditional branch, based on the setting.

* lisp/treesit.el (treesit-settings): New option.
(treesit-defun-type-regexp): Change docstring.
(treesit-mode-supported)
(treesit-required-languages)
(treesit--local-variable-backup): Remove variables.
(treesit--backup-local-variable)
(treesit-mode)
(global-treesit-mode--turn-on)
(global-treesit-mode): Remove functions.
(treesit--setting-for-mode): New function.
(treesit-ready-p): New argument MODE, changed REPORT to QUIET, and
LANGUAGEs to LANGUAGE (now it can be a single symbol or a list of
them).
(treesit-major-mode-setup): New function.  Mostly comes from
treesit-mode.

* test/src/treesit-tests.el (treesit-misc): New test.

* lisp/progmodes/python.el (python-mode): Move some setup code into
the conditional branch at the end.

* lisp/progmodes/js.el (js-json-mode)
(js-mode): Move some setup code into the conditional branch at the
end.

* lisp/progmodes/ts-mode.el: Move tree-sitter setup into the
conditional branch.

2 years ago* lisp/progmodes/ts-mode.el (ts-mode): Fix font-lock setup.
Yuan Fu [Mon, 24 Oct 2022 22:02:41 +0000 (15:02 -0700)]
* lisp/progmodes/ts-mode.el (ts-mode): Fix font-lock setup.

2 years ago* lisp/treesit.el (treesit-node-at): Remove argument LARGEST.
Yuan Fu [Mon, 24 Oct 2022 01:54:12 +0000 (18:54 -0700)]
* lisp/treesit.el (treesit-node-at): Remove argument LARGEST.

LARGEST returns the root node at BOB, finding the smallest node at
point and search upward is a better practice.

2 years ago* lisp/treesit.el (treesit-parser-range-on): New function.
Yuan Fu [Mon, 24 Oct 2022 01:51:35 +0000 (18:51 -0700)]
* lisp/treesit.el (treesit-parser-range-on): New function.

2 years agoFix treesit-beginning/end-of-defun
Yuan Fu [Mon, 24 Oct 2022 01:47:02 +0000 (18:47 -0700)]
Fix treesit-beginning/end-of-defun

Now they always move to the top-level defun (i.e., skips nested ones).

* lisp/treesit.el (treesit--find-top-level-match): New function
(treesit-beginning-of-defun): Goes to the top-level match.
(treesit-end-of-defun): Simply move to the end of current match.

2 years agoMake treesit-search-forward-goto accept a NODE argument
Yuan Fu [Mon, 24 Oct 2022 01:29:02 +0000 (18:29 -0700)]
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.

2 years agoMake treesit-node-at return the last leaf node at EOB
Yuan Fu [Mon, 24 Oct 2022 01:23:17 +0000 (18:23 -0700)]
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.

2 years agoMake treesit-node-child and fiends accept negative index
Yuan Fu [Mon, 24 Oct 2022 01:05:10 +0000 (18:05 -0700)]
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.

2 years ago; * lisp/treesit.el (treesit-range-functions): Fix typo.
Yuan Fu [Sun, 23 Oct 2022 23:45:54 +0000 (16:45 -0700)]
; * lisp/treesit.el (treesit-range-functions): Fix typo.

2 years ago* lisp/treesit.el (treesit-node-at): Add LARGEST argument.
Yuan Fu [Sun, 23 Oct 2022 23:16:27 +0000 (16:16 -0700)]
* lisp/treesit.el (treesit-node-at): Add LARGEST argument.

2 years agoChange function signiture of treesit search functions
Yuan Fu [Sun, 23 Oct 2022 21:56:17 +0000 (14:56 -0700)]
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.

2 years ago; Resolve FIXME's in tree-sitter manual sections
Yuan Fu [Sun, 23 Oct 2022 21:23:59 +0000 (14:23 -0700)]
; 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.

2 years ago; Minor copyedits of tree-sitter stuff in ELisp manual
Eli Zaretskii [Sun, 23 Oct 2022 08:14:18 +0000 (11:14 +0300)]
; 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.

2 years agoFix infinite loop in treesit-search-forward-goto
Yuan Fu [Sun, 23 Oct 2022 05:50:56 +0000 (22:50 -0700)]
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.

2 years agoResolve FIXME's in tree-sitter manual sections
Yuan Fu [Sun, 23 Oct 2022 01:44:11 +0000 (18:44 -0700)]
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.

2 years agoClean up tree-sitter sections of the ELisp manual
Eli Zaretskii [Sat, 22 Oct 2022 15:48:42 +0000 (18:48 +0300)]
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.

2 years ago* lisp/treesit.el (treesit-font-lock-enable): Add function back.
Yuan Fu [Sat, 22 Oct 2022 01:50:24 +0000 (18:50 -0700)]
* lisp/treesit.el (treesit-font-lock-enable): Add function back.

2 years agoRevise the toggle scheme of tree-sitter (again)
Yuan Fu [Wed, 19 Oct 2022 23:44:04 +0000 (16:44 -0700)]
Revise the toggle scheme of tree-sitter (again)

Now instead of a toggle function (major-mode-backend-function), we let
major mode set local variables like treesit-font-lock-settings,
treesit-imenu-function, then treesit-mode takes care of activating
those things (clearing font-lock-keywords, setting
imenu-create-index-function to treesit-imenu-function, etc).

js.el and python.el: I've returned js-mode and python-mode to exactly
what they were before tree-sitter change, plus lines at the end
setting up tree-sitter variables.  Sorry about all these fuss :-D

* lisp/treesit.el (treesit-mode-inhibit-message): Remove option.
(major-mode-backend-function)
(treesit-remapped-major-mode-alist): Remove variables.
(treesit-mode): Move down to the end of buffer.  Do more things.
(global-treesit-mode): Move down to the end of buffer.  Don't handle
major-mode-remap-alist anymore.
(global-treesit-mode--turn-on): Move down to the end of buffer.
(treesit-ready-p): Move down to the end of buffer.  Changed signature.
(treesit-font-lock-enable): Remove function.
(treesit-defun-type-regexp): New variable.
(treesit-beginning-of-defun)
(treesit-end-of-defun): New function.
(treesit-imenu-function): New variable.
(treesit-mode-supported)
(treesit-required-languages)
(treesit--local-variable-backup): New variables.
(treesit--backup-local-variable): New function

* lisp/progmodes/js.el (js-use-tree-sitter): Remove option.
(js--treesit-defun-type-regexp): Remove variable.  (Now set inline in
js-mode.)
(js--treesit-beginning-of-defun)
(js--treesit-end-of-defun): Remove functions.  (Now use
treesit-beginning/end-of-defun.)
(js--backend-toggle)
(js--json-backend-toggle): Remove function.
(js-mode)
(js-json-mode): Restore back to before tree-sitter changes.  Add
tree-sitter setup at the end.

* lisp/progmodes/python.el (python--backend-toggle): Remove function.
(python-mode): Restore back to before tree-sitter changes.  Add
tree-sitter setup at the end.

* lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): Use
js--fontify-template-string.
(ts-mode--fontify-template-string): Remove function (because we can
just use js--fontify-template-string).
(ts-mode--defun-type-regexp): Remove variable (now set inline in
ts-mode).
(ts-mode--beginning-of-defun)
(ts-mode--end-of-defun): Remove functions (now using
treesit-beginning/end-of-defun).
(ts-mode): Setup tree-sitter variables and then turn on treesit-mode
or move to js-mode.

2 years agoAdd a new section to tree-sitter's manual node
Yuan Fu [Tue, 18 Oct 2022 21:24:22 +0000 (14:24 -0700)]
Add a new section to tree-sitter's manual node

* doc/lispref/parsing.texi (Parsing Program Source): New section
Tree-sitter major modes.

2 years ago; * lisp/progmodes/python.el (python--backend-toggle): Use cond.
Yuan Fu [Tue, 18 Oct 2022 21:06:13 +0000 (14:06 -0700)]
; * lisp/progmodes/python.el (python--backend-toggle): Use cond.

2 years agoAdd more granular features in font-locking
Theodor Thornhill [Mon, 17 Oct 2022 10:49:19 +0000 (12:49 +0200)]
Add more granular features in font-locking

There is now support for three font-locking levels, 'minimal',
'moderate' and 'full'.  The richest experience is to be expected from
the 'full', and all levels are enabled by default.

* lisp/progmodes/js.el (js--treesit-font-lock-settings): New defvar
renamed from 'js--treesit-settings'.

(js--treesit-font-lock-settings): New defvar renamed from
'js--json-treesit-settings'.

* lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings): New defvar
renamed from 'ts-mode--settings'.

2 years agoRename tree-sitter group to treesit
Yuan Fu [Tue, 18 Oct 2022 20:24:37 +0000 (13:24 -0700)]
Rename tree-sitter group to treesit

* lisp/treesit.el (tree-sitter): Rename to treesit.
(treesit-mode)
(global-treesit-mode): Use treesit group.

2 years ago* lisp/treesit.el: Add commentary.
Yuan Fu [Tue, 18 Oct 2022 20:21:55 +0000 (13:21 -0700)]
* lisp/treesit.el: Add commentary.

2 years agoInstall new toggle scheme for tree-sitter
Yuan Fu [Tue, 18 Oct 2022 20:06:25 +0000 (13:06 -0700)]
Install new toggle scheme for tree-sitter

Basically we now have treesit-mode and global-treesit-mode.  Major
modes set major-mode-backend-function which treesit-mode calls to
activate/deactivate tree-sitter.

js.el needs a bit explanation: I'm so sorry for messing up the
history, but basically now js-mode and js-json-mode should be exactly
the same as before any tree-sitter change was introduced, sans some
initialization code that are moved to js(-json)--backend-toggle.
js-mode and js-json-mode now just sets major-mode-backend-function and
initialize with js(-json)--backend-toggle.

* lisp/treesit.el (treesit-mode-inhibit-message): New option.
(treesit-can-enable-p): Remove function.
(major-mode-backend-function)
(treesit-remapped-major-mode-alist): New variables.
(treesit-mode)
(global-treesit-mode): New minor modes.
(global-treesit-mode--turn-on)
(treesit-ready-p): New functions.

* lisp/progmodes/python.el: Remove option.
(python--backend-toggle): New function.
(python-mode): Remove the if-form, all the initialization code are
moved to python--backend-toggle, python-mode now just sets
major-mode-backend-function and initialize with
python--backend-toggle.
* lisp/progmodes/js.el (js--treesit-can-enable-p)
(js--json-treesit-can-enable-p)
(js--treesit-enable)
(js--json-treesit-enable): Remove functions.
(js--backend-toggle)
(js-json--backend-toggle): New function.

* lisp/progmodes/ts-mode.el (ts-mode): Use treesit-ready-p.

2 years ago; Fix typos in treesit.c
Daniel Martín [Mon, 17 Oct 2022 23:00:13 +0000 (01:00 +0200)]
; Fix typos in treesit.c

* src/treesit.c: Fix a couple of typos.  (Bug#58600)

2 years agoChange free to xfree in treesit.el
Yuan Fu [Tue, 18 Oct 2022 00:31:23 +0000 (17:31 -0700)]
Change free to xfree in treesit.el

This should be in the last commit but I forgot.

* src/treesit.c (Ftreesit_parser_set_included_ranges): Change free to
xfree.

2 years agoChange malloc to xmalloc in treesit.c
Yuan Fu [Tue, 18 Oct 2022 00:13:25 +0000 (17:13 -0700)]
Change malloc to xmalloc in treesit.c

* src/treesit.c (Ftreesit_parser_set_included_ranges): Change malloc
to xmalloc.

2 years agoFix casts to uint32_t in treesit.c
Yuan Fu [Tue, 18 Oct 2022 00:04:49 +0000 (17:04 -0700)]
Fix casts to uint32_t in treesit.c

* src/treesit.c (treesit_tree_edit_1): Add assertion.
(treesit_ensure_position_synced): Add assertion.
(treesit_check_buffer_size): Change error message.
(treesit_ensure_parsed): Move treesit_check_buffer_size and
treesit_ensure_position_synced together
(treesit_read_buffer): Add assertion.
(Ftreesit_parser_set_included_ranges): Add assertion.  Signal error if
list too long.  Add check for buffer size.
(Ftreesit_parser_included_ranges): Add check for buffer size.
(Ftreesit_query_capture): Add assertion.

2 years agoSimplify error reported by loading tree-sitter language definition
Yuan Fu [Mon, 17 Oct 2022 21:12:24 +0000 (14:12 -0700)]
Simplify error reported by loading tree-sitter language definition

Before:

Error: Cannot load language definition:
"javascript",
("/home/jostein/.emacs.d/tree-sitter/libtree-sitter-javascript:
cannot open shared object file: No such file or directory"
"/home/jostein/.emacs.d/tree-sitter/libtree-sitter-javascript.so:
cannot open shared object file: No such file or directory"
"libtree-sitter-javascript: cannot open shared object file: No such
file or directory" "libtree-sitter-javascript.so: cannot open shared
object file: No such file or directory")

After:

(treesit-load-language-error
not-found
("libtree-sitter-z.so" "libtree-sitter-z.dylib")
"No such file or directory")

* src/treesit.c (treesit_load_language): Add base_candidates, remove
error_list, report base_candidates rather than error_list.

2 years agoSkip tree-sitter tests unless language definition is available
Yuan Fu [Mon, 17 Oct 2022 21:00:12 +0000 (14:00 -0700)]
Skip tree-sitter tests unless language definition is available

* test/src/treesit-tests.el (treesit-basic-parsing)
(treesit-node-api)
(treesit-query-api)
(treesit-narrow)
(treesit-cross-boundary)
(treesit-multi-lang)
(treesit-node-supplemental): Add skip-unless form.

2 years agoFix memory leak in ts_load_language
Yuan Fu [Mon, 17 Oct 2022 20:43:06 +0000 (13:43 -0700)]
Fix memory leak in ts_load_language

* src/treesit.c (ts_load_language): Move initialization of c_name down
and free it right after use.

2 years agoMake sure the treesit path variables are lists
Eli Zaretskii [Mon, 17 Oct 2022 17:39:23 +0000 (20:39 +0300)]
Make sure the treesit path variables are lists

* src/treesit.c: (treesit_load_language)
(treesit_find_override_name): Make sure the lists we use are
really lists.

2 years ago; Rename ts_* symbols in treesit.c
Eli Zaretskii [Mon, 17 Oct 2022 10:11:13 +0000 (13:11 +0300)]
; Rename ts_* symbols in treesit.c

* src/treesit.c: Rename all ts_* functions and variables to
treesit_*; all references changed.  Fix whitespace.

2 years agoFix js/ts tree-sitter template_string font-lock
Yuan Fu [Mon, 17 Oct 2022 08:47:01 +0000 (01:47 -0700)]
Fix js/ts tree-sitter template_string font-lock

* lisp/progmodes/js.el (js--treesit-settings): Fontify
template_strings with js--fontify-template-string.
(js--fontify-template-string): New function.
(js--json-treesit-settings): Add missing :feature flag.
* lisp/progmodes/ts-mode.el (ts-mode--settings): Fontify
template_strings with js--fontify-template-string.

2 years ago; * src/treesit.c (ts_search_dfs): Fix tab inline.
Yuan Fu [Mon, 17 Oct 2022 05:30:16 +0000 (22:30 -0700)]
; * src/treesit.c (ts_search_dfs): Fix tab inline.

Introduced by c6dce90d7e5 which is a format-fix so I think it's fine
to fix this as a standalone change?

2 years ago; * src/treesit.c: Change commentary to reflect recent changes.
Yuan Fu [Mon, 17 Oct 2022 05:29:15 +0000 (22:29 -0700)]
; * src/treesit.c: Change commentary to reflect recent changes.

2 years ago* lisp/treesit.el (treesit-font-lock-rules): Warn about :feature.
Yuan Fu [Sat, 15 Oct 2022 23:14:02 +0000 (16:14 -0700)]
* lisp/treesit.el (treesit-font-lock-rules): Warn about :feature.

2 years ago; Fix doc strings in treesit.c
Eli Zaretskii [Mon, 17 Oct 2022 07:54:55 +0000 (10:54 +0300)]
; Fix doc strings in treesit.c

* src/treesit.c (Ftreesit_language_version)
(Ftreesit_parser_create, Ftreesit_parser_delete)
(Ftreesit_parser_language, Ftreesit_parser_set_included_ranges)
(Ftreesit_parser_included_ranges, Ftreesit_node_start)
(Ftreesit_node_end, Ftreesit_node_parent, Ftreesit_node_child)
(Ftreesit_node_check, Ftreesit_node_field_name_for_child)
(Ftreesit_node_child_by_field_name, Ftreesit_node_next_sibling)
(Ftreesit_node_prev_sibling, Ftreesit_node_first_child_for_pos)
(Ftreesit_node_descendant_for_range, Ftreesit_pattern_expand)
(Ftreesit_query_expand, Ftreesit_query_compile)
(Ftreesit_query_capture, Ftreesit_search_subtree)
(Ftreesit_search_forward, Ftreesit_induce_sparse_tree)
(syms_of_treesit): Doc string fixes.

2 years ago; * src/treesit.c: Fix some indentation problems and doc strings.
Eli Zaretskii [Sun, 16 Oct 2022 15:09:01 +0000 (18:09 +0300)]
; * src/treesit.c: Fix some indentation problems and doc strings.

2 years agoSupport MinGW build on MS-Windows
Eli Zaretskii [Sun, 16 Oct 2022 13:22:09 +0000 (16:22 +0300)]
Support MinGW build on MS-Windows

* src/treesit.c [WINDOWSNT]: Add MS-Windows boilerplate for
dynamically-loaded optional libraries.
(init_treesit_functions) [WINDOWSNT]: New function.
(load_tree_sitter_if_necessary): New function.
(ts_initialize): Call 'load_tree_sitter_if_necessary'.
(ts_delete_parser, ts_delete_query, ts_named_node_p): Wrapper
functions for TS calls from outside treesit.c.
(Ftreesit_parser_root_node, Ftreesit_parser_set_included_ranges)
(Ftreesit_parser_included_ranges, Ftreesit_node_type)
(Ftreesit_node_start, Ftreesit_node_end, Ftreesit_node_string)
(Ftreesit_node_parent, Ftreesit_node_child, Ftreesit_node_check)
(Ftreesit_node_field_name_for_child, Ftreesit_node_child_count)
(Ftreesit_node_next_sibling, Ftreesit_node_prev_sibling)
(Ftreesit_node_first_child_for_pos)
(Ftreesit_node_descendant_for_range, Ftreesit_node_eq)
(Ftreesit_query_compile, Ftreesit_query_capture)
(Ftreesit_search_subtree, Ftreesit_search_forward)
(Ftreesit_induce_sparse_tree): Call 'ts_initialize' before any
other TS functions.
(Ftreesit_available_p): 'treesit-available-p' implemented in C, so
that on WINDOWSNT the library could be loaded dynamically.
* src/treesit.h (ts_delete_parser, ts_delete_query)
(ts_named_node_p): Add prototypes.
* src/print.c (print_vectorlike):
* src/alloc.c (cleanup_vector): Call tree-sitter function via
wrappers defined in treesit.c, not directly, because WINDOWSNT
redefines the TS functions to be called via function pointers.
* src/Makefile.in (base_obj): Add treesit.o
(TREE_SITTER_OBJ): Remove.

* lisp/treesit.el (treesit-available-p): Remove: now implemented
in C.
* lisp/term/w32-win.el (dynamic-library-alist): Add libtree-sitter
DLLs.

* configure.ac (TREE_SITTER): Support the MinGW build.
(TREE_SITTER_OBJ): Remove.

2 years agoUpdate ts-mode font-lock to work with tree-sitter's :feature
Yuan Fu [Sat, 15 Oct 2022 23:09:35 +0000 (16:09 -0700)]
Update ts-mode font-lock to work with tree-sitter's :feature

* lisp/progmodes/ts-mode.el (ts-mode--settings): Add :feature flag.
(ts-mode): Set treesit-font-lock-feature-list.

2 years agoUpdate tree-sitter manual to reflect the previous commit
Yuan Fu [Thu, 13 Oct 2022 22:08:20 +0000 (15:08 -0700)]
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)}.

2 years agoRework tree-sitter font-lock
Yuan Fu [Thu, 13 Oct 2022 21:44:42 +0000 (14:44 -0700)]
Rework tree-sitter font-lock

Remove :toggle and :level, add :feature.

* lisp/progmodes/js.el (js--treesit-settings): Add :feature.
(js--treesit-enable): Set treesit-font-lock-feature-list.
* lisp/progmodes/python.el: Replace :level with :feature.
(python-mode): Set treesit-font-lock-feature-list.
* lisp/treesit.el (treesit-font-lock-feature-list): New variable.
(treesit-font-lock-settings): Change format.
(treesit-font-lock-rules): Remove :toggle and :level, add :feature.
(treesit-font-lock-recompute-features): New function.
(treesit-font-lock-fontify-region): Change to work with the new
format.
(treesit-font-lock-enable): Add call to
treesit-font-lock-recompute-features.  And improve the font-lock-mode
workaround.

2 years ago* doc/lispref/parsing.texi: Add manual for treesit-query-language.
Yuan Fu [Thu, 13 Oct 2022 21:40:38 +0000 (14:40 -0700)]
* doc/lispref/parsing.texi: Add manual for treesit-query-language.

2 years ago* src/treesit.c (Ftreesit_query_language): New function.
Yuan Fu [Thu, 13 Oct 2022 21:39:51 +0000 (14:39 -0700)]
* src/treesit.c (Ftreesit_query_language): New function.

2 years agoBetter signal data for treesit-load-language-error
Yuan Fu [Wed, 12 Oct 2022 17:38:35 +0000 (10:38 -0700)]
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.

2 years ago; Comment and docstring fixup in ts-mode.el
Yuan Fu [Wed, 12 Oct 2022 06:49:04 +0000 (23:49 -0700)]
; Comment and docstring fixup in ts-mode.el

* lisp/progmodes/ts-mode.el: Add comment section and docstrings.

2 years agoAdd TypeScript support with tree-sitter
Theodor Thornhill [Tue, 11 Oct 2022 08:27:55 +0000 (10:27 +0200)]
Add TypeScript support with tree-sitter

* lisp/progmodes/ts-mode.el (ts-mode): New major mode for TypeScript
with support for tree-sitter.  It uses the TSX parser, so that we get
support for TSX as well as TypeScript.  If we cannot find tree-sitter,
we default to using js-mode.

2 years agoFix byte-compile warning for js--treesit-defun-type-regexp
Theodor Thornhill [Tue, 11 Oct 2022 08:03:33 +0000 (10:03 +0200)]
Fix byte-compile warning for js--treesit-defun-type-regexp

* lisp/progmodes/js.el (js--treesit-defun-type-regexp): Move before
js--treesit-beginning-of-defun.

2 years agoLazily compile tree-sitter query
Yuan Fu [Tue, 11 Oct 2022 16:30:42 +0000 (09:30 -0700)]
Lazily compile tree-sitter query

See comment on struct Lisp_TS_Query for why.  Previous commits adding
python and js support for tree-sitter breaks Emacs build if language
definitions aren't available at build time.  This commit fixes that.

Now query object don't compile the query upon creation, but stores the
query source and language symbol, and compiles upon first use (in
treesit-query-capture).

I want ts_ensure_query_compiled to return signal symbol and data
rather than signaling itself, because it's a helper function not lisp
function.  But because it calls ts_load_language, I had to update
ts_load_language to also use the signal symbol/data interface.

* src/treesit.h (struct Lisp_TS_Query): Add two new field.
* src/treesit.c (ts_load_language): Return signal symbol and data
rather than signaling itself.
(Ftreesit_langauge_available_p)
(Ftreesit_parser_create): Update usage of ts_load_language

(make_ts_query): Now returns a lisp object.
(ts_query_error_to_string): Moved because it's used by
ts_compose_query_signal_data.
(ts_compose_query_signal_data)
(ts_ensure_query_compiled): New functions.
(Ftreesit_query_compile): Delay compiling the query.
(Ftreesit_query_capture): Instead of creating a query object which
compiles the query, now goes two routes: if QUERY is a query object,
make sure it is compiled and use the TSQuery; if QUERY is a cons or
string, compile directly to TSQuery, and free it after use.  Creating
a lisp query requires the language symbol, but in this function we
only have TSLanguage.

2 years agoFix typo in Makefile.in
Daniel Martín [Mon, 10 Oct 2022 11:03:30 +0000 (13:03 +0200)]
Fix typo in Makefile.in

* src/Makefile.in (TREE_SITTER_CFLAGS): Set the correct C flags.

2 years agoMake treesit-node-at faster
Yuan Fu [Mon, 10 Oct 2022 18:56:12 +0000 (11:56 -0700)]
Make treesit-node-at faster

* lisp/treesit.el (treesit-node-at): We only need to use
treesit-node-first-child-for-pos.  This is both faster for large
buffers and simpler.  Also remove the TODO comment.

2 years agoFix typo in treesit--check-manual-covarage
Theodor Thornhill [Mon, 10 Oct 2022 18:20:19 +0000 (20:20 +0200)]
Fix typo in treesit--check-manual-covarage

* lisp/treesit.el (treesit--check-manual-coverage): Fix typo in
function name and also lookup the correct library in
`find-library-name'

2 years agoImprove treesit-search-forward-goto so it doens't stuck at EOF
Yuan Fu [Mon, 10 Oct 2022 18:14:35 +0000 (11:14 -0700)]
Improve treesit-search-forward-goto so it doens't stuck at EOF

* lisp/treesit.el (treesit-search-forward-goto): Handle the edge case.

2 years ago* admin/notes/tree-sitter/starter-guide (Navigation): Improve demo.
Yuan Fu [Mon, 10 Oct 2022 18:00:51 +0000 (11:00 -0700)]
* admin/notes/tree-sitter/starter-guide (Navigation): Improve demo.

2 years agoFix js--treesit-beginning/end-of-defun
Yuan Fu [Mon, 10 Oct 2022 17:46:47 +0000 (10:46 -0700)]
Fix js--treesit-beginning/end-of-defun

* lisp/progmodes/js.el (require): Add rx.
(js--treesit-move-to-node): Remove function.
(js--treesit-beginning-of-defun)
(js--treesit-end-of-defun): Change to use treesit-search-forward-goto.
(js-treesit--defun-query): Remove variable.
(js--treesit-defun-type-regexp): Add variable.

2 years agoAdd tree-sitter functionality to js-mode
Theodor Thornhill [Sun, 9 Oct 2022 19:22:55 +0000 (21:22 +0200)]
Add tree-sitter functionality to js-mode

The diff for js-mode, js-json-mode, js-jsx-mode are a bit strange, but
all we did is to wrap some the old code in

(if tree-sitter
  (tree-sitter-enable)
 ...some old-code)

...other old-code (that’s tree-sitter-agnostic)

* lisp/progmodes/js.el (treesit): Add tree-sitter dependency
(js-use-treesitter)
(js-json-use-treesitter): New custom options.

(js--treesit-keywords)
(js--treesit-settings)
(js--treesit-indent-rules)
(js--json-treesit-settings)
(js--json-treesit-indent-rules): New variables.

(js--treesit-backward-up-list)
(js-treesit-current-defun)
(js--treesit-move-to-node)
(js--treesit-beginning-of-defun, js--treesit-end-of-defun)
(js--treesit-enable)
(js--json-treesit-enable): New functions.

(js-mode, js-json-mode, js-jsx-mode): Add support for tree-sitter
functionalities.

2 years agoFix tree-sitter build script in admin/notes
Yuan Fu [Mon, 10 Oct 2022 16:14:30 +0000 (09:14 -0700)]
Fix tree-sitter build script in admin/notes

* admin/notes/tree-sitter/build-module/README: Add explaination.
* admin/notes/tree-sitter/build-module/build.sh: change
typescript to tsx.

2 years agoRename custom group treesit to tree-sitter
Yuan Fu [Mon, 10 Oct 2022 03:59:59 +0000 (20:59 -0700)]
Rename custom group treesit to tree-sitter

* lisp/treesit.el (treesit): Rename.

2 years agoAdd :version tag for new tree-sitter custom options
Yuan Fu [Mon, 10 Oct 2022 03:54:19 +0000 (20:54 -0700)]
Add :version tag for new tree-sitter custom options

* lisp/progmodes/python.el (python-use-tree-sitter): Add version tag.
* lisp/treesit.el (treesit):
(treesit-max-buffer-size): Add version tag.

2 years agoMake python tree-sitter font-lock support decoration levels
Yuan Fu [Sun, 9 Oct 2022 22:19:36 +0000 (15:19 -0700)]
Make python tree-sitter font-lock support decoration levels

* lisp/progmodes/python.el (python--treesit-settings): Stratify into
three levels.

2 years agoMake tree-sitter font-lock support decoration levels
Yuan Fu [Sun, 9 Oct 2022 22:17:11 +0000 (15:17 -0700)]
Make tree-sitter font-lock support decoration levels

* admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html:
Update.
* admin/notes/tree-sitter/html-manual/Parsing-Program-Source.html:
Update.
* doc/lispref/modes.texi: Mention the new :level option.
* lisp/treesit.el (treesit-font-lock-settings): Update docstring.
(treesit-font-lock-rules): Support :level.  Relayout the let form.
(treesit-font-lock-fontify-region): Support :level.

2 years agoAdd note on tree-sitter's naming convention
Yuan Fu [Sat, 8 Oct 2022 01:06:04 +0000 (18:06 -0700)]
Add note on tree-sitter's naming convention

* admin/notes/tree-sitter/starter-guide: Add note.
* doc/lispref/parsing.texi: Add note.

2 years agoAdd a :toggle option for tree-sitter font-lock
Yuan Fu [Fri, 7 Oct 2022 08:21:09 +0000 (01:21 -0700)]
Add a :toggle option for tree-sitter font-lock

* admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html:
Update html manual.
* admin/notes/tree-sitter/html-manual/build-manual.sh: Fix manual
path.
* admin/notes/tree-sitter/starter-guide: Mention :toggle.
* doc/lispref/modes.texi: Mention :toggle.
* lisp/treesit.el (treesit-font-lock-settings): Update docstring.
(treesit-font-lock-rules): Handle :toggle.  Also change
some wrong-type-argument signal to treesit-font-lock-error which is
easier to understand.
(treesit-font-lock-fontify-region): Handle :toggle.

2 years ago* src/treesit.c (syms_of_treesit): Add Streesit_language_version.
Yuan Fu [Thu, 6 Oct 2022 22:46:01 +0000 (15:46 -0700)]
* src/treesit.c (syms_of_treesit): Add Streesit_language_version.

2 years agoMerge branch 'master' into feature/tree-sitter
Yuan Fu [Thu, 6 Oct 2022 18:06:07 +0000 (11:06 -0700)]
Merge branch 'master' into feature/tree-sitter

2 years agoPass correct environment name to `reftex-label'
Arash Esbati [Thu, 6 Oct 2022 17:45:44 +0000 (19:45 +0200)]
Pass correct environment name to `reftex-label'

* lisp/textmodes/tex-mode.el (latex-block-body-alist): Pass
"figure" to `reftex-label' when inserting a figure float.
(bug#58329)

2 years agoetc/NEWS: Fix typo in seq-keep entry.
Lars Ingebrigtsen [Thu, 6 Oct 2022 12:56:47 +0000 (14:56 +0200)]
etc/NEWS: Fix typo in seq-keep entry.

2 years agoReplace aging OpenPGP artifacts in gnus' mml-sec tests.
Justus Winter [Wed, 5 Oct 2022 10:36:39 +0000 (12:36 +0200)]
Replace aging OpenPGP artifacts in gnus' mml-sec tests.

This replaces the old OpenPGPv4 keys that are used in the test suite
with more modern OpenPGPv4 keys.

Having old cryptographic artifacts in the test suite presents a
problem once the old algorithms are rejected by contemporary
implementations (bug#58301).

2 years agoReplace aging OpenPGP artifacts in the package-resources tests.
Justus Winter [Fri, 16 Sep 2022 10:24:26 +0000 (12:24 +0200)]
Replace aging OpenPGP artifacts in the package-resources tests.

This replaces the old OpenPGPv4 key that is used in the test suite
with a more modern OpenPGPv4 key.  The key is the Alice key from
https://datatracker.ietf.org/doc/draft-bre-openpgp-samples/.  All
cryptographic artifacts in the test suite are updated accordingly.

Having old cryptographic artifacts in the test suite presents a
problem once the old algorithms are rejected by contemporary
implementations.

2 years agoReplace aging OpenPGP artifacts in the epg tests.
Justus Winter [Fri, 16 Sep 2022 10:24:14 +0000 (12:24 +0200)]
Replace aging OpenPGP artifacts in the epg tests.

This replaces the old OpenPGPv4 key that is used in the test suite
with a more modern OpenPGPv4 key.  The key is the Alice key from
https://datatracker.ietf.org/doc/draft-bre-openpgp-samples/.  All
cryptographic artifacts in the test suite are updated accordingly.

Having old cryptographic artifacts in the test suite presents a
problem once the old algorithms are rejected by contemporary
implementations.

2 years agoFix epg's reliance on an implicit GnuPG command.
Justus Winter [Fri, 16 Sep 2022 10:23:39 +0000 (12:23 +0200)]
Fix epg's reliance on an implicit GnuPG command.

Previously, epg invoked GnuPG without an explicit command to verify
signatures.  Make that operation explicit.  Happily, this aligns how
gpg and gpgsm is invoked, so it actually makes the code simpler.

2 years agoFix BSD battery mode over TRAMP (bug#58307)
Manuel Giraud [Thu, 6 Oct 2022 12:46:39 +0000 (14:46 +0200)]
Fix BSD battery mode over TRAMP (bug#58307)

* lisp/battery.el (battery--call-process-to-string): Simple wrapper
to `call-process' that outputs to a string.
(battery-bsd-apm): Use it instead of `shell-command-to-string'
(bug#58307).

2 years agoFix calling `package-reinstall' just after quick initialization.
Matt Armstrong [Thu, 6 Oct 2022 12:08:20 +0000 (14:08 +0200)]
Fix calling `package-reinstall' just after quick initialization.

* lisp/emacs-lisp/package.el (package-reinstall): call
`package--archives-initialize', just like `package-install' does.
This populates `package-alist', and so fixes calling
`package-reinstall' as the first thing done after package "quick
init" (Bug#53527).

2 years agoAdd missing staticpro (bug#58327)
Gerd Möllmann [Thu, 6 Oct 2022 08:18:59 +0000 (10:18 +0200)]
Add missing staticpro (bug#58327)

* src/window.c (init_window_once): staticpro old_selected_window.

2 years agoInhibit GC in probably_quit (bug#58042)
Gerd Möllmann [Thu, 6 Oct 2022 07:09:04 +0000 (09:09 +0200)]
Inhibit GC in probably_quit (bug#58042)

2 years ago* etc/NEWS: Document how to continue using 'linum'. (Bug#58220)
Stefan Kangas [Thu, 6 Oct 2022 06:54:54 +0000 (08:54 +0200)]
* etc/NEWS: Document how to continue using 'linum'.  (Bug#58220)

2 years ago; * src/xterm.c (x_term_init): Fix typo.
Po Lu [Thu, 6 Oct 2022 02:57:43 +0000 (10:57 +0800)]
; * src/xterm.c (x_term_init): Fix typo.

2 years agoMinor fixes to IM locale handling
Po Lu [Thu, 6 Oct 2022 02:55:25 +0000 (10:55 +0800)]
Minor fixes to IM locale handling

* lisp/term/x-win.el (x-get-input-coding-system): Translate locales.
* src/xterm.c (x_term_init): If the X library doesn't support
the current locale, don't set up input methods.

2 years agoFix nsmenu crash when exiting popup dialog
Po Lu [Thu, 6 Oct 2022 02:52:34 +0000 (10:52 +0800)]
Fix nsmenu crash when exiting popup dialog

* src/nsmenu.m (pop_down_menu): Do not discard menu items here.
(ns_popup_dialog): Call discard_menu_items after
unuse_menu_items.  (bug#58296)

2 years ago* etc/NEWS: Add instructions for replacing 'linum'. (Bug#58220)
Stefan Kangas [Wed, 5 Oct 2022 23:32:59 +0000 (01:32 +0200)]
* etc/NEWS: Add instructions for replacing 'linum'.  (Bug#58220)

2 years agoMerge branch 'master' into feature/tree-sitter
Yuan Fu [Wed, 5 Oct 2022 21:22:03 +0000 (14:22 -0700)]
Merge branch 'master' into feature/tree-sitter

2 years agoAdd tree-sitter admin notes
Yuan Fu [Wed, 5 Oct 2022 21:11:33 +0000 (14:11 -0700)]
Add tree-sitter admin notes

starter-guide: Guide on writing major mode features.
build-module: Script for building official language definitions.
html-manual: HTML version of the manual for easy access.

* admin/notes/tree-sitter/build-module/README: New file.
* admin/notes/tree-sitter/build-module/batch.sh: New file.
* admin/notes/tree-sitter/build-module/build.sh: New file.
* admin/notes/tree-sitter/starter-guide: New file.
* admin/notes/tree-sitter/html-manual/Accessing-Node.html: New file.
* admin/notes/tree-sitter/html-manual/Language-Definitions.html: New file.
* admin/notes/tree-sitter/html-manual/Multiple-Languages.html: New file.
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html:
New file.
* admin/notes/tree-sitter/html-manual/Parser_002dbased-Indentation.html:
New file.
* admin/notes/tree-sitter/html-manual/Parsing-Program-Source.html: New
file.
* admin/notes/tree-sitter/html-manual/Pattern-Matching.html: New file.
* admin/notes/tree-sitter/html-manual/Retrieving-Node.html: New file.
* admin/notes/tree-sitter/html-manual/Tree_002dsitter-C-API.html: New
file.
* admin/notes/tree-sitter/html-manual/Using-Parser.html: New file.
* admin/notes/tree-sitter/html-manual/build-manual.sh: New file.
* admin/notes/tree-sitter/html-manual/manual.css: New file.

2 years ago* lisp/repeat.el (repeat-exit): Add autoload cookie.
Juri Linkov [Wed, 5 Oct 2022 19:47:42 +0000 (22:47 +0300)]
* lisp/repeat.el (repeat-exit): Add autoload cookie.

2 years ago* etc/tutorials/TUTORIAL.uk: Fix typos.
Juri Linkov [Wed, 5 Oct 2022 19:43:12 +0000 (22:43 +0300)]
* etc/tutorials/TUTORIAL.uk: Fix typos.

2 years agoAdapt Tramp manual
Michael Albinus [Wed, 5 Oct 2022 15:11:33 +0000 (17:11 +0200)]
Adapt Tramp manual

* doc/misc/tramp.texi (Inline methods): Method "kubernetes" does
not support user names.

2 years agoNew command 'world-clock-copy-time-as-kill'
Stefan Kangas [Wed, 5 Oct 2022 14:33:18 +0000 (16:33 +0200)]
New command 'world-clock-copy-time-as-kill'

* lisp/time.el (world-clock-copy-time-as-kill): New command.
(world-clock-mode-map): Bind above new command to "w".

2 years agoAdd face help-key-binding in help-char echo
Stefan Kangas [Wed, 5 Oct 2022 13:23:39 +0000 (15:23 +0200)]
Add face help-key-binding in help-char echo

* src/keyboard.c (echo_add_key): Add help-key-binding face to the
"?" key in 'help-char' echo.  (Bug#57906)
(syms_of_keyboard) <Qhelp_key_binding>: New DEFSYM.

2 years ago; * lisp/files.el (find-file-noselect): Minor simplification.
Stefan Kangas [Wed, 5 Oct 2022 13:08:01 +0000 (15:08 +0200)]
; * lisp/files.el (find-file-noselect): Minor simplification.