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: Mon, 31 Jan 2022 20:25:29 +0200 Organization: LINKOV.NET Message-ID: <86sft3kbja.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> <86pmos3no7.fsf@mail.linkov.net> <86czkr36ll.fsf@mail.linkov.net> <921c0b69-7bac-b78a-54d8-987165331661@yandex.ru> <0b8d87f8-e6db-9902-bd89-d81864d626d6@yandex.ru> <861r16235x.fsf@mail.linkov.net> <829a1d78-c07e-4bb8-e3bd-07263271fc30@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35315"; 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: Jon Eskin , Eli Zaretskii , emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jan 31 19:54:11 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 1nEboZ-00092y-Aa for ged-emacs-devel@m.gmane-mx.org; Mon, 31 Jan 2022 19:54:11 +0100 Original-Received: from localhost ([::1]:44932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEboW-0004cu-PR for ged-emacs-devel@m.gmane-mx.org; Mon, 31 Jan 2022 13:54:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEbZg-0000te-SP for emacs-devel@gnu.org; Mon, 31 Jan 2022 13:38:52 -0500 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:60903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEbZY-00055M-Nu; Mon, 31 Jan 2022 13:38:47 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 955EB200009; Mon, 31 Jan 2022 18:38:23 +0000 (UTC) In-Reply-To: <829a1d78-c07e-4bb8-e3bd-07263271fc30@yandex.ru> (Dmitry Gutov's message of "Fri, 21 Jan 2022 05:06:06 +0200") Received-SPF: pass client-ip=217.70.178.232; envelope-from=juri@linkov.net; helo=relay12.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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:285690 Archived-At: --=-=-= Content-Type: text/plain >>> + (read-string >>> + prompt >>> + nil nil >>> + (if read-regexp-defaults-function >>> + (funcall read-regexp-defaults-function) >>> + (query-replace-read-from-suggestions)) >> Isn't it too strange that read-string uses the read-regexp function? >> Maybe better to add a new variable read-string-defaults-function. > > That sounds fine to me. > >> Then it could provide an option to use 'car' of >> query-replace-read-from-suggestions, and allow a custom function. > > ...less confident about this one, because read-regexp-defaults-function > doesn't do anything like that, right? It might be nice if the options > mirrored each other. > > But if it's too much of a bother right now, I could just add two > hand-written prompts with default to xref-find-references-and-replace, > without the fancy "arrow". It's not like the replacements history is going > to see too much use for this command. > > In the meantime, I think you should install your latest patch now (without > the xref.el part, since it doesn't work yet). After thinking more about this, I can't find a possible use for read-string-defaults-function, because every call of read-string provides own default value. Also using read-regexp-defaults-function in query-replace-read-from is not the right thing either - when the users already customized it for e.g. occur, it would be too unexpected when it will use a tag at point instead of from->to pairs in query-replace. Since query-replace is a very special command, the most uncontroversial thing to do for a conservative approach would be to add two specific variables (that later could be turned into options when needed): --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=query-replace-read-from-default.patch diff --git a/lisp/replace.el b/lisp/replace.el index 689a3f77ed..91cd2b3420 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -186,6 +186,12 @@ query-replace--split-string length) length))))) +(defvar query-replace-read-from-default nil + "Function to get default non-regexp value for `query-replace-read-from'.") + +(defvar query-replace-read-from-regexp-default nil + "Function to get default regexp value for `query-replace-read-from'.") + (defun query-replace-read-from-suggestions () "Return a list of standard suggestions for `query-replace-read-from'. By default, the list includes the active region, the identifier @@ -234,7 +240,10 @@ query-replace-read-from (symbol-value query-replace-from-history-variable))) (minibuffer-allow-text-properties t) ; separator uses text-properties (prompt - (cond ((and query-replace-defaults separator) + (cond ((and query-replace-read-from-regexp-default regexp-flag) prompt) + ((and query-replace-read-from-default (not regexp-flag)) + (format-prompt prompt (funcall query-replace-read-from-default))) + ((and query-replace-defaults separator) (format-prompt prompt (car minibuffer-history))) (query-replace-defaults (format-prompt @@ -255,10 +264,19 @@ query-replace-read-from (append '((separator . t) (face . t)) text-property-default-nonsticky))) (if regexp-flag - (read-regexp prompt nil 'minibuffer-history) + (read-regexp + (if query-replace-read-from-regexp-default + (string-remove-suffix ": " prompt) + prompt) + query-replace-read-from-regexp-default + 'minibuffer-history) (read-from-minibuffer prompt nil nil nil nil - (query-replace-read-from-suggestions) t))))) + (if query-replace-read-from-default + (cons (funcall query-replace-read-from-default) + (query-replace-read-from-suggestions)) + (query-replace-read-from-suggestions)) + t))))) (to)) (if (and (zerop (length from)) query-replace-defaults) (cons (caar query-replace-defaults) --=-=-= Content-Type: text/plain Then you could use these variables like this: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=query-replace-read-from-regexp-default.patch diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index c812f28c1b..f606a25575 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1072,9 +1072,10 @@ project-query-replace-regexp If you exit the `query-replace', you can later continue the `query-replace' loop using the command \\[fileloop-continue]." (interactive - (pcase-let ((`(,from ,to) - (query-replace-read-args "Query replace (regexp)" t t))) - (list from to))) + (let ((query-replace-read-from-regexp-default 'find-tag-default-as-regexp)) + (pcase-let ((`(,from ,to) + (query-replace-read-args "Query replace (regexp)" t t))) + (list from to)))) (fileloop-initialize-replace from to (project-files (project-current t)) 'default) (fileloop-continue)) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 37e2159782..4efa652084 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -1481,8 +1481,9 @@ xref-find-references (defun xref-find-references-and-replace (from to) "Replace all references to identifier FROM with TO." (interactive - (let ((common - (query-replace-read-args "Query replace identifier" nil))) + (let* ((query-replace-read-from-default 'find-tag-default) + (common + (query-replace-read-args "Query replace identifier" nil))) (list (nth 0 common) (nth 1 common)))) (require 'xref) (with-current-buffer --=-=-=--