comparison lisp/replace.el @ 89958:0bdb5a16ae51

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-27 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-471 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-478 Update from CVS
author Miles Bader <miles@gnu.org>
date Tue, 03 Aug 2004 00:03:00 +0000
parents c08afac24467 6cfb1ef9200f
children cce1c0ee76ee
comparison
equal deleted inserted replaced
89957:c08afac24467 89958:0bdb5a16ae51
92 (format "%s: " string)) 92 (format "%s: " string))
93 nil nil nil 93 nil nil nil
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)
101 (let ((match (match-string 3 from))) 102 (let ((match (match-string 3 from)))
102 (cond 103 (cond
105 ((string= match "\\t") 106 ((string= match "\\t")
106 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB"))) 107 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))
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 113 Returns a list suitable for `perform-replace' if necessary,
113 (read-from-minibuffer 114 the 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
122 (setq pos (match-end 0)) 120 (setq pos (match-end 0))
123 (push (substring to 0 (- pos 2)) list) 121 (push (substring to 0 (- pos 2)) list)
140 (cdr pos))) 138 (cdr pos)))
141 (1+ (cdr pos)) 139 (1+ (cdr pos))
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))
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))
152 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))
156 (let* ((from (query-replace-read-from string regexp-flag)) 165 (let* ((from (query-replace-read-from string regexp-flag))