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: Jon Eskin
Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project
Date: Tue, 11 Jan 2022 04:50:13 -0500

That's a great function, I love seeing all the results in an xref buffer. I previously explored adding a command to the xref similar to 'xref-query-replace-in-results' that pre-populates the FROM field with the item you were searching for when you executed 'project-find-regexp'.

Unfortunately I couldn't find a way to make that work- I couldn't find a function or variable referring to the item being cross referenced in the context of an xref buffer. If I understand correctly, xref only seems to be concerned with logic to deal with xref results that it is provided. With that assumption I couldn't really think of a way to architect a good solution without modifying xref in a way that violates [what I understood to be] its intent. I'm definitely open to suggestions on how to make that work, though.

On Tue, Jan 11, 2022 at 2:51 AM Manuel Uberti <manuel.uberti@inventati.org> wrote:
On 11/01/22 08:45, Jon Eskin wrote:
> Attached is a small patch adding command 'project-query-replace-at-point' to
> project.el. The command is designed to improve the ergonomics of making a
> project wide text replacement of a symbol at point.
>
> Currently, if you want to make a project wide replacement of a symbol using
> project.el, the best options I've found are:
>
> - Mark the symbol you wish to replace
> - Save symbol to kill ring with 'kill-ring-save'
> - Enter command 'project-query-replace-regexp'
> - Paste in the symbol, taking care to quote regex if necessary, and hit return
> - Enter the replacement string and hit return
>
> or
>
> - Mark the symbol you wish to replace
> - Save symbol to kill ring with 'kill-ring-save'
> - Place cursor on symbol and enter command 'project-find-regexp'
> - Hit return at the next prompt to accept the default prompt
> - Enter command 'xref-query-replace-in-results'
> - Enter the replacement string and hit return
>
> 'project-query-replace-at-point' regex-quotes the symbol at point and then calls
> into the fileloop-initialize-replace function used by the existing
> project-query-replace-regexp command.
>
> Replacing a symbol with 'project-query-replace-at-point' occurs as follows:
>
> - Place cursor on symbol and enter command 'project-query-replace-at-point'
> - Enter the replacement string and hit return
>
> Let me know what you guys think. I haven't contributed before so please let me
> know if I'm doing anything incorrectly.
>

I usually use the `project-find-regexp` approach you described, but I agree a
simpler solution would be nicer.

--
Manuel Uberti
www.manueluberti.eu


--
Jon Eskin
(301) 675-6663

reply via email to

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