From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project Date: Sat, 15 Jan 2022 20:30:44 +0200 Organization: LINKOV.NET Message-ID: <86pmos3no7.fsf@mail.linkov.net> 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 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34009"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Eli Zaretskii , emacs-devel@gnu.org, Dmitry Gutov To: Jon Eskin Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 15 19:48:44 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 1n8o6W-0008k9-MF for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jan 2022 19:48:44 +0100 Original-Received: from localhost ([::1]:55184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n8o6V-0003L4-Ef for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Jan 2022 13:48:43 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:54584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8nzh-0000Se-VK for emacs-devel@gnu.org; Sat, 15 Jan 2022 13:41:42 -0500 Original-Received: from [2001:4b98:dc4:8::222] (port=50041 helo=relay2-d.mail.gandi.net) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8nzD-00072b-FN; Sat, 15 Jan 2022 13:41:36 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 6564040002; Sat, 15 Jan 2022 18:40:50 +0000 (UTC) In-Reply-To: <0617E8BF-CC43-4D82-8648-064252F644FD@gmail.com> (Jon Eskin's message of "Sat, 15 Jan 2022 04:55:52 -0500") X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:4b98:dc4:8::222 (failed) Received-SPF: pass client-ip=2001:4b98:dc4:8::222; envelope-from=juri@linkov.net; helo=relay2-d.mail.gandi.net X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, 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:284785 Archived-At: > 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.