From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jon Eskin Newsgroups: gmane.emacs.devel Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project Date: Wed, 12 Jan 2022 03:03:07 -0500 Message-ID: References: <88e2f28a-925b-551c-b85b-0af400997dc5@yandex.ru> Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_FBA3E966-0260-4CEA-A035-76BE22712677" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5883"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jan 12 09:08:12 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n7Yfz-0001Lp-Uy for ged-emacs-devel@m.gmane-mx.org; Wed, 12 Jan 2022 09:08:12 +0100 Original-Received: from localhost ([::1]:53058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7Yfy-0008C8-Bu for ged-emacs-devel@m.gmane-mx.org; Wed, 12 Jan 2022 03:08:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7YbC-00064y-Rv for emacs-devel@gnu.org; Wed, 12 Jan 2022 03:03:14 -0500 Original-Received: from [2607:f8b0:4864:20::f2b] (port=33644 helo=mail-qv1-xf2b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7YbA-0006eP-UQ for emacs-devel@gnu.org; Wed, 12 Jan 2022 03:03:14 -0500 Original-Received: by mail-qv1-xf2b.google.com with SMTP id t7so2147050qvj.0 for ; Wed, 12 Jan 2022 00:03:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=xovZO7eTzFdhgDNUrRzk+7Dt9v9c4IqjPCepq5NdvNc=; b=b7n4b4uunhUWJoGtI6HB+leq0dgOGq/SnIPiuqUcLfa7yKkGXvWIIcjSIvWq0bOGUB XEkmgRpAv1mbZWE71LvDKN6SpyvBa9VDbNXUgvNpgbG2XwR34hbcYDcl2kR24qHAJWtF i+6cIOYKefhdbZx2pQQMBQvFASCT69wDXrfr/LQjL8Zd5omHJU9coc3+oYLe2iOw0pRH 9nsCh9WB6pwGF9x5XJ9BA7Gu75kMmAXHLYM9JPidW63i3VBcif9Nb89V6r2YT7NmfNx9 8+EMCYZWk6HyAi5NINWxA/To/NITubbRK+Rwrhof9McSUoVOTqJoPrETWB2UHqIRKyU1 vnVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=xovZO7eTzFdhgDNUrRzk+7Dt9v9c4IqjPCepq5NdvNc=; b=tYQSFV3FMSkW8/fnTDsoCAw5lIJIq1GapJIDc6p7y4l4TLSXq9JSrKHrxArDKSC5Rq XaqxrKwbmG4MZau70zRroYrAzWfzQoQo17JiMf/RyRILpHWj4Zqc/5EJY7+RTD6OWCIN lbjuq0rWP2AE4qVwQWXa27H/HXZ7Thvh2Pt60o+7nw9p4LDVUqmIk9+xLmm/lUXqoGJE lUGJUJE8pXll6Bcly2pa241CaJ9mO5Hf2rl6TVZpovhhoEN9UvPL9lxa2cMVwr3RbvwL 2rVHZe9xTcPiGAwpe7pbqXjkI8AbP/HEcFeeWGDBtybQIJnmpamvzJD/QJIx3NbCeuCw eypQ== X-Gm-Message-State: AOAM530icaV8YPFycsdolk3V+98dwss7GA7tjB4suypCG8WrnCx9vkjC W7LsO4DIxlVkLPpxmWKNmf+SHKuJnY7vXw== X-Google-Smtp-Source: ABdhPJym4xhZbgrRn18KQfA2PDhfVIsbL40nn36bNm61H4xe2MdKqAr80awflpTDnKsAqCn4yJbDEw== X-Received: by 2002:a05:6214:5287:: with SMTP id kj7mr6944568qvb.38.1641974589087; Wed, 12 Jan 2022 00:03:09 -0800 (PST) Original-Received: from smtpclient.apple (pool-108-31-85-19.washdc.fios.verizon.net. [108.31.85.19]) by smtp.gmail.com with ESMTPSA id r20sm9038345qkp.21.2022.01.12.00.03.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jan 2022 00:03:07 -0800 (PST) In-Reply-To: <88e2f28a-925b-551c-b85b-0af400997dc5@yandex.ru> X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f2b (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2b; envelope-from=eskinjp@gmail.com; helo=mail-qv1-xf2b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:284642 Archived-At: --Apple-Mail=_FBA3E966-0260-4CEA-A035-76BE22712677 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello! :) > On Jan 11, 2022, at 10:42 PM, Dmitry Gutov wrote: >=20 > Hi! >=20 > On 11.01.2022 09: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: >=20 >> or >> - Mark the symbol you wish to replace >> - Save symbol to kill ring with 'kill-ring-save' >=20 > You don't need these two steps, do you? Just do the rest, and it = should work. >=20 >> - 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 >=20 > I agree it could use some more optimization still. >=20 >> '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. Sorry, yes, those two steps are not needed. My brain crossed a few = wires. >=20 > If we're trying to improve project-query-replace-regexp, why not make = it use the symbol at point by default? >=20 I thought about the option of using symbol at point by default, but I = noticed that the command currently uses the history variable. I wondered = if some people were relying on its current behavior in a way that I = didn=E2=80=99t anticipate (especially since I=E2=80=99m pretty new to = all this). If so, it would be an annoying change to have to worry about = whether the cursor is on a symbol when using a command you previously = relied on. I wanted to try to put forth something possibly useful = without breaking stuff. > You would use the same command, but would be able to press RET to have = the default regexp (symbol at point) used as FROM. I don't have a patch = yet, but it might be something that all callers of = query-replace-read-args might benefit from. Since I think I can understand what you=E2=80=99re suggesting, I would = be happy to make an attempt at a patch to modify the callers of = query-replace-read-args to default to a regexp quoted symbol-at-point. = But no worries if you would rather have experienced eyes on it. >=20 > And you can actually do this right now: >=20 > - Enter command 'project-query-replace-regexp' > - Press M-n, having the symbol at point picked up as FROM, hit return > - Enter the replacement string and hit return This is awesome! Did not know about that behavior, thank you for = sharing! --Apple-Mail=_FBA3E966-0260-4CEA-A035-76BE22712677 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hello! :)

On Jan 11, 2022, at 10:42 PM, = Dmitry Gutov <dgutov@yandex.ru> wrote:

Hi!
On 11.01.2022 09: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:

or
- Mark = the symbol you wish to replace
- Save symbol to kill ring = with 'kill-ring-save'

You = don't need these two steps, do you? Just do the rest, and it should = work.

- = 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

I agree it could use some more = optimization still.

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

Sorry, yes, those two steps are not needed. My = brain crossed a few wires.


If we're = trying to improve project-query-replace-regexp, why not make it use the = symbol at point by default?


I thought about the option of using symbol = at point by default, but I noticed that the command currently uses the = history variable. I wondered if some people were relying on its current = behavior in a way that I didn=E2=80=99t anticipate (especially since = I=E2=80=99m pretty new to all this). If so, it would be an annoying = change to have to worry about whether the cursor is on a symbol when = using a command you previously relied on. I wanted to try to put = forth something possibly useful without breaking = stuff.

You would use the same command, but would be = able to press RET to have the default regexp (symbol at point) used as = FROM. I don't have a patch yet, but it might be something that all = callers of query-replace-read-args might benefit from.

Since = I think I can understand what you=E2=80=99re suggesting, I would be = happy to make an attempt at a patch to modify the callers of = query-replace-read-args to default to a regexp quoted symbol-at-point. = But no worries if you would rather have experienced eyes on = it.


And you can = actually do this right now:

- Enter command = 'project-query-replace-regexp'
- Press M-n, having the = symbol at point picked up as FROM, hit return
- Enter the = replacement string and hit return

This is awesome! Did not know about that behavior, thank you = for sharing!

= --Apple-Mail=_FBA3E966-0260-4CEA-A035-76BE22712677--