[Top][All Lists]

[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: Dmitry Gutov
Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project
Date: Mon, 17 Jan 2022 02:19:50 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

On 16.01.2022 19:58, Juri Linkov wrote:
This is needed to handle `read-regexp` in `occur-read-primary-args`
that uses the symbol `regexp-history-last` by default.


read-regexp is called from query-replace-read-from.

Binding read-regexp-defaults-function doesn't seem to work because its use
is for some reason predicated on (and defaults (symbolp defaults))
evaluating to non-nil.

And 'read-regexp' is called with nil second argument.

The customizable user option 'read-regexp-defaults-function' was created
for the following problem: by default, 'occur' uses the last history item
as the default value, so 'read-regexp-defaults-function' could be
customized to get a tag at point as the default value of 'occur'.

Exactly the same situation is with 'query-replace-read-from':
by default, it uses the last history item, so changing the value of
'read-regexp-defaults-function' should also affect the query-replace
like in the patch that I sent to Jon.

The patch works for project-query-replace-regexp but not for xref-find-references-and-replace, which still doesn't suggest the symbol at point as FROM (BTW, in the final version this function should probably use #'find-tag-default rather than 'find-tag-default-as-regexp).

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)
                     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.

It doesn't have to be the same. project-query-replace-regexp could bind
read-regexp-defaults-function, and xref-find-references-and-replace could
bind something else. But that variable still needs to be created.

xref-find-references-and-replace calls query-replace-read-args
with a non-regexp flag, so I have no idea what new variable
could be created for read-from-minibuffer.

I don't really have a preference as to how the implementation is organized, as long as it all works.

As far as I'm concerned, it might as well use read-regexp-defaults-function. But the implementation is made more complicated by the fact that read-regexp and read-from-minibuffer treat their PROMPT and DEFAULTS arguments differently.

E.g. the latter won't return DEFAULT-VALUE on empty input and won't format the prompt. If I use read-string instead, it uses the default value instead of empty input, but does not format the prompt still.

It already uses
'query-replace-read-from-suggestions' where the top value
could be the default.

That would affect all callers of query-replace-read-from, wouldn't it? I'm not sure, but a conservative approach (which we often take here) would be to try to avoid that.

reply via email to

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