diff options
| author | Eli Zaretskii | 2021-04-17 11:24:04 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2021-04-17 11:24:04 +0300 |
| commit | 1789dcdb359bbac371ebabbd07643eaaea67c4f7 (patch) | |
| tree | 89d97ca0cd0e678eb2e8c63bf97ebdaa87232ff8 | |
| parent | eedad01b4bd8db2e8af087d8810c99c8f00a86af (diff) | |
| download | emacs-1789dcdb359bbac371ebabbd07643eaaea67c4f7.tar.gz emacs-1789dcdb359bbac371ebabbd07643eaaea67c4f7.zip | |
Improve documentation of 'map-y-or-n-p'
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p): Doc fix. (Bug#47833)
* doc/lispref/minibuf.texi (Multiple Queries): Fix the wording in
the description of 'map-y-or-n-p'.
| -rw-r--r-- | doc/lispref/minibuf.texi | 89 | ||||
| -rw-r--r-- | lisp/emacs-lisp/map-ynp.el | 86 |
2 files changed, 104 insertions, 71 deletions
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 726b786905f..f16212abdca 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi | |||
| @@ -2128,9 +2128,10 @@ This function asks the user a series of questions, reading a | |||
| 2128 | single-character answer in the echo area for each one. | 2128 | single-character answer in the echo area for each one. |
| 2129 | 2129 | ||
| 2130 | The value of @var{list} specifies the objects to ask questions about. | 2130 | The value of @var{list} specifies the objects to ask questions about. |
| 2131 | It should be either a list of objects or a generator function. If it is | 2131 | It should be either a list of objects or a generator function. If it |
| 2132 | a function, it should expect no arguments, and should return either the | 2132 | is a function, it will be called with no arguments, and should return |
| 2133 | next object to ask about, or @code{nil}, meaning to stop asking questions. | 2133 | either the next object to ask about, or @code{nil}, meaning to stop |
| 2134 | asking questions. | ||
| 2134 | 2135 | ||
| 2135 | The argument @var{prompter} specifies how to ask each question. If | 2136 | The argument @var{prompter} specifies how to ask each question. If |
| 2136 | @var{prompter} is a string, the question text is computed like this: | 2137 | @var{prompter} is a string, the question text is computed like this: |
| @@ -2141,19 +2142,20 @@ The argument @var{prompter} specifies how to ask each question. If | |||
| 2141 | 2142 | ||
| 2142 | @noindent | 2143 | @noindent |
| 2143 | where @var{object} is the next object to ask about (as obtained from | 2144 | where @var{object} is the next object to ask about (as obtained from |
| 2144 | @var{list}). | 2145 | @var{list}). @xref{Formatting Strings}, for more information about |
| 2146 | @code{format}. | ||
| 2145 | 2147 | ||
| 2146 | If not a string, @var{prompter} should be a function of one argument | 2148 | If @var{prompter} is not a string, it should be a function of one |
| 2147 | (the next object to ask about) and should return the question text. If | 2149 | argument (the object to ask about) and should return the question text |
| 2148 | the value is a string, that is the question to ask the user. The | 2150 | for that object. If the value @var{prompter} returns is a string, |
| 2149 | function can also return @code{t}, meaning do act on this object (and | 2151 | that is the question to ask the user. The function can also return |
| 2150 | don't ask the user), or @code{nil}, meaning ignore this object (and don't | 2152 | @code{t}, meaning to act on this object without asking the user, or |
| 2151 | ask the user). | 2153 | @code{nil}, which means to silently ignore this object. |
| 2152 | 2154 | ||
| 2153 | The argument @var{actor} says how to act on the answers that the user | 2155 | The argument @var{actor} says how to act on the objects for which the |
| 2154 | gives. It should be a function of one argument, and it is called with | 2156 | user answers yes. It should be a function of one argument, and will |
| 2155 | each object that the user says yes for. Its argument is always an | 2157 | be called with each object from @var{LIST} for which the user answers |
| 2156 | object obtained from @var{list}. | 2158 | yes. |
| 2157 | 2159 | ||
| 2158 | If the argument @var{help} is given, it should be a list of this form: | 2160 | If the argument @var{help} is given, it should be a list of this form: |
| 2159 | 2161 | ||
| @@ -2163,34 +2165,49 @@ If the argument @var{help} is given, it should be a list of this form: | |||
| 2163 | 2165 | ||
| 2164 | @noindent | 2166 | @noindent |
| 2165 | where @var{singular} is a string containing a singular noun that | 2167 | where @var{singular} is a string containing a singular noun that |
| 2166 | describes the objects conceptually being acted on, @var{plural} is the | 2168 | describes a single object to be acted on, @var{plural} is the |
| 2167 | corresponding plural noun, and @var{action} is a transitive verb | 2169 | corresponding plural noun, and @var{action} is a transitive verb |
| 2168 | describing what @var{actor} does. | 2170 | describing what @var{actor} does with the objects. |
| 2169 | 2171 | ||
| 2170 | If you don't specify @var{help}, the default is @code{("object" | 2172 | If you don't specify @var{help}, it defaults to the list |
| 2171 | "objects" "act on")}. | 2173 | @w{@code{("object" "objects" "act on")}}. |
| 2172 | 2174 | ||
| 2173 | Each time a question is asked, the user may enter @kbd{y}, @kbd{Y}, or | 2175 | Each time a question is asked, the user can answer as follows: |
| 2174 | @key{SPC} to act on that object; @kbd{n}, @kbd{N}, or @key{DEL} to skip | 2176 | |
| 2175 | that object; @kbd{!} to act on all following objects; @key{ESC} or | 2177 | @table @asis |
| 2176 | @kbd{q} to exit (skip all following objects); @kbd{.} (period) to act on | 2178 | @item @kbd{y}, @kbd{Y}, or @kbd{@key{SPC}} |
| 2177 | the current object and then exit; or @kbd{C-h} to get help. These are | 2179 | act on the object |
| 2178 | the same answers that @code{query-replace} accepts. The keymap | 2180 | @item @kbd{n}, @kbd{N}, or @kbd{@key{DEL}} |
| 2179 | @code{query-replace-map} defines their meaning for @code{map-y-or-n-p} | 2181 | skip the object |
| 2180 | as well as for @code{query-replace}; see @ref{Search and Replace}. | 2182 | @item @kbd{!} |
| 2183 | act on all the following objects | ||
| 2184 | @item @kbd{@key{ESC}} or @kbd{q} | ||
| 2185 | exit (skip all following objects) | ||
| 2186 | @item @kbd{.} (period) | ||
| 2187 | act on the object and then exit | ||
| 2188 | @item @kbd{C-h} | ||
| 2189 | get help | ||
| 2190 | @end table | ||
| 2191 | |||
| 2192 | @noindent | ||
| 2193 | These are the same answers that @code{query-replace} accepts. The | ||
| 2194 | keymap @code{query-replace-map} defines their meaning for | ||
| 2195 | @code{map-y-or-n-p} as well as for @code{query-replace}; see | ||
| 2196 | @ref{Search and Replace}. | ||
| 2181 | 2197 | ||
| 2182 | You can use @var{action-alist} to specify additional possible answers | 2198 | You can use @var{action-alist} to specify additional possible answers |
| 2183 | and what they mean. It is an alist of elements of the form | 2199 | and what they mean. If provided, @var{action-alist} should be an |
| 2184 | @code{(@var{char} @var{function} @var{help})}, each of which defines one | 2200 | alist whose elements are of the form @w{@code{(@var{char} |
| 2185 | additional answer. In this element, @var{char} is a character (the | 2201 | @var{function} @var{help})}}. Each of the alist elements defines one |
| 2202 | additional answer. In each element, @var{char} is a character (the | ||
| 2186 | answer); @var{function} is a function of one argument (an object from | 2203 | answer); @var{function} is a function of one argument (an object from |
| 2187 | @var{list}); @var{help} is a string. | 2204 | @var{list}); and @var{help} is a string. When the user responds with |
| 2188 | 2205 | @var{char}, @code{map-y-or-n-p} calls @var{function}. If it returns | |
| 2189 | When the user responds with @var{char}, @code{map-y-or-n-p} calls | 2206 | non-@code{nil}, the object is considered to have been acted upon, and |
| 2190 | @var{function}. If it returns non-@code{nil}, the object is considered | 2207 | @code{map-y-or-n-p} advances to the next object in @var{list}. If it |
| 2191 | acted upon, and @code{map-y-or-n-p} advances to the next object in | 2208 | returns @code{nil}, the prompt is repeated for the same object. If |
| 2192 | @var{list}. If it returns @code{nil}, the prompt is repeated for the | 2209 | the user requests help, the text in @var{help} is used to describe |
| 2193 | same object. | 2210 | these additional answers. |
| 2194 | 2211 | ||
| 2195 | Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while | 2212 | Normally, @code{map-y-or-n-p} binds @code{cursor-in-echo-area} while |
| 2196 | prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it | 2213 | prompting. But if @var{no-cursor-in-echo-area} is non-@code{nil}, it |
diff --git a/lisp/emacs-lisp/map-ynp.el b/lisp/emacs-lisp/map-ynp.el index 14112a1c147..8d3a42b09f6 100644 --- a/lisp/emacs-lisp/map-ynp.el +++ b/lisp/emacs-lisp/map-ynp.el | |||
| @@ -38,46 +38,62 @@ | |||
| 38 | 38 | ||
| 39 | (defun map-y-or-n-p (prompter actor list &optional help action-alist | 39 | (defun map-y-or-n-p (prompter actor list &optional help action-alist |
| 40 | no-cursor-in-echo-area) | 40 | no-cursor-in-echo-area) |
| 41 | "Ask a series of boolean questions. | 41 | "Ask a boolean question per PROMPTER for each object in LIST, then call ACTOR. |
| 42 | Takes args PROMPTER ACTOR LIST, and optional args HELP and ACTION-ALIST. | ||
| 43 | 42 | ||
| 44 | LIST is a list of objects, or a function of no arguments to return the next | 43 | LIST is a list of objects, or a function of no arguments to return the next |
| 45 | object or nil. | 44 | object; when it returns nil, the list of objects is considered exhausted. |
| 46 | 45 | ||
| 47 | If PROMPTER is a string, the prompt is \(format PROMPTER OBJECT). If not | 46 | If PROMPTER is a string, it should be a format string to be used to format |
| 48 | a string, PROMPTER is a function of one arg (an object from LIST), which | 47 | the question as \(format PROMPTER OBJECT). |
| 49 | returns a string to be used as the prompt for that object. If the return | 48 | If PROMPTER is not a string, it should be a function of one argument, an |
| 50 | value is not a string, it may be nil to ignore the object or non-nil to act | 49 | object from LIST, which returns a string to be used as the question for |
| 51 | on the object without asking the user. | 50 | that object. If the function's return value is not a string, it may be |
| 52 | 51 | nil to ignore the object, or non-nil to act on the object with ACTOR | |
| 53 | ACTOR is a function of one arg (an object from LIST), | 52 | without asking the user. |
| 54 | which gets called with each object that the user answers `yes' for. | 53 | |
| 55 | 54 | ACTOR is a function of one argument, an object from LIST, | |
| 56 | If HELP is given, it is a list (OBJECT OBJECTS ACTION), | 55 | which gets called with each object for which the user answers `yes' |
| 57 | where OBJECT is a string giving the singular noun for an elt of LIST; | 56 | to the question presented by PROMPTER. |
| 58 | OBJECTS is the plural noun for elts of LIST, and ACTION is a transitive | 57 | |
| 59 | verb describing ACTOR. The default is \(\"object\" \"objects\" \"act on\"). | 58 | The user's answers to the questions may be one of the following: |
| 60 | 59 | ||
| 61 | At the prompts, the user may enter y, Y, or SPC to act on that object; | 60 | - y, Y, or SPC to act on that object; |
| 62 | n, N, or DEL to skip that object; ! to act on all following objects; | 61 | - n, N, or DEL to skip that object; |
| 63 | ESC or q to exit (skip all following objects); . (period) to act on the | 62 | - ! to act on all following objects; |
| 64 | current object and then exit; or \\[help-command] to get help. | 63 | - ESC or q to exit (skip all following objects); |
| 65 | 64 | - . (period) to act on the current object and then exit; or | |
| 66 | If ACTION-ALIST is given, it is an alist (KEY FUNCTION HELP) of extra keys | 65 | - \\[help-command] to get help. |
| 67 | that will be accepted. KEY is a character; FUNCTION is a function of one | 66 | |
| 68 | arg (an object from LIST); HELP is a string. When the user hits KEY, | 67 | HELP provides information for displaying help when the user |
| 69 | FUNCTION is called. If it returns non-nil, the object is considered | 68 | types \\[help-command]. If HELP is given, it should be a list of |
| 70 | \"acted upon\", and the next object from LIST is processed. If it returns | 69 | the form (OBJECT OBJECTS ACTION), where OBJECT is a string giving |
| 71 | nil, the prompt is repeated for the same object. | 70 | the singular noun describing an element of LIST; OBJECTS is the |
| 72 | 71 | plural noun describing several elements of LIST, and ACTION is a | |
| 73 | Final optional argument NO-CURSOR-IN-ECHO-AREA non-nil says not to set | 72 | transitive verb describing action by ACTOR on one or more elements |
| 74 | `cursor-in-echo-area' while prompting. | 73 | of LIST. If HELP is omitted or nil, it defaults |
| 74 | to \(\"object\" \"objects\" \"act on\"). | ||
| 75 | |||
| 76 | If ACTION-ALIST is given, it is an alist specifying additional keys | ||
| 77 | that will be accepted as an answer to the questions. Each element | ||
| 78 | of the alist has the form (KEY FUNCTION HELP), where KEY is a character; | ||
| 79 | FUNCTION is a function of one argument (an object from LIST); and HELP | ||
| 80 | is a string. When the user presses KEY, FUNCTION is called; if it | ||
| 81 | returns non-nil, the object is considered to have been \"acted upon\", | ||
| 82 | and `map-y-or-n-p' proceeeds to the next object from LIST. If | ||
| 83 | FUNCTION returns nil, the prompt is re-issued for the same object: this | ||
| 84 | comes in handy if FUNCTION produces some display that will allow the | ||
| 85 | user to make an intelligent decision whether the object in question | ||
| 86 | should be acted upon. If the user types \\[help-command], the string | ||
| 87 | given by HELP is used to describe the effect of KEY. | ||
| 88 | |||
| 89 | Optional argument NO-CURSOR-IN-ECHO-AREA, if non-nil, means not to set | ||
| 90 | `cursor-in-echo-area' while prompting with the questions. | ||
| 75 | 91 | ||
| 76 | This function uses `query-replace-map' to define the standard responses, | 92 | This function uses `query-replace-map' to define the standard responses, |
| 77 | but not all of the responses which `query-replace' understands | 93 | but only some of the responses which `query-replace' understands |
| 78 | are meaningful here. | 94 | are meaningful here, as described above. |
| 79 | 95 | ||
| 80 | Returns the number of actions taken." | 96 | The function's value is the number of actions taken." |
| 81 | (let* ((actions 0) | 97 | (let* ((actions 0) |
| 82 | (msg (current-message)) | 98 | (msg (current-message)) |
| 83 | user-keys mouse-event map prompt char elt def | 99 | user-keys mouse-event map prompt char elt def |