bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#41692: 26.3; Enhancement request, `query-replace': let user use text


From: Juri Linkov
Subject: bug#41692: 26.3; Enhancement request, `query-replace': let user use text at point as default
Date: Fri, 12 Jun 2020 01:58:36 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> Currently `query-replace-read-from' has:
>>   (if regexp-flag
>>       (read-regexp prompt nil 'minibuffer-history)
>>     (read-from-minibuffer
>>       prompt nil nil nil nil (car search-ring) t))
>> 
>> It's easy to extend `read-regexp' with more options,
>> but what to do for non-regexp case?
>> 
>> Maybe to try to use `read-string' and extend it with
>> more M-n options like in `read-regexp'.
>
> I don't understand the question.  `read-from-minibuffer'
> accepts a list of default values.  Or maybe I don't
> understand what you mean by "more options".

Right, let's add more default values to `read-from-minibuffer':

diff --git a/lisp/replace.el b/lisp/replace.el
index 69092c16f9..a5a5200df7 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -227,7 +227,16 @@ query-replace-read-from
                 (if regexp-flag
                     (read-regexp prompt nil 'minibuffer-history)
                   (read-from-minibuffer
-                   prompt nil nil nil nil (car search-ring) t)))))
+                   prompt nil nil nil nil
+                   (delq nil
+                         (list
+                          (when (use-region-p)
+                            (buffer-substring-no-properties
+                             (region-beginning) (region-end)))
+                          (find-tag-default)
+                          (car search-ring)
+                          (car (symbol-value 
query-replace-from-history-variable))))
+                   t)))))
            (to))
       (if (and (zerop (length from)) query-replace-defaults)
          (cons (caar query-replace-defaults)
@@ -798,6 +807,9 @@ read-regexp-suggestions
 appends the list returned by this function to the end of values available
 via \\<minibuffer-local-map>\\[next-history-element]."
   (list
+   (when (use-region-p)
+     (buffer-substring-no-properties
+      (region-beginning) (region-end)))
    (find-tag-default-as-regexp)
    (find-tag-default-as-symbol-regexp)
    (car regexp-search-ring)

reply via email to

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