unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#58177: Return value of perform-replace and its documentation string
@ 2022-09-29 18:02 Ruy Exel
  2022-09-30 13:25 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Ruy Exel @ 2022-09-29 18:02 UTC (permalink / raw)
  To: 58177

This bug report was suggested to me by Emacs Stack Exchange user
"db48x" in a reply to my question "How to count number of replacements
made by "query-replace?"
(https://emacs.stackexchange.com/questions/73860/how-to-count-number-of-replacements-made-by-query-replace)
and corroborated by user "dalanicolai".

Primarily this is related to the documentation string of the emacs
function "perform-replace" which says:

"This function returns nil if and only if there were no matches to
make, or the user didn’t cancel the call."

Since the return value IS NIL when the user DID cancel the call, the
documentation string appears to be incorrect.

On the other hand, it seems to me that the actual behavior, namely
returning nil upon cancellation, is not the ideal behavior.

Recall that the return value of perform-replace, when not interrupted
by the user, is a list giving information regarding the replacements
tried, including those actually made.

In case the user decides to reply "yes" to the first few queries, and
then decides to reply with "q", canceling the command, the return
value of nil cannot be used to determine which replacements were made,
which in turn might be of interest in certain circumstances, as in the
one described in my Emacs Stack Exchange question mentioned above.

Thus, I would like to add a feature request to this bug report, namely
that the return value of perform-replace, in case it is canceled by
the user, be changed from nil to some other value reflecting the
replacements considered before the cancel request.

Yours,
Ruy Exel





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58177: Return value of perform-replace and its documentation string
  2022-09-29 18:02 bug#58177: Return value of perform-replace and its documentation string Ruy Exel
@ 2022-09-30 13:25 ` Lars Ingebrigtsen
  2022-10-01 19:13   ` Juri Linkov
  0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-30 13:25 UTC (permalink / raw)
  To: Ruy Exel; +Cc: 58177

Ruy Exel <ruyexel@gmail.com> writes:

> Thus, I would like to add a feature request to this bug report, namely
> that the return value of perform-replace, in case it is canceled by
> the user, be changed from nil to some other value reflecting the
> replacements considered before the cancel request.

Yes, I think that makes sense.  An alternate value would be to return a
list of all considered replacements, but marking all the ones after the
`q' the same way as the `n's are marked.  I.e., `q' as a way of saying
"skip all the rest", which it is, in a way.

Anybody have any opinions here?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58177: Return value of perform-replace and its documentation string
  2022-09-30 13:25 ` Lars Ingebrigtsen
@ 2022-10-01 19:13   ` Juri Linkov
  2022-10-02 12:09     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Juri Linkov @ 2022-10-01 19:13 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 58177, Ruy Exel

>> Thus, I would like to add a feature request to this bug report, namely
>> that the return value of perform-replace, in case it is canceled by
>> the user, be changed from nil to some other value reflecting the
>> replacements considered before the cancel request.
>
> Yes, I think that makes sense.  An alternate value would be to return a
> list of all considered replacements, but marking all the ones after the
> `q' the same way as the `n's are marked.  I.e., `q' as a way of saying
> "skip all the rest", which it is, in a way.
>
> Anybody have any opinions here?

Unfortunately, nil value is used to decide whether to continue
to the next file in multi-buffer replacements.  Examples of such code
including but not limited to: xref--query-replace-1 that contains

(defun xref--query-replace-1 (from to iter)
  (let* ((continue t)
    ...
    (while (and continue ...
      ...
      (setq continue
            (perform-replace from to t t nil nil multi-query-replace-map)))
      ...

and

(defun fileloop-continue ()
    ...
    (while
      ...
      (save-restriction
        (widen)
        (funcall fileloop--operate-function)))
      (setq file-finished t))))

etc.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#58177: Return value of perform-replace and its documentation string
  2022-10-01 19:13   ` Juri Linkov
@ 2022-10-02 12:09     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2022-10-02 12:09 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 58177, Ruy Exel

Juri Linkov <juri@linkov.net> writes:

> Unfortunately, nil value is used to decide whether to continue
> to the next file in multi-buffer replacements.

Hm, right.  We could add Yet Another Parameter to change the return
value, but I'm not sure whether that would be valuable (especially since
there's already 11 parameter).

So I guess the only thing to do here is to fix the doc string, and I've
now done that in Emacs 29.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-02 12:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-29 18:02 bug#58177: Return value of perform-replace and its documentation string Ruy Exel
2022-09-30 13:25 ` Lars Ingebrigtsen
2022-10-01 19:13   ` Juri Linkov
2022-10-02 12:09     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).