emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Patch] Add project.el command to replace symbol at point throughout


From: Juri Linkov
Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project
Date: Sat, 15 Jan 2022 20:30:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

> When I first let-bound `read-regexp-defaults-function` around the call to
> `query-replace-read-args`, it didn't work- it looks like `read-regexp`
> needs to be passed a symbol for its `DEFAULTS` parameter or it ignores
> `read-regexp-default-function`. I passed in the symbol at point to
> `DEFAULTS` which works- if I understand correctly the value of any I pass
> in doesn't end up making a difference as long as it's a symbol. I wasn't
> sure what the reason was for that behavior, but I didn't want to mess with
> stuff I didn't understand.

This is needed to handle `read-regexp` in `occur-read-primary-args`
that uses the symbol `regexp-history-last` by default.

> Another issue is that hardcoded logic in `read-regexp`:
>
> 'If PROMPT ends in \":\" (followed by
> optional whitespace), use it as-is.  Otherwise, add \": \" to the end,
> possibly preceded by the default result (see below).'
>
> The PROMPT passed into read-regexp does end in a ":" due to it being
> formatted by a call to `format-prompt` in `query-replace-read-from`. As
> a result, when the symbol is at point, `read-regexp` display the prompt
> with the last replacement from history. To address this, I added a cond
> case where the formatting takes place and omit the formatting step when
> there is a symbol at point so that `read-regex` will correctly format the
> prompt with the symbol at point.
>
> The result is that a call to `project-query-replace-regexp` will take
> the symbol at point as the default when available, otherwise it will
> use its previous behavior of defaulting to the last replacement
> available in history.
>
> Let me know what you think.

Before finishing this implementation, please answer one question.
`query-replace-read-from` uses two minibuffer-reading functions:

                (if regexp-flag
                    (read-regexp prompt sym-at-point 'minibuffer-history)
                  (read-from-minibuffer
                   prompt nil nil nil nil
                   (query-replace-read-from-suggestions) t))

Do you think the same default with the symbol at point
should be used for the non-regexp case with read-from-minibuffer as well?
If yes, then we need a different solution that works for both cases.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]