* lisp/replace.el (query-replace-read-from-default): New variable.
(query-replace-read-from-regexp-default): New variable. (query-replace-read-from): Use new variables. * lisp/progmodes/project.el (project-query-replace-regexp): Let-bind query-replace-read-from-regexp-default to find-tag-default-as-regexp. * lisp/progmodes/xref.el (xref-find-references-and-replace): Let-bind query-replace-read-from-default to find-tag-default. https://lists.gnu.org/archive/html/emacs-devel/2022-01/msg01909.html
This commit is contained in:
parent
4af491605c
commit
749ba35bf5
4 changed files with 39 additions and 8 deletions
11
etc/NEWS
11
etc/NEWS
|
|
@ -1237,6 +1237,17 @@ inhibits 'isearch' matching the STRING parameter.
|
|||
** New function 'replace-regexp-function'.
|
||||
It can be used to implement own regexp syntax for search/replace.
|
||||
|
||||
---
|
||||
** New variable 'query-replace-read-from-default'.
|
||||
It can be set to a function that returns the default value (such as
|
||||
'find-tag-default') when 'query-replace' reads a string to replace.
|
||||
Another new variable 'query-replace-read-from-regexp-default'
|
||||
can be set to a function that returns the default value (such as
|
||||
'find-tag-default-as-regexp') when 'query-replace-regexp'
|
||||
reads a regexp to replace. When these variables are nil
|
||||
(which is the default) then 'query-replace' uses the previous
|
||||
replacement from-to pair as the default value.
|
||||
|
||||
---
|
||||
** New user option 'pp-use-max-width'.
|
||||
If non-nil, 'pp' will attempt to limit the line length when formatting
|
||||
|
|
|
|||
|
|
@ -1072,9 +1072,10 @@ Stops when a match is found and prompts for whether to replace it.
|
|||
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))
|
||||
|
|
|
|||
|
|
@ -1481,8 +1481,9 @@ is nil, prompt only if there's no usable symbol at point."
|
|||
(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
|
||||
|
|
|
|||
|
|
@ -186,6 +186,12 @@ See `replace-regexp' and `query-replace-regexp-eval'.")
|
|||
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 @@ wants to replace FROM with TO."
|
|||
(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 @@ wants to replace FROM with TO."
|
|||
(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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue