Commit 1606466a authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(query-replace-read-from, query-replace-read-to): New funs extracted

from query-replace-read-args.
(query-replace-read-args): Use them.
parent 5291cbca
...@@ -64,21 +64,20 @@ strings or patterns." ...@@ -64,21 +64,20 @@ strings or patterns."
:group 'matching :group 'matching
:version "21.4") :version "21.4")
(defun query-replace-read-args (string regexp-flag &optional noerror) (defun query-replace-read-from (string regexp-flag)
(unless noerror "Query and return the `from' argument of a query-replace operation."
(barf-if-buffer-read-only)) (if query-replace-interactive
(let (from to) (car (if regexp-flag regexp-search-ring search-ring))
(if query-replace-interactive (let* ((from
(setq from (car (if regexp-flag regexp-search-ring search-ring))) ;; The save-excursion here is in case the user marks and copies
;; The save-excursion here is in case the user marks and copies ;; a region in order to specify the minibuffer input.
;; a region in order to specify the minibuffer input. ;; That should not clobber the region for the query-replace itself.
;; That should not clobber the region for the query-replace itself. (save-excursion
(save-excursion (read-from-minibuffer
(setq from (read-from-minibuffer (format "%s: " string)
(format "%s: " string) nil nil nil
nil nil nil query-replace-from-history-variable
query-replace-from-history-variable nil t))))
nil t)))
;; Warn if user types \n or \t, but don't reject the input. ;; Warn if user types \n or \t, but don't reject the input.
(and regexp-flag (and regexp-flag
(string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
...@@ -88,13 +87,16 @@ strings or patterns." ...@@ -88,13 +87,16 @@ strings or patterns."
(message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead")) (message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead"))
((string= match "\\t") ((string= match "\\t")
(message "Note: `\\t' here doesn't match a tab; to do that, just type TAB"))) (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))
(sit-for 2)))) (sit-for 2)))
from)))
(save-excursion
(setq to (read-from-minibuffer (defun query-replace-read-to (from string regexp-flag)
(format "%s %s with: " string from) "Query and return the `from' argument of a query-replace operation."
nil nil nil (let ((to (save-excursion
query-replace-to-history-variable from t))) (read-from-minibuffer
(format "%s %s with: " string from)
nil nil nil
query-replace-to-history-variable from t))))
(when (and regexp-flag (when (and regexp-flag
(string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)) (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))
(let (pos list char) (let (pos list char)
...@@ -129,6 +131,13 @@ strings or patterns." ...@@ -129,6 +131,13 @@ strings or patterns."
(if (> (length to) 1) (if (> (length to) 1)
(cons 'concat to) (cons 'concat to)
(car to))))) (car to)))))
to))
(defun query-replace-read-args (string regexp-flag &optional noerror)
(unless noerror
(barf-if-buffer-read-only))
(let* ((from (query-replace-read-from string regexp-flag))
(to (query-replace-read-to from string regexp-flag)))
(list from to current-prefix-arg))) (list from to current-prefix-arg)))
(defun query-replace (from-string to-string &optional delimited start end) (defun query-replace (from-string to-string &optional delimited start end)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment