Merge from origin/emacs-29

ee20b50dfe ; * lisp/progmodes/typescript-ts-mode.el (treesit-query-c...
2215298d90 Update JSX support due to upstream changes (bug#64647)
235561a2cc Update TSX support due to upstream changes (bug#64647)
12ab82d3b3 ; Fix customization form of 'bookmark-watch-bookmark-file'
d149a4dc42 ; Improve documentation of automatic addition to minibuff...
42a9962794 ; Improve documentation of 'last-command-event'
101455cb85 ; * lisp/subr.el (ignore, always): Doc fixes.  (Bug#64776)
This commit is contained in:
Eli Zaretskii 2023-07-31 11:11:21 -04:00
commit 555cb8f7b1
8 changed files with 157 additions and 63 deletions

View file

@ -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

View file

@ -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
@ -2551,7 +2573,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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'."
@ -75,6 +76,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 +123,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 +154,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 +337,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

View file

@ -423,8 +423,8 @@ 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'."
;; Not declared `side-effect-free' because we don't want calls to it
;; elided; see `byte-compile-ignore'.
@ -433,8 +433,8 @@ Also see `always'."
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'."
(declare (pure t) (side-effect-free error-free))
t)

View file

@ -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);