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: Sat, 15 Jan 2022 13:41:00 -0500 Message-ID: <77116180-4340-4401-AEB2-7E2CEC42DB58@gmail.com> References: <83zgo2770l.fsf@gnu.org> <83zgo15dhp.fsf@gnu.org> <83czkw3uvl.fsf@gnu.org> <170a1c89-7767-0930-f726-f7b2551876b2@yandex.ru> <44f72f97-d1d8-0b4c-73a0-7f077fb1ef26@yandex.ru> <0617E8BF-CC43-4D82-8648-064252F644FD@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_84ED9A54-0174-4201-9681-5A79DA15AE2F" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12994"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel@gnu.org To: Dmitry Gutov , Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 15 19:52:52 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 1n8oAW-0003DC-DW for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jan 2022 19:52:52 +0100 Original-Received: from localhost ([::1]:57294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n8oAU-0004wy-6f for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jan 2022 13:52:50 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:54656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8nzq-0000TE-BO for emacs-devel@gnu.org; Sat, 15 Jan 2022 13:41:52 -0500 Original-Received: from [2607:f8b0:4864:20::82f] (port=46011 helo=mail-qt1-x82f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n8nzl-00072j-Se; Sat, 15 Jan 2022 13:41:49 -0500 Original-Received: by mail-qt1-x82f.google.com with SMTP id x8so8258834qta.12; Sat, 15 Jan 2022 10:41:01 -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=NFQgn3Gqa5R2VJGFnnA5idgurBGL9u1doj7Q3jLyHfk=; b=JvldybN0tzYwt8QnIcpnUOnkW3ouMKGrGpwX5qA14A1AGdv6fwOqrTdCBClRCKlmx7 yMOpJucQRC4jeNd4577Ph2sX9WoPqR6CdKkSiUnf8VoLPh32JUygJj9VZ0qhEOSYWZff v/kMR7hOzax7pPJbb5stAWBmcJo7y7w2RJH4PK8UWaUYt2WOIfsbgG47PBM0G7UIs2ye VpiKuTvbZaPhjERiLyw5t4bZ/3VbyOUqjAQCiPJKnQ8YoTA0nFHr8YxvfrZJxM1jMGRr rYf0qUQ5ERONE6xrat7HouqmwYoblZteOrRVUezt3UGBMQXNfhlJlr5RMxkHkuWKTxHU v0RA== 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=NFQgn3Gqa5R2VJGFnnA5idgurBGL9u1doj7Q3jLyHfk=; b=XTosuPNtiMmXJQiMU+tvdxUdb1u7ovLu3uWXus0dAOBpqOvXaLLoDedgcnWBfaR3jf LOKB+5pEcoLTaWIs4yK08sT6m05FRJ0UWQwv/3OrqydyKtHm/fr42eZuJE2zoVUnLryg iRMDZW3dbo0qNvqXCYDhz1lRatQGwgTeh5cOcIFhmmDU3A9T2UbDil9cFHVmdKNwhSwF WN+VJz1AftKqzNkvUqf9cHt7AT+V3abNLzK8eApUjE+C1mzLucV9Gi8+qvL/+boau5/1 KSDoo1WtJGuM/yso8gxTS/L3xeymLmpR6PHMbsexjW2N5aBXoNgqtsVzhaLXgBb25Rt0 2Q1w== X-Gm-Message-State: AOAM5337wYpSAz8SQj6vvQdunGpOzRrEz3NJ8+eus0cFACuOQG8dE6pF IIzKOVdCD/dtZOLCdQywB1c= X-Google-Smtp-Source: ABdhPJwpvoJffYwhXu4dhM/RaEx40u7l900nElxiZ5svGWQgmTcioxbzil6kol6K5q1C6uUBfUAnMQ== X-Received: by 2002:a05:622a:1a8b:: with SMTP id s11mr2065471qtc.496.1642272060954; Sat, 15 Jan 2022 10:41:00 -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 k8sm6131638qtx.35.2022.01.15.10.41.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jan 2022 10:41:00 -0800 (PST) In-Reply-To: <0617E8BF-CC43-4D82-8648-064252F644FD@gmail.com> X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::82f (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::82f; envelope-from=eskinjp@gmail.com; helo=mail-qt1-x82f.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, PDS_HP_HELO_NORDNS=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:284786 Archived-At: --Apple-Mail=_84ED9A54-0174-4201-9681-5A79DA15AE2F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Apologies- in the event that this patch is satisfactory, the following = includes `xref-find-references-and-replace`. I didn=E2=80=99t realize it = would be a simple replacement.=20= --Apple-Mail=_84ED9A54-0174-4201-9681-5A79DA15AE2F Content-Disposition: attachment; filename=0001-Use-symbol-at-point-as-default-for-query-replace-rea.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Use-symbol-at-point-as-default-for-query-replace-rea.patch" Content-Transfer-Encoding: quoted-printable =46rom=203d575a12107daa09fdb0efc0397ff8c7affa9b1a=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Jon=20Eskin=20=0ADate:=20= Fri,=2014=20Jan=202022=2010:03:30=20-0500=0ASubject:=20[PATCH]=20Use=20= symbol=20at=20point=20as=20default=20for=20query-replace-read-args=0A=0A= *=20lisp/progmodes/project.el=0A(project-query-replace-regexp):=20= Let-bind=0A`read-regexp-defaults-function`=20to=20default=20to=20symbol=20= at=20point.=0A=0A*=20lisp/replace.el=0A(query-replace-read-from):=20= Don't=20format=20prompt=20if=20there's=20a=20symbol=20at=0Apoint,=20= otherwise=20read-regexp=20is=20forced=20to=20use=20the=20wrong=20prompt.=0A= =0A*=20lisp/progmodex/xref.el=20(xref-find-references):=20Let-bind=0A= `read-regexp-defaults-function`=20to=20default=20to=20symbol=20at=20= point=0A---=0A=20lisp/progmodes/project.el=20|=20=208=20+++++---=0A=20= lisp/progmodes/xref.el=20=20=20=20|=20=204=20+++-=0A=20lisp/replace.el=20= =20=20=20=20=20=20=20=20=20=20|=2010=20++++++----=0A=203=20files=20= changed,=2014=20insertions(+),=208=20deletions(-)=0A=0Adiff=20--git=20= a/lisp/progmodes/project.el=20b/lisp/progmodes/project.el=0Aindex=20= c812f28c1b..b44b23554f=20100644=0A---=20a/lisp/progmodes/project.el=0A= +++=20b/lisp/progmodes/project.el=0A@@=20-1072,9=20+1072,11=20@@=20= project-query-replace-regexp=0A=20If=20you=20exit=20the=20= `query-replace',=20you=20can=20later=20continue=20the=0A=20= `query-replace'=20loop=20using=20the=20command=20\\[fileloop-continue]."=0A= =20=20=20(interactive=0A-=20=20=20(pcase-let=20((`(,from=20,to)=0A-=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(query-replace-read-args=20= "Query=20replace=20(regexp)"=20t=20t)))=0A-=20=20=20=20=20(list=20from=20= to)))=0A+=20=20=20(let=20((read-regexp-defaults-function=20(lambda=20()=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (find-tag-default-as-regexp))))=0A+=20=20=20=20(pcase-let=20((`(,from=20= ,to)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (query-replace-read-args=20"Query=20replace=20(regexp)"=20t=20t)))=0A+=20= =20=20=20=20=20(list=20from=20to))))=0A=20=20=20= (fileloop-initialize-replace=0A=20=20=20=20from=20to=20(project-files=20= (project-current=20t))=20'default)=0A=20=20=20(fileloop-continue))=0A= diff=20--git=20a/lisp/progmodes/xref.el=20b/lisp/progmodes/xref.el=0A= index=20a1e976cb1c..5336c319bb=20100644=0A---=20a/lisp/progmodes/xref.el=0A= +++=20b/lisp/progmodes/xref.el=0A@@=20-1481,7=20+1481,9=20@@=20= xref-find-references=0A=20(defun=20xref-find-references-and-replace=20= (from=20to)=0A=20=20=20"Replace=20all=20references=20to=20identifier=20= FROM=20with=20TO."=0A=20=20=20(interactive=0A-=20=20=20(let=20((common=0A= +=20=20=20(let*=20((common=0A+=20=20=20=20=20=20=20=20=20=20= (read-regexp-defaults-function=20(lambda=20()=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(find-tag-default-as-regexp)))=0A=20=20=20=20=20= =20=20=20=20=20=20(query-replace-read-args=20"Query=20replace=20= identifier"=20nil)))=0A=20=20=20=20=20=20(list=20(nth=200=20common)=20= (nth=201=20common))))=0A=20=20=20(require=20'xref)=0Adiff=20--git=20= a/lisp/replace.el=20b/lisp/replace.el=0Aindex=2060e507c642..3d7648611b=20= 100644=0A---=20a/lisp/replace.el=0A+++=20b/lisp/replace.el=0A@@=20-208,7=20= +208,8=20@@=20query-replace-read-from=0A=20wants=20to=20replace=20FROM=20= with=20TO."=0A=20=20=20(if=20query-replace-interactive=0A=20=20=20=20=20=20= =20(car=20(if=20regexp-flag=20regexp-search-ring=20search-ring))=0A-=20=20= =20=20(let*=20((history-add-new-input=20nil)=0A+=20=20=20=20(let*=20= ((sym-at-point=20(symbol-at-point))=0A+=20=20=20=20=20=20=20=20=20=20=20= (history-add-new-input=20nil)=0A=20=09=20=20=20(separator-string=0A=20=09= =20=20=20=20(when=20query-replace-from-to-separator=0A=20=09=20=20=20=20=20= =20;;=20Check=20if=20the=20first=20non-whitespace=20char=20is=20= displayable=0A@@=20-234,8=20+235,9=20@@=20query-replace-read-from=0A=20=09= =20=20=20=20=20(symbol-value=20query-replace-from-history-variable)))=0A=20= =09=20=20=20(minibuffer-allow-text-properties=20t)=20;=20separator=20= uses=20text-properties=0A=20=09=20=20=20(prompt=0A-=09=20=20=20=20(cond=20= ((and=20query-replace-defaults=20separator)=0A-=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20(format-prompt=20prompt=20(car=20= minibuffer-history)))=0A+=09=20=20=20=20(cond=20(sym-at-point=20prompt)=20= ;;=20if=20there's=20a=20symbol=20at=20point,=20let=20read-regexp=20= format=20the=20prompt=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20((and=20query-replace-defaults=20separator)=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(format-prompt=20prompt=20(car=20= minibuffer-history)))=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(query-replace-defaults=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20(format-prompt=0A=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20prompt=20(format=20"%s=20->=20%s"=0A@@=20-255,7=20= +257,7=20@@=20query-replace-read-from=0A=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (append=20'((separator=20.=20t)=20(face=20.=20t))=0A=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20text-property-default-nonsticky)))=0A=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(if=20regexp-flag=0A-=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(read-regexp=20prompt=20= nil=20'minibuffer-history)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20(read-regexp=20prompt=20sym-at-point=20= 'minibuffer-history)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(read-from-minibuffer=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20prompt=20nil=20nil=20nil=20nil=0A=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(query-replace-read-from-suggestions)=20= t)))))=0A--=20=0A2.34.1=0A=0A= --Apple-Mail=_84ED9A54-0174-4201-9681-5A79DA15AE2F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Jan 15, 2022, at 4:55 AM, Jon Eskin wrote: >=20 >=20 >=20 >> On Jan 14, 2022, at 3:28 PM, Dmitry Gutov wrote: >>=20 >> On 14.01.2022 12:26, Jon Eskin wrote: >>>> So Jon, if you fancy writing a patch in this area, you can try = implementing what Juri suggested: >>>>=20 >>>> let-bind read-regexp-defaults-function around the call >>>> of query-replace-read-args, and use a symbol at point as the = default. >>>>=20 >>>> That can apply to both project-query-replace-regexp and = xref-find-references-and-replace. >>> On it! I might take a little while but I'll check in if I get stuck. >>=20 >> Yeah, don't hesitate to ask questions if/when you have any. >=20 >=20 > Hey all, >=20 > I took a stab at the implementation Juri described for = `project-query-replace-regexp` and I was able to get the correct = behavior, but I wanted to check in and see if it needs improvements = before looking at `xref-find-references-and-replace.` >=20 > 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. >=20 > Another issue is that hardcoded logic in `read-regexp`: >=20 > '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).' >=20 > 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.=20 >=20 > 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. >=20 > Let me know what you think. >=20 > <0001-Use-symbol-at-point-as-default-for-query-replace-rea.patch> --Apple-Mail=_84ED9A54-0174-4201-9681-5A79DA15AE2F--