aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el41
1 files changed, 25 insertions, 16 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index f09868cc6d3..47437659923 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -94,7 +94,8 @@ wants to replace FROM with TO."
94 query-replace-from-history-variable 94 query-replace-from-history-variable
95 nil t)))) 95 nil t))))
96 (if (and (zerop (length from)) lastto lastfrom) 96 (if (and (zerop (length from)) lastto lastfrom)
97 (cons lastfrom lastto) 97 (cons lastfrom
98 (query-replace-compile-replacement lastto regexp-flag))
98 ;; Warn if user types \n or \t, but don't reject the input. 99 ;; Warn if user types \n or \t, but don't reject the input.
99 (and regexp-flag 100 (and regexp-flag
100 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) 101 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
@@ -107,15 +108,12 @@ wants to replace FROM with TO."
107 (sit-for 2))) 108 (sit-for 2)))
108 from)))) 109 from))))
109 110
110(defun query-replace-read-to (from string regexp-flag) 111(defun query-replace-compile-replacement (to regexp-flag)
111 "Query and return the `from' argument of a query-replace operation." 112 "Maybe convert a regexp replacement TO to Lisp.
112 (let ((to (save-excursion 113Returns a list suitable for `perform-replace' if necessary,
113 (read-from-minibuffer 114the original string if not."
114 (format "%s %s with: " string (query-replace-descr from)) 115 (if (and regexp-flag
115 nil nil nil 116 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))
116 query-replace-to-history-variable from t))))
117 (when (and regexp-flag
118 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))
119 (let (pos list char) 117 (let (pos list char)
120 (while 118 (while
121 (progn 119 (progn
@@ -142,14 +140,25 @@ wants to replace FROM with TO."
142 (cdr pos)))) 140 (cdr pos))))
143 (setq to (substring to end))))) 141 (setq to (substring to end)))))
144 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))) 142 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)))
145 (setq to (nreverse (delete "" (cons to list))))) 143 (setq to (nreverse (delete "" (cons to list))))
146 (replace-match-string-symbols to) 144 (replace-match-string-symbols to)
147 (setq to (cons 'replace-eval-replacement 145 (cons 'replace-eval-replacement
148 (if (> (length to) 1) 146 (if (cdr to)
149 (cons 'concat to) 147 (cons 'concat to)
150 (car to))))) 148 (car to))))
151 to)) 149 to))
152 150
151
152(defun query-replace-read-to (from string regexp-flag)
153 "Query and return the `to' argument of a query-replace operation."
154 (query-replace-compile-replacement
155 (save-excursion
156 (read-from-minibuffer
157 (format "%s %s with: " string (query-replace-descr from))
158 nil nil nil
159 query-replace-to-history-variable from t))
160 regexp-flag))
161
153(defun query-replace-read-args (string regexp-flag &optional noerror) 162(defun query-replace-read-args (string regexp-flag &optional noerror)
154 (unless noerror 163 (unless noerror
155 (barf-if-buffer-read-only)) 164 (barf-if-buffer-read-only))