diff options
| author | Karoly Lorentey | 2004-08-03 12:45:59 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2004-08-03 12:45:59 +0000 |
| commit | 4fce8dfae60dce6a19bef88ce893bcc019576c66 (patch) | |
| tree | 41dcfb7ebfda8af1faba9e2833283f3dd1fba472 /lisp/replace.el | |
| parent | d0e37e4839b378aa90ba6686013f9563cc3c0821 (diff) | |
| parent | ed5c373cab5483317a8b6fca3d8d4d52432934fc (diff) | |
| download | emacs-4fce8dfae60dce6a19bef88ce893bcc019576c66.tar.gz emacs-4fce8dfae60dce6a19bef88ce893bcc019576c66.zip | |
Merged in changes from CVS trunk.
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-473
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-474
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-475
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-476
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-477
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-478
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-225
Diffstat (limited to 'lisp/replace.el')
| -rw-r--r-- | lisp/replace.el | 41 |
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 | 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 |
| @@ -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)) |