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: Dmitry Gutov
Subject: Re: [Patch] Add project.el command to replace symbol at point throughout project
Date: Mon, 17 Jan 2022 03:15:54 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

On 17.01.2022 02:19, Dmitry Gutov wrote:
As far as I'm concerned, it might as well use read-regexp-defaults-function. But the implementation is made more complicated by the fact that read-regexp and read-from-minibuffer treat their PROMPT and DEFAULTS arguments differently.

E.g. the latter won't return DEFAULT-VALUE on empty input and won't format the prompt. If I use read-string instead, it uses the default value instead of empty input, but does not format the prompt still.

So, this seems to work, but I wonder if it's the best we can do:

diff --git a/lisp/replace.el b/lisp/replace.el
index 60e507c642..9847e4ebea 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -234,7 +234,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 regexp-flag read-regexp-defaults-function) prompt)
+                  (read-regexp-defaults-function
+ (format-prompt prompt (funcall read-regexp-defaults-function)))
+                  ((and query-replace-defaults separator)
                    (format-prompt prompt (car minibuffer-history)))
                   (query-replace-defaults
                    (format-prompt
@@ -255,10 +258,17 @@ query-replace-read-from
                                 (append '((separator . t) (face . t))
                                         text-property-default-nonsticky)))
                 (if regexp-flag
-                    (read-regexp prompt nil 'minibuffer-history)
-                  (read-from-minibuffer
-                   prompt nil nil nil nil
-                   (query-replace-read-from-suggestions) t)))))
+                    (read-regexp
+ (if read-regexp-defaults-function (string-remove-suffix ": " prompt))
+                     read-regexp-defaults-function
+                     'minibuffer-history)
+                  (read-string
+                   prompt
+                   nil nil
+                   (if read-regexp-defaults-function
+                       (funcall read-regexp-defaults-function)
+                     (query-replace-read-from-suggestions))
+                   t)))))
            (to))
       (if (and (zerop (length from)) query-replace-defaults)
          (cons (caar query-replace-defaults)



reply via email to

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