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: Juri Linkov
Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project
Date: Sun, 16 Jan 2022 19:55:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

> Apologies- in the event that this patch is satisfactory, the following
> includes `xref-find-references-and-replace`.  I didn’t realize it
> would be a simple replacement.
> [...]
> @@ -1072,9 +1072,11 @@ project-query-replace-regexp
> -   (pcase-let ((`(,from ,to)
> -                (query-replace-read-args "Query replace (regexp)" t t)))
> -     (list from to)))
> +   (let ((read-regexp-defaults-function (lambda ()
> +                                          (find-tag-default-as-regexp))))
> +    (pcase-let ((`(,from ,to)
> +                 (query-replace-read-args "Query replace (regexp)" t t)))
> +      (list from to))))

The problem was in let-binding 'read-regexp-defaults-function' to a lambda.
It should work when using 'find-tag-default-as-regexp' as a symbol:

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index c812f28c1b..c58c05bc71 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 ((read-regexp-defaults-function '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..640c8745db 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* ((read-regexp-defaults-function 'find-tag-default-as-regexp)
+          (common
+           (query-replace-read-args "Query replace identifier" nil)))
      (list (nth 0 common) (nth 1 common))))
   (require 'xref)
   (with-current-buffer
diff --git a/lisp/replace.el b/lisp/replace.el
index 60e507c642..9c7680a563 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -234,7 +234,8 @@ 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 regexp-flag read-regexp-defaults-function) prompt)
+                  ((and query-replace-defaults separator)
                    (format-prompt prompt (car minibuffer-history)))
                   (query-replace-defaults
                    (format-prompt
@@ -255,7 +256,10 @@ 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 read-regexp-defaults-function (string-remove-suffix 
": " prompt))
+                     read-regexp-defaults-function
+                     'minibuffer-history)
                   (read-from-minibuffer
                    prompt nil nil nil nil
                    (query-replace-read-from-suggestions) t)))))

reply via email to

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