From 101455cb8534d07518871c0287e4861e09f22a32 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 22 Jul 2023 08:36:08 +0300 Subject: [PATCH 1/7] ; * lisp/subr.el (ignore, always): Doc fixes. (Bug#64776) --- lisp/subr.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index 43cf4572fe2..872c701dbe7 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -399,16 +399,16 @@ PREFIX is a string, and defaults to \"g\"." (make-symbol (format "%s%d" (or prefix "g") num)))) (defun ignore (&rest _arguments) - "Do nothing and return nil. -This function accepts any number of ARGUMENTS, but ignores them. + "Ignore ARGUMENTS, do nothing, and return nil. +This function accepts any number of arguments in ARGUMENTS. Also see `always'." (declare (completion ignore)) (interactive) nil) (defun always (&rest _arguments) - "Do nothing and return t. -This function accepts any number of ARGUMENTS, but ignores them. + "Ignore ARGUMENTS, do nothing, and return t. +This function accepts any number of arguments in ARGUMENTS. Also see `ignore'." t) From 42a99627948986bbaa7bb872bea19c164085c9cb Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 22 Jul 2023 09:34:15 +0300 Subject: [PATCH 2/7] ; Improve documentation of 'last-command-event' * doc/lispref/text.texi (Commands for Insertion): * doc/lispref/commands.texi (Command Loop Info): * src/cmds.c (syms_of_cmds) : Improve the documentation of 'last-command-event' and 'post-self-insert-hook'. --- doc/lispref/commands.texi | 4 +++- doc/lispref/text.texi | 19 +++++++++++-------- src/cmds.c | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index cd1745614eb..f84afcf52bd 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi @@ -1132,7 +1132,9 @@ up a menu. It is also used internally by @code{y-or-n-p} This variable is set to the last input event that was read by the command loop as part of a command. The principal use of this variable is in @code{self-insert-command}, which uses it to decide which -character to insert. +character to insert, and in @code{post-self-insert-hook} +(@pxref{Commands for Insertion}), which uses it to access the +character that was just inserted. @example @group diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 82e79e2bc14..0b0328d0252 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -551,14 +551,17 @@ character has close parenthesis syntax (@pxref{Blinking}). @vindex self-insert-uses-region-functions The final thing this command does is to run the hook @code{post-self-insert-hook}. You could use this to automatically -reindent text as it is typed, for example. If any function on this -hook needs to act on the region (@pxref{The Region}), it should make -sure Delete Selection mode (@pxref{Using Region, Delete Selection, , -emacs, The GNU Emacs Manual}) doesn't delete the region before -@code{post-self-insert-hook} functions are invoked. The way to do so -is to add a function that returns @code{nil} to -@code{self-insert-uses-region-functions}, a special hook that tells -Delete Selection mode it should not delete the region. +reindent text as it is typed, for example. The functions on this hook +can use @code{last-command-event} (@pxref{Command Loop Info}) to +access the character just inserted. + +If any function on this hook needs to act on the region (@pxref{The +Region}), it should make sure Delete Selection mode (@pxref{Using +Region, Delete Selection, , emacs, The GNU Emacs Manual}) doesn't +delete the region before @code{post-self-insert-hook} functions are +invoked. The way to do so is to add a function that returns +@code{nil} to @code{self-insert-uses-region-functions}, a special hook +that tells Delete Selection mode it should not delete the region. Do not try substituting your own definition of @code{self-insert-command} for the standard one. The editor command diff --git a/src/cmds.c b/src/cmds.c index 15caa4a6972..840d5881b59 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -518,7 +518,8 @@ syms_of_cmds (void) DEFVAR_LISP ("post-self-insert-hook", Vpost_self_insert_hook, doc: /* Hook run at the end of `self-insert-command'. -This is run after inserting the character. */); +This is run after inserting a character. +The hook can access the inserted character via `last-command-event'. */); Vpost_self_insert_hook = Qnil; defsubr (&Sforward_char); From d149a4dc428b108232789594132a80d1ab27a33e Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 22 Jul 2023 11:02:04 +0300 Subject: [PATCH 3/7] ; Improve documentation of automatic addition to minibuffer history * doc/lispref/minibuf.texi (Minibuffer History) (Minibuffer Commands, Text from Minibuffer) (Minibuffer Completion): Document the behavior of 'M-n' and "future history" when the value(s) in DEFAULT is/are exhausted. (Bug#64656) --- doc/lispref/minibuf.texi | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 7fbdd9eb6e2..5ef061891b9 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -156,7 +156,11 @@ reads the text and returns the resulting Lisp object, unevaluated. The argument @var{default} specifies default values to make available through the history commands. It should be a string, a list of strings, or @code{nil}. The string or strings become the minibuffer's -``future history'', available to the user with @kbd{M-n}. +``future history'', available to the user with @kbd{M-n}. In +addition, if the call provides completion (e.g., via the @var{keymap} +argument), the completion candidates are added to the ``future +history'' when the values in @var{default} are exhausted by @kbd{M-n}; +see @ref{Minibuffer History,, minibuffer-default-add-function}. If @var{read} is non-@code{nil}, then @var{default} is also used as the input to @code{read}, if the user enters empty input. @@ -648,10 +652,25 @@ buffer local, then each buffer will have its own input history list. Both @code{read-from-minibuffer} and @code{completing-read} add new elements to the history list automatically, and provide commands to -allow the user to reuse items on the list. The only thing your program -needs to do to use a history list is to initialize it and to pass its -name to the input functions when you wish. But it is safe to modify the -list by hand when the minibuffer input functions are not using it. +allow the user to reuse items on the list (@pxref{Minibuffer +Commands}). The only thing your program needs to do to use a history +list is to initialize it and to pass its name to the input functions +when you wish. But it is safe to modify the list by hand when the +minibuffer input functions are not using it. + +@vindex minibuffer-default-add-function + By default, when @kbd{M-n} (@code{next-history-element}, +@pxref{Minibuffer Commands,,next-history-element}) reaches the end of +the list of default values provided by the command which initiated +reading input from the minibuffer, @kbd{M-n} adds all of the +completion candidates, as specified by +@code{minibuffer-completion-table} (@pxref{Completion Commands}), to +the list of defaults, so that all those candidates are available as +``future history''. Your program can control that via the variable +@code{minibuffer-default-add-function}: if its value is not a +function, this automatic addition is disabled, and you can also set +this variable to your own function which adds only some candidates, or +some other values, to the ``future history''. Emacs functions that add a new element to a history list can also delete old elements if the list gets too long. The variable @@ -1161,7 +1180,10 @@ However, empty input is always permitted, regardless of the value of first element of @var{default}, if it is a list; @code{""}, if @var{default} is @code{nil}; or @var{default}. The string or strings in @var{default} are also available to the user through the history -commands. +commands (@pxref{Minibuffer Commands}). In addition, the completion +candidates are added to the ``future history'' when the values in +@var{default} are exhausted by @kbd{M-n}; see @ref{Minibuffer +History,, minibuffer-default-add-function}. The function @code{completing-read} uses @code{minibuffer-local-completion-map} as the keymap if @@ -2543,7 +2565,11 @@ minibuffer. The argument @var{nabs} specifies the absolute history position in descending order, where 0 means the current element and a positive number @var{n} means the @var{n}th previous element. NABS being a negative number -@var{n} means the @var{n}th entry of ``future -history.'' +history''. When this function reaches the end of the default values +provided by @code{read-from-minibuffer} (@pxref{Text from Minibuffer}) +and @code{completing-read} (@pxref{Minibuffer Completion}), it adds +the completion candidates to ``future history'', see @ref{Minibuffer +History,, minibuffer-default-add-function}. @end deffn @node Minibuffer Windows From 12ab82d3b358fa72dc4705cb6ff7ce0523968200 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 22 Jul 2023 15:45:40 +0300 Subject: [PATCH 4/7] ; Fix customization form of 'bookmark-watch-bookmark-file' * lisp/bookmark.el (bookmark-watch-bookmark-file): Fix the doc string and the customization type. (Bug#64790) --- lisp/bookmark.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 026257ff758..10ff2f5ebbf 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -89,13 +89,15 @@ To specify the file in which to save them, modify the variable :type 'file) (defcustom bookmark-watch-bookmark-file t - "If non-nil watch the default bookmark file. + "If non-nil reload the default bookmark file if it was changed. If this file has changed on disk since it was last loaded, query the user whether to load it again. If the value is `silent' reload without querying. This file defaults to `bookmark-default-file'. But during an Emacs session, `bookmark-load' and `bookmark-save' can redefine the current default file." :version "27.1" - :type 'boolean + :type '(choice (const :tag "Suggest to reload bookmark file if changed" t) + (const :tag "Silently reload bookmark file if changed" silent) + (const :tag "Ignore changes of bookmark file" nil)) :group 'bookmark) (defcustom bookmark-version-control 'nospecial From 235561a2ccc03f50652cd942ab7906fe6178ef83 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo Date: Sat, 22 Jul 2023 13:37:54 +0200 Subject: [PATCH 5/7] Update TSX support due to upstream changes (bug#64647) A recent change in tree-sitter-typescript grammar support for TSX (commit b893426), changed two things: 1. renamed nested_identifier to member_expression 2. removed jsx_fragment, jsx_text is used instead * lisp/progmodes/typescript-ts-mode.el (tsx-ts-mode--indent-compatibility-b893426): Indent helper function to handle different tree-sitter-typescript version. * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--indent-rules): use the new function to handle both jsx_fragment and jsx_text. * lisp/progmodes/typescript-ts-mode.el (tsx-ts-mode--font-lock-compatibility-bb1f97b): Font lock helper function for handle different tree-sitter-typescript version. * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode--font-lock-settings): Use the new function to handle both nested_identifier and member_expression. --- lisp/progmodes/typescript-ts-mode.el | 78 ++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 5df34de0472..173ec52f209 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -75,6 +75,18 @@ table) "Syntax table for `typescript-ts-mode'.") +(defun tsx-ts-mode--indent-compatibility-b893426 () + "Indent rules helper, to handle different releases of tree-sitter-tsx. +Check if a node type is available, then return the right indent rules." + ;; handle commit b893426 + (condition-case nil + (progn (treesit-query-capture 'tsx '((jsx_fragment) @capture)) + `(((match "<" "jsx_fragment") parent 0) + ((parent-is "jsx_fragment") parent typescript-ts-mode-indent-offset))) + (error + `(((match "<" "jsx_text") parent 0) + ((parent-is "jsx_text") parent typescript-ts-mode-indent-offset))))) + (defun typescript-ts-mode--indent-rules (language) "Rules used for indentation. Argument LANGUAGE is either `typescript' or `tsx'." @@ -110,16 +122,15 @@ Argument LANGUAGE is either `typescript' or `tsx'." ((parent-is "binary_expression") parent-bol typescript-ts-mode-indent-offset) ,@(when (eq language 'tsx) - `(((match "<" "jsx_fragment") parent 0) - ((parent-is "jsx_fragment") parent typescript-ts-mode-indent-offset) - ((node-is "jsx_closing_element") parent 0) - ((match "jsx_element" "statement") parent typescript-ts-mode-indent-offset) - ((parent-is "jsx_element") parent typescript-ts-mode-indent-offset) - ((parent-is "jsx_text") parent-bol typescript-ts-mode-indent-offset) - ((parent-is "jsx_opening_element") parent typescript-ts-mode-indent-offset) - ((parent-is "jsx_expression") parent-bol typescript-ts-mode-indent-offset) - ((match "/" "jsx_self_closing_element") parent 0) - ((parent-is "jsx_self_closing_element") parent typescript-ts-mode-indent-offset))) + (append (tsx-ts-mode--indent-compatibility-b893426) + `(((node-is "jsx_closing_element") parent 0) + ((match "jsx_element" "statement") parent typescript-ts-mode-indent-offset) + ((parent-is "jsx_element") parent typescript-ts-mode-indent-offset) + ((parent-is "jsx_text") parent-bol typescript-ts-mode-indent-offset) + ((parent-is "jsx_opening_element") parent typescript-ts-mode-indent-offset) + ((parent-is "jsx_expression") parent-bol typescript-ts-mode-indent-offset) + ((match "/" "jsx_self_closing_element") parent 0) + ((parent-is "jsx_self_closing_element") parent typescript-ts-mode-indent-offset)))) ;; FIXME(Theo): This no-node catch-all should be removed. When is it needed? (no-node parent-bol 0)))) @@ -142,6 +153,38 @@ Argument LANGUAGE is either `typescript' or `tsx'." "&&" "||" "!" "?.") "TypeScript operators for tree-sitter font-locking.") +(defun tsx-ts-mode--font-lock-compatibility-bb1f97b () + "Font lock rules helper, to handle different releases of tree-sitter-tsx. +Check if a node type is available, then return the right font lock rules." + ;; handle commit bb1f97b + ;; Warning: treesitter-query-capture says both node types are valid, + ;; but then raises an error if the wrong node type is used. So it is + ;; important to check with the new node type (member_expression) + (condition-case nil + (progn (treesit-query-capture 'tsx '((member_expression) @capture)) + '((jsx_opening_element + [(member_expression (identifier)) (identifier)] + @typescript-ts-jsx-tag-face) + + (jsx_closing_element + [(member_expression (identifier)) (identifier)] + @typescript-ts-jsx-tag-face) + + (jsx_self_closing_element + [(member_expression (identifier)) (identifier)] + @typescript-ts-jsx-tag-face))) + (error '((jsx_opening_element + [(nested_identifier (identifier)) (identifier)] + @typescript-ts-jsx-tag-face) + + (jsx_closing_element + [(nested_identifier (identifier)) (identifier)] + @typescript-ts-jsx-tag-face) + + (jsx_self_closing_element + [(nested_identifier (identifier)) (identifier)] + @typescript-ts-jsx-tag-face))))) + (defun typescript-ts-mode--font-lock-settings (language) "Tree-sitter font-lock settings. Argument LANGUAGE is either `typescript' or `tsx'." @@ -293,19 +336,8 @@ Argument LANGUAGE is either `typescript' or `tsx'." :language language :feature 'jsx - `((jsx_opening_element - [(nested_identifier (identifier)) (identifier)] - @typescript-ts-jsx-tag-face) - - (jsx_closing_element - [(nested_identifier (identifier)) (identifier)] - @typescript-ts-jsx-tag-face) - - (jsx_self_closing_element - [(nested_identifier (identifier)) (identifier)] - @typescript-ts-jsx-tag-face) - - (jsx_attribute (property_identifier) @typescript-ts-jsx-attribute-face)) + (append (tsx-ts-mode--font-lock-compatibility-bb1f97b) + `((jsx_attribute (property_identifier) @typescript-ts-jsx-attribute-face))) :language language :feature 'number From 2215298d90bb04968803e7323af0cc3d819ae301 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo Date: Sat, 22 Jul 2023 13:38:48 +0200 Subject: [PATCH 6/7] Update JSX support due to upstream changes (bug#64647) A recent change in tree-sitter-javascript grammar support for JSX (commit bb1f97b), changed two things: 1. renamed nested_identifier to member_expression 2. removed jsx_fragment, jsx_text is used instead * lisp/progmodes/js.el (js-jsx--treesit-indent-compatibility-bb1f97b): Indent helper function to handle different tree-sitter-javascript version. * lisp/progmodes/js.el (js--treesit-indent-rules): Use the new function to handle both jsx_fragment and jsx_text. * lisp/progmodes/js.el (js-jsx--treesit-font-lock-compatibility-bb1f97b): Font lock helper function for handle different tree-sitter-javascript version. * lisp/progmodes/js.el (js--treesit-font-lock-settings): Use the new function to handle both nested_identifier and member_expression. --- lisp/progmodes/js.el | 61 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index a05bd758dbc..70048e5d26c 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3427,6 +3427,18 @@ This function is intended for use in `after-change-functions'." ;;; Tree sitter integration +(defun js-jsx--treesit-indent-compatibility-bb1f97b () + "Indent rules helper, to handle different releases of tree-sitter-javascript. +Check if a node type is available, then return the right indent rules." + ;; handle commit bb1f97b + (condition-case nil + (progn (treesit-query-capture 'javascript '((jsx_fragment) @capture)) + `(((match "<" "jsx_fragment") parent 0) + ((parent-is "jsx_fragment") parent js-indent-level))) + (error + `(((match "<" "jsx_text") parent 0) + ((parent-is "jsx_text") parent js-indent-level))))) + (defvar js--treesit-indent-rules (let ((switch-case (rx "switch_" (or "case" "default")))) `((javascript @@ -3462,8 +3474,7 @@ This function is intended for use in `after-change-functions'." ((parent-is "statement_block") parent-bol js-indent-level) ;; JSX - ((match "<" "jsx_fragment") parent 0) - ((parent-is "jsx_fragment") parent js-indent-level) + (js-jsx--treesit-indent-compatibility-bb1f97b) ((node-is "jsx_closing_element") parent 0) ((match "jsx_element" "statement") parent js-indent-level) ((parent-is "jsx_element") parent js-indent-level) @@ -3490,6 +3501,35 @@ This function is intended for use in `after-change-functions'." "&&" "||" "!") "JavaScript operators for tree-sitter font-locking.") +(defun js-jsx--treesit-font-lock-compatibility-bb1f97b () + "Font lock rules helper, to handle different releases of tree-sitter-javascript. +Check if a node type is available, then return the right font lock rules." + ;; handle commit bb1f97b + (condition-case nil + (progn (treesit-query-capture 'javascript '((member_expression) @capture)) + '((jsx_opening_element + [(member_expression (identifier)) (identifier)] + @font-lock-function-call-face) + + (jsx_closing_element + [(member_expression (identifier)) (identifier)] + @font-lock-function-call-face) + + (jsx_self_closing_element + [(member_expression (identifier)) (identifier)] + @font-lock-function-call-face))) + (error '((jsx_opening_element + [(nested_identifier (identifier)) (identifier)] + @font-lock-function-call-face) + + (jsx_closing_element + [(nested_identifier (identifier)) (identifier)] + @font-lock-function-call-face) + + (jsx_self_closing_element + [(nested_identifier (identifier)) (identifier)] + @font-lock-function-call-face))))) + (defvar js--treesit-font-lock-settings (treesit-font-lock-rules @@ -3599,21 +3639,8 @@ This function is intended for use in `after-change-functions'." :language 'javascript :feature 'jsx - '((jsx_opening_element - [(nested_identifier (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_closing_element - [(nested_identifier (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_self_closing_element - [(nested_identifier (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_attribute - (property_identifier) - @font-lock-constant-face)) + (append (js-jsx--treesit-font-lock-compatibility-bb1f97b) + '((jsx_attribute (property_identifier) @font-lock-constant-face))) :language 'javascript :feature 'number From ee20b50dfeded512ecdc784421f8bbe97161d729 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 23 Jul 2023 08:16:14 +0300 Subject: [PATCH 7/7] ; * lisp/progmodes/typescript-ts-mode.el (treesit-query-capture): Declare. --- lisp/progmodes/typescript-ts-mode.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 173ec52f209..ae0a80aea86 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -33,6 +33,7 @@ (require 'c-ts-common) ; For comment indent and filling. (declare-function treesit-parser-create "treesit.c") +(declare-function treesit-query-capture "treesit.c") (defcustom typescript-ts-mode-indent-offset 2 "Number of spaces for each indentation step in `typescript-ts-mode'."