From c786afcbb9f5c4edf845beae08bdaa11d168a42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Tue, 3 Jan 2023 22:08:13 +0100 Subject: [PATCH 1/8] Fontify C++ function definitions in c-ts-mode (bug#60529) * lisp/progmodes/c-ts-mode.el (c-ts-mode--declarator-identifier): Teach the code how to extract the declarator of a node of type "qualified_identifier". (c-ts-mode--fontify-declarator): Consider the case where the identifier in a function declarator is buried inside "qualifier_identifier" nodes. --- lisp/progmodes/c-ts-mode.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 1f2a195bf64..ffc15e681f7 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -430,6 +430,9 @@ MODE is either `c' or `cpp'." ((or "function_declarator" "array_declarator" "init_declarator") (c-ts-mode--declarator-identifier (treesit-node-child-by-field-name node "declarator"))) + ("qualified_identifier" + (c-ts-mode--declarator-identifier + (treesit-node-child-by-field-name node "name"))) ;; Terminal case. ((or "identifier" "field_identifier") node))) @@ -439,7 +442,14 @@ MODE is either `c' or `cpp'." For NODE, OVERRIDE, START, END, and ARGS, see `treesit-font-lock-rules'." (let* ((identifier (c-ts-mode--declarator-identifier node)) - (face (pcase (treesit-node-type (treesit-node-parent identifier)) + (qualified-root + (treesit-parent-while (treesit-node-parent identifier) + (lambda (node) + (equal (treesit-node-type node) + "qualified_identifier")))) + (face (pcase (treesit-node-type (treesit-node-parent + (or qualified-root + identifier))) ("function_declarator" 'font-lock-function-name-face) (_ 'font-lock-variable-name-face)))) (treesit-fontify-with-override From 651927ac3916f601e3ea29281572621044e08fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Tue, 3 Jan 2023 13:49:08 +0100 Subject: [PATCH 2/8] ; Fix function reference in comment in c-ts-mode.el (bug#60514) * lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Fix reference. --- lisp/progmodes/c-ts-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index ffc15e681f7..30a14ecdfae 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -358,7 +358,7 @@ MODE is either `c' or `cpp'." :language mode :feature 'assignment ;; TODO: Recursively highlight identifiers in parenthesized - ;; expressions, see `c-ts-mode--fontify-struct-declarator' for + ;; expressions, see `c-ts-mode--fontify-declarator' for ;; inspiration. '((assignment_expression left: (identifier) @font-lock-variable-name-face) From 6b5831c6964873025dabfb924bd23dfc72138c5d Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 4 Jan 2023 09:57:06 +0200 Subject: [PATCH 3/8] Tree-sitter doc fixes (bug#60524) * doc/lispref/modes.texi (Parser-based Font Lock): Replace :lang with :language. * doc/lispref/parsing.texi (Language Grammar): Replace treesit-load-suffixes with dynamic-library-suffixes. (Retrieving Nodes): Fix function names. (Tree-sitter Major Modes): Fix treesit-ready-p args. Fix pxref to Parser-based Indentation. (Tree-sitter C API): Fix function names. * lisp/treesit.el (treesit--simple-indent-eval): Remove cond BODY duplicated from CONDITION. (treesit): Fix function names. --- .../html-manual/Accessing-Node.html | 2 +- .../html-manual/Language-Definitions.html | 2 +- .../Parser_002dbased-Font-Lock.html | 2 +- .../html-manual/Retrieving-Node.html | 10 +++--- .../html-manual/Tree_002dsitter-C-API.html | 12 +++---- admin/notes/tree-sitter/starter-guide | 2 +- doc/lispref/modes.texi | 2 +- doc/lispref/parsing.texi | 33 +++++++++---------- lisp/treesit.el | 15 ++++----- 9 files changed, 39 insertions(+), 41 deletions(-) diff --git a/admin/notes/tree-sitter/html-manual/Accessing-Node.html b/admin/notes/tree-sitter/html-manual/Accessing-Node.html index 9e7a4b68299..afbbdaa11b5 100644 --- a/admin/notes/tree-sitter/html-manual/Accessing-Node.html +++ b/admin/notes/tree-sitter/html-manual/Accessing-Node.html @@ -187,7 +187,7 @@

-
Function: treesit-child-count node &optional named
+
Function: treesit-node-child-count node &optional named

This function finds the number of children of node. If named is non-nil, it only counts named child (see named node).

diff --git a/admin/notes/tree-sitter/html-manual/Language-Definitions.html b/admin/notes/tree-sitter/html-manual/Language-Definitions.html index 6c17e8c3344..9b1e0021272 100644 --- a/admin/notes/tree-sitter/html-manual/Language-Definitions.html +++ b/admin/notes/tree-sitter/html-manual/Language-Definitions.html @@ -94,7 +94,7 @@

In each of these directories, Emacs looks for a file with file-name -extensions specified by the variable treesit-load-suffixes. +extensions specified by the variable dynamic-library-suffixes.

If Emacs cannot find the library or has problems loading it, Emacs signals the treesit-load-language-error error. The data of diff --git a/admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html b/admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html index 670f235bd20..a3fe6622162 100644 --- a/admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html +++ b/admin/notes/tree-sitter/html-manual/Parser_002dbased-Font-Lock.html @@ -134,7 +134,7 @@ tree-sitter query in either the string, s-expression or compiled form.

For each query, the :keyword/value pairs that -precede it add meta information to it. The :lang keyword +precede it add meta information to it. The :language keyword declares query’s language. The :feature keyword sets the feature name of query. Users can control which features are enabled with font-lock-maximum-decoration and diff --git a/admin/notes/tree-sitter/html-manual/Retrieving-Node.html b/admin/notes/tree-sitter/html-manual/Retrieving-Node.html index 58e87e8df7f..16eeb0b1091 100644 --- a/admin/notes/tree-sitter/html-manual/Retrieving-Node.html +++ b/admin/notes/tree-sitter/html-manual/Retrieving-Node.html @@ -201,13 +201,13 @@

-
Function: treesit-next-sibling node &optional named
+
Function: treesit-node-next-sibling node &optional named

This function finds the next sibling of node. If named is non-nil, it finds the next named sibling.

-
Function: treesit-prev-sibling node &optional named
+
Function: treesit-node-prev-sibling node &optional named

This function finds the previous sibling of node. If named is non-nil, it finds the previous named sibling.

@@ -221,13 +221,13 @@ could have a declarator node and a body node.

-
Function: treesit-child-by-field-name node field-name
+
Function: treesit-node-child-by-field-name node field-name

This function finds the child of node whose field name is field-name, a string.

;; Get the child that has "body" as its field name.
-(treesit-child-by-field-name node "body")
+(treesit-node-child-by-field-name node "body")
   ⇒ #<treesit-node (compound_statement) in 45-89>
 
@@ -237,7 +237,7 @@
-
Function: treesit-first-child-for-pos node pos &optional named
+
Function: treesit-node-first-child-for-pos node pos &optional named

This function finds the first child of node that extends beyond buffer position pos. “Extends beyond” means the end of the child node is greater or equal to pos. This function only looks diff --git a/admin/notes/tree-sitter/html-manual/Tree_002dsitter-C-API.html b/admin/notes/tree-sitter/html-manual/Tree_002dsitter-C-API.html index 0c827b3e755..1d992b828ea 100644 --- a/admin/notes/tree-sitter/html-manual/Tree_002dsitter-C-API.html +++ b/admin/notes/tree-sitter/html-manual/Tree_002dsitter-C-API.html @@ -142,12 +142,12 @@ ts_node_named_child_count treesit-node-child-count ts_node_child_by_field_name treesit-node-by-field-name ts_node_child_by_field_id -ts_node_next_sibling treesit-next-sibling -ts_node_prev_sibling treesit-prev-sibling -ts_node_next_named_sibling treesit-next-sibling -ts_node_prev_named_sibling treesit-prev-sibling -ts_node_first_child_for_byte treesit-first-child-for-pos -ts_node_first_named_child_for_byte treesit-first-child-for-pos +ts_node_next_sibling treesit-node-next-sibling +ts_node_prev_sibling treesit-node-prev-sibling +ts_node_next_named_sibling treesit-node-next-sibling +ts_node_prev_named_sibling treesit-node-prev-sibling +ts_node_first_child_for_byte treesit-node-first-child-for-pos +ts_node_first_named_child_for_byte treesit-node-first-child-for-pos ts_node_descendant_for_byte_range treesit-descendant-for-range ts_node_descendant_for_point_range ts_node_named_descendant_for_byte_range treesit-descendant-for-range diff --git a/admin/notes/tree-sitter/starter-guide b/admin/notes/tree-sitter/starter-guide index a6a4c647f23..606f7891dfa 100644 --- a/admin/notes/tree-sitter/starter-guide +++ b/admin/notes/tree-sitter/starter-guide @@ -238,7 +238,7 @@ Concretely, something like this: ... (cond ;; Tree-sitter. - ((treesit-ready-p 'python-mode 'python) + ((treesit-ready-p 'python) (treesit-parser-create 'python) (setq-local treesit-font-lock-settings python--treesit-settings) (setq-local treesit-font-lock-feature-list diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index dffd6653369..b2dd294ea28 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi @@ -4054,7 +4054,7 @@ tree-sitter query in either the string, s-expression or compiled form. @c FIXME: Cross-ref treesit-font-lock-level to user manual. For each @var{query}, the @var{:keyword}/@var{value} pairs that -precede it add meta information to it. The @code{:lang} keyword +precede it add meta information to it. The @code{:language} keyword declares @var{query}'s language. The @code{:feature} keyword sets the feature name of @var{query}. Users can control which features are enabled with @code{treesit-font-lock-level} and diff --git a/doc/lispref/parsing.texi b/doc/lispref/parsing.texi index 19a22c121de..9635427f940 100644 --- a/doc/lispref/parsing.texi +++ b/doc/lispref/parsing.texi @@ -65,7 +65,6 @@ For example, the C language grammar is represented as the symbol @vindex treesit-extra-load-path @vindex treesit-load-language-error -@vindex treesit-load-suffixes Tree-sitter language grammar are distributed as dynamic libraries. In order to use a language grammar in Emacs, you need to make sure that the dynamic library is installed on the system. Emacs looks for @@ -83,7 +82,7 @@ and finally, in the system's default locations for dynamic libraries. @end itemize In each of these directories, Emacs looks for a file with file-name -extensions specified by the variable @code{treesit-load-suffixes}. +extensions specified by the variable @code{dynamic-library-suffixes}. If Emacs cannot find the library or has problems loading it, Emacs signals the @code{treesit-load-language-error} error. The data of @@ -677,12 +676,12 @@ This function returns all of @var{node}'s children as a list. If @var{named} is non-@code{nil}, it retrieves only named nodes. @end defun -@defun treesit-next-sibling node &optional named +@defun treesit-node-next-sibling node &optional named This function finds the next sibling of @var{node}. If @var{named} is non-@code{nil}, it finds the next named sibling. @end defun -@defun treesit-prev-sibling node &optional named +@defun treesit-node-prev-sibling node &optional named This function finds the previous sibling of @var{node}. If @var{named} is non-@code{nil}, it finds the previous named sibling. @end defun @@ -696,14 +695,14 @@ assign @dfn{field names} to child nodes (@pxref{tree-sitter node field name, field name}). For example, a @code{function_definition} node could have a @code{declarator} node and a @code{body} node. -@defun treesit-child-by-field-name node field-name +@defun treesit-node-child-by-field-name node field-name This function finds the child of @var{node} whose field name is @var{field-name}, a string. @example @group ;; Get the child that has "body" as its field name. -(treesit-child-by-field-name node "body") +(treesit-node-child-by-field-name node "body") @result{} # @end group @end example @@ -713,7 +712,7 @@ This function finds the child of @var{node} whose field name is @cindex nodes, by position @cindex syntax tree nodes, by position -@defun treesit-first-child-for-pos node pos &optional named +@defun treesit-node-first-child-for-pos node pos &optional named This function finds the first child of @var{node} that extends beyond buffer position @var{pos}. ``Extends beyond'' means the end of the child node is greater or equal to @var{pos}. This function only looks @@ -1002,7 +1001,7 @@ Note that @var{n} counts both named and anonymous child. And @var{n} could be negative, e.g., @code{-1} represents the last child. @end defun -@defun treesit-child-count node &optional named +@defun treesit-node-child-count node &optional named This function finds the number of children of @var{node}. If @var{named} is non-@code{nil}, it only counts named children (@pxref{tree-sitter named node, named node}). @@ -1694,7 +1693,7 @@ this pattern: ... (cond ;; Tree-sitter setup. - ((treesit-ready-p 'woomy-mode 'woomy) + ((treesit-ready-p 'woomy) (setq-local treesit-variables ...) (treesit-major-mode-setup)) ;; Non-tree-sitter setup. @@ -1706,7 +1705,7 @@ this pattern: First, the major mode should use @code{treesit-ready-p} to determine whether tree-sitter can be activated in this mode. -@defun treesit-ready-p mode language &optional quiet +@defun treesit-ready-p language &optional quiet This function checks for conditions for activating tree-sitter. It checks whether Emacs was built with tree-sitter, whether the buffer's size is not too large for tree-sitter to handle it, and whether the @@ -1734,7 +1733,7 @@ If @code{treesit-font-lock-settings} (@pxref{Parser-based Font Lock}) is non-@code{nil}, it sets up fontification. @item -If @code{treesit-simple-indent-rules} (@pxref{Parser-based Font Lock}) +If @code{treesit-simple-indent-rules} (@pxref{Parser-based Indentation}) is non-@code{nil}, it sets up indentation. @item @@ -1897,12 +1896,12 @@ ts_node_named_child treesit-node-child ts_node_named_child_count treesit-node-child-count ts_node_child_by_field_name treesit-node-by-field-name ts_node_child_by_field_id -ts_node_next_sibling treesit-next-sibling -ts_node_prev_sibling treesit-prev-sibling -ts_node_next_named_sibling treesit-next-sibling -ts_node_prev_named_sibling treesit-prev-sibling -ts_node_first_child_for_byte treesit-first-child-for-pos -ts_node_first_named_child_for_byte treesit-first-child-for-pos +ts_node_next_sibling treesit-node-next-sibling +ts_node_prev_sibling treesit-node-prev-sibling +ts_node_next_named_sibling treesit-node-next-sibling +ts_node_prev_named_sibling treesit-node-prev-sibling +ts_node_first_child_for_byte treesit-node-first-child-for-pos +ts_node_first_named_child_for_byte treesit-node-first-child-for-pos ts_node_descendant_for_byte_range treesit-descendant-for-range ts_node_descendant_for_point_range ts_node_named_descendant_for_byte_range treesit-descendant-for-range diff --git a/lisp/treesit.el b/lisp/treesit.el index 933d53082f9..ed0aa1c8612 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1288,8 +1288,7 @@ the function." (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)) + ((alist-get exp treesit-simple-indent-presets)) ((functionp exp) exp) ((symbolp exp) (if (null exp) @@ -2914,8 +2913,8 @@ function signals an error." :eg-result-string "#") - (treesit-first-child-for-pos - :no-eval (treesit-first-child-for-pos node 1) + (treesit-node-first-child-for-pos + :no-eval (treesit-node-first-child-for-pos node 1) :eg-result-string "#") (treesit-node-descendant-for-range :no-eval (treesit-node-descendant-for-range node 2 3) @@ -2989,11 +2988,11 @@ function signals an error." :eg-result t) - (treesit-field-name-for-child - :no-eval (treesit-field-name-for-child node) + (treesit-node-field-name-for-child + :no-eval (treesit-node-field-name-for-child node) :eg-result "body") - (treesit-child-count - :no-eval (treesit-child-count node) + (treesit-node-child-count + :no-eval (treesit-node-child-count node) :eg-result 3) From 7eed8e050a9c580cc5770508d70b0139c4ac75a7 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 4 Jan 2023 18:11:31 +0100 Subject: [PATCH 4/8] * lisp/files.el (find-sibling-rules): Fix docstring. --- lisp/files.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c45c3d40a5d..18a046e9bb4 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -7419,9 +7419,9 @@ files, you could say something like: (\"src/emacs/[^/]+/\\\\(.*\\\\)\\\\\\='\" \"src/emacs/.*/\\\\1\\\\\\='\") -In this example, if you're in src/emacs/emacs-27/lisp/abbrev.el, -and you an src/emacs/emacs-28/lisp/abbrev.el file exists, it's -now defined as a sibling." +In this example, if you're in \"src/emacs/emacs-27/lisp/abbrev.el\", +and a \"src/emacs/emacs-28/lisp/abbrev.el\" file exists, it's now +defined as a sibling." :type 'sexp :version "29.1") From c18878ee0a2e16d294bb1b55d233469c604a83ea Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 4 Jan 2023 18:12:02 +0100 Subject: [PATCH 5/8] Fix bug in Tramp multi-hop * lisp/net/tramp.el (tramp-compute-multi-hops): Make check for host name more robust. (Bug#60499) --- lisp/net/tramp.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 61a606c3383..f0b17ef3934 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4694,7 +4694,8 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.") (or ;; The host name is used for the remote shell command. (member - '("%h") (tramp-get-method-parameter item 'tramp-login-args)) + "%h" (tramp-compat-flatten-tree + (tramp-get-method-parameter item 'tramp-login-args))) ;; The host name must match previous hop. (string-match-p previous-host host)) (setq tramp-default-proxies-alist saved-tdpa) From 8d530ca6542b169cb8f0cd3862cc5d24f68935c8 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 4 Jan 2023 19:25:47 +0200 Subject: [PATCH 6/8] ; Fix documentation of y-or-n-p/yes-or-no-p * lisp/subr.el (y-or-n-p): * src/fns.c (Fyes_or_no_p): Doc fix. --- lisp/subr.el | 3 +-- src/fns.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 9087f9a4044..62f72734e14 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3535,8 +3535,7 @@ character. This is not possible when using `read-key', but using Return t if answer is \"y\" and nil if it is \"n\". PROMPT is the string to display to ask the question; `y-or-n-p' -adds \" (y or n) \" to it. It does not need to end in space, but -if it does up to one space will be removed. +adds \"(y or n) \" to it. If you bind the variable `help-form' to a non-nil value while calling this function, then pressing `help-char' diff --git a/src/fns.c b/src/fns.c index 51ef1153fb7..1aaf17914a2 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3168,8 +3168,7 @@ DEFUN ("yes-or-no-p", Fyes_or_no_p, Syes_or_no_p, 1, 1, 0, Return t if answer is yes, and nil if the answer is no. PROMPT is the string to display to ask the question; `yes-or-no-p' -adds \"(yes or no) \" to it. It does not need to end in space, but if -it does up to one space will be removed. +adds \"(yes or no) \" to it. The user must confirm the answer with RET, and can edit it until it has been confirmed. From cef875f6c516e63fd53d5d05410a88f3c7750269 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 4 Jan 2023 20:51:04 +0200 Subject: [PATCH 7/8] ; * etc/NEWS: Instructions for builds without tree-sitter (bug#60559) --- etc/NEWS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 38a8798507a..b45b7de1fcc 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3157,6 +3157,15 @@ files, the new modes based on tree-sitter are for now entirely optional, and you must turn them on manually, or customize 'auto-mode-alist' to turn them on automatically. +Where no major modes previously existed in Emacs for editing the kinds +of files for which Emacs now provides a tree-sitter based mode, Emacs +will now try to enable the tree-sitter mode automatically when you +visit such files, and will display a warning if the tree-sitter +library or the parser grammar library is not available. To prevent +the warnings, either build Emacs with tree-sitter and install the +grammar libraries, or customize 'auto-mode-alist' to specify some +other major mode (or even Fundamental mode) for those kinds of files. + Each major mode based on tree-sitter needs a language grammar library, usually named "libtree-sitter-LANG.so" ("libtree-sitter-LANG.dll" on MS-Windows), where LANG is the corresponding language name. Emacs From 92f753dc19010cf4075db5e6bcedcc5ac0fc2e41 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 4 Jan 2023 20:52:41 +0200 Subject: [PATCH 8/8] ; * etc/NEWS: Fix wording in last change. --- etc/NEWS | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b45b7de1fcc..91e470306c7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -3159,12 +3159,12 @@ optional, and you must turn them on manually, or customize Where no major modes previously existed in Emacs for editing the kinds of files for which Emacs now provides a tree-sitter based mode, Emacs -will now try to enable the tree-sitter mode automatically when you -visit such files, and will display a warning if the tree-sitter -library or the parser grammar library is not available. To prevent -the warnings, either build Emacs with tree-sitter and install the -grammar libraries, or customize 'auto-mode-alist' to specify some -other major mode (or even Fundamental mode) for those kinds of files. +will now try to enable these new modes automatically when you visit +such files, and will display a warning if the tree-sitter library or +the parser grammar library is not available. To prevent the warnings, +either build Emacs with tree-sitter and install the grammar libraries, +or customize 'auto-mode-alist' to specify some other major mode (or +even Fundamental mode) for those kinds of files. Each major mode based on tree-sitter needs a language grammar library, usually named "libtree-sitter-LANG.so" ("libtree-sitter-LANG.dll" on