diff options
| author | Stefan Monnier | 2004-07-05 23:12:28 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-07-05 23:12:28 +0000 |
| commit | 1606466a39bbfe949ead462074686a3c893d0bca (patch) | |
| tree | 59f74566d87ed548e2293bd212f228e16937c685 /lisp/replace.el | |
| parent | 5291cbca50f116e0848623668ab3dc8cc1ff1cbe (diff) | |
| download | emacs-1606466a39bbfe949ead462074686a3c893d0bca.tar.gz emacs-1606466a39bbfe949ead462074686a3c893d0bca.zip | |
(query-replace-read-from, query-replace-read-to): New funs extracted
from query-replace-read-args.
(query-replace-read-args): Use them.
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/lisp/replace.el b/lisp/replace.el index 2d3e1f40a31..380dd83c87e 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -64,21 +64,20 @@ strings or patterns." | |||
| 64 | :group 'matching | 64 | :group 'matching |
| 65 | :version "21.4") | 65 | :version "21.4") |
| 66 | 66 | ||
| 67 | (defun query-replace-read-args (string regexp-flag &optional noerror) | 67 | (defun query-replace-read-from (string regexp-flag) |
| 68 | (unless noerror | 68 | "Query and return the `from' argument of a query-replace operation." |
| 69 | (barf-if-buffer-read-only)) | 69 | (if query-replace-interactive |
| 70 | (let (from to) | 70 | (car (if regexp-flag regexp-search-ring search-ring)) |
| 71 | (if query-replace-interactive | 71 | (let* ((from |
| 72 | (setq from (car (if regexp-flag regexp-search-ring search-ring))) | 72 | ;; The save-excursion here is in case the user marks and copies |
| 73 | ;; The save-excursion here is in case the user marks and copies | 73 | ;; a region in order to specify the minibuffer input. |
| 74 | ;; a region in order to specify the minibuffer input. | 74 | ;; That should not clobber the region for the query-replace itself. |
| 75 | ;; That should not clobber the region for the query-replace itself. | 75 | (save-excursion |
| 76 | (save-excursion | 76 | (read-from-minibuffer |
| 77 | (setq from (read-from-minibuffer | 77 | (format "%s: " string) |
| 78 | (format "%s: " string) | 78 | nil nil nil |
| 79 | nil nil nil | 79 | query-replace-from-history-variable |
| 80 | query-replace-from-history-variable | 80 | nil t)))) |
| 81 | nil t))) | ||
| 82 | ;; Warn if user types \n or \t, but don't reject the input. | 81 | ;; Warn if user types \n or \t, but don't reject the input. |
| 83 | (and regexp-flag | 82 | (and regexp-flag |
| 84 | (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) | 83 | (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) |
| @@ -88,13 +87,16 @@ strings or patterns." | |||
| 88 | (message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead")) | 87 | (message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead")) |
| 89 | ((string= match "\\t") | 88 | ((string= match "\\t") |
| 90 | (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB"))) | 89 | (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB"))) |
| 91 | (sit-for 2)))) | 90 | (sit-for 2))) |
| 92 | 91 | from))) | |
| 93 | (save-excursion | 92 | |
| 94 | (setq to (read-from-minibuffer | 93 | (defun query-replace-read-to (from string regexp-flag) |
| 95 | (format "%s %s with: " string from) | 94 | "Query and return the `from' argument of a query-replace operation." |
| 96 | nil nil nil | 95 | (let ((to (save-excursion |
| 97 | query-replace-to-history-variable from t))) | 96 | (read-from-minibuffer |
| 97 | (format "%s %s with: " string from) | ||
| 98 | nil nil nil | ||
| 99 | query-replace-to-history-variable from t)))) | ||
| 98 | (when (and regexp-flag | 100 | (when (and regexp-flag |
| 99 | (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)) | 101 | (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)) |
| 100 | (let (pos list char) | 102 | (let (pos list char) |
| @@ -129,6 +131,13 @@ strings or patterns." | |||
| 129 | (if (> (length to) 1) | 131 | (if (> (length to) 1) |
| 130 | (cons 'concat to) | 132 | (cons 'concat to) |
| 131 | (car to))))) | 133 | (car to))))) |
| 134 | to)) | ||
| 135 | |||
| 136 | (defun query-replace-read-args (string regexp-flag &optional noerror) | ||
| 137 | (unless noerror | ||
| 138 | (barf-if-buffer-read-only)) | ||
| 139 | (let* ((from (query-replace-read-from string regexp-flag)) | ||
| 140 | (to (query-replace-read-to from string regexp-flag))) | ||
| 132 | (list from to current-prefix-arg))) | 141 | (list from to current-prefix-arg))) |
| 133 | 142 | ||
| 134 | (defun query-replace (from-string to-string &optional delimited start end) | 143 | (defun query-replace (from-string to-string &optional delimited start end) |