aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorKaroly Lorentey2006-06-12 07:27:12 +0000
committerKaroly Lorentey2006-06-12 07:27:12 +0000
commit476e9367ec1f440aa23904b7bc482ea4a3b8041c (patch)
tree4f7f5a5e9a6668f908834bb6e216c8fa3727d4b3 /lisp/replace.el
parenta13f8f50d4cc544d3bbfa78568e82ce09e68bded (diff)
parent6b519504c3297595101628e823e72c91e562ab45 (diff)
downloademacs-476e9367ec1f440aa23904b7bc482ea4a3b8041c.tar.gz
emacs-476e9367ec1f440aa23904b7bc482ea4a3b8041c.zip
Merged from emacs@sv.gnu.org.
Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-294 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-295 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-296 Update from CVS: admin/FOR-RELEASE: Update refcard section. * emacs@sv.gnu.org/emacs--devo--0--patch-297 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-298 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-299 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-300 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-301 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-302 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-303 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-304 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-103 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-104 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-570
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el43
1 files changed, 23 insertions, 20 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index f1792b499fc..2f8fe86860c 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -36,6 +36,11 @@
36 36
37(defvar query-replace-history nil) 37(defvar query-replace-history nil)
38 38
39(defvar query-replace-defaults nil
40 "Default values of FROM-STRING and TO-STRING for `query-replace'.
41This is a cons cell (FROM-STRING . TO-STRING), or nil if there is
42no default value.")
43
39(defvar query-replace-interactive nil 44(defvar query-replace-interactive nil
40 "Non-nil means `query-replace' uses the last search string. 45 "Non-nil means `query-replace' uses the last search string.
41That becomes the \"string to replace\".") 46That becomes the \"string to replace\".")
@@ -94,32 +99,26 @@ The return value can also be a pair (FROM . TO) indicating that the user
94wants to replace FROM with TO." 99wants to replace FROM with TO."
95 (if query-replace-interactive 100 (if query-replace-interactive
96 (car (if regexp-flag regexp-search-ring search-ring)) 101 (car (if regexp-flag regexp-search-ring search-ring))
97 (let* ((lastfrom (car (symbol-value query-replace-from-history-variable))) 102 (let* ((history-add-new-input nil)
98 (lastto (car (symbol-value query-replace-to-history-variable)))
99 (from 103 (from
100 ;; The save-excursion here is in case the user marks and copies 104 ;; The save-excursion here is in case the user marks and copies
101 ;; a region in order to specify the minibuffer input. 105 ;; a region in order to specify the minibuffer input.
102 ;; That should not clobber the region for the query-replace itself. 106 ;; That should not clobber the region for the query-replace itself.
103 (save-excursion 107 (save-excursion
104 (when (equal lastfrom lastto)
105 ;; Typically, this is because the two histlists are shared.
106 (setq lastfrom (cadr (symbol-value
107 query-replace-from-history-variable))))
108 (read-from-minibuffer 108 (read-from-minibuffer
109 (if (and lastto lastfrom) 109 (if query-replace-defaults
110 (format "%s (default %s -> %s): " prompt 110 (format "%s (default %s -> %s): " prompt
111 (query-replace-descr lastfrom) 111 (query-replace-descr (car query-replace-defaults))
112 (query-replace-descr lastto)) 112 (query-replace-descr (cdr query-replace-defaults)))
113 (format "%s: " prompt)) 113 (format "%s: " prompt))
114 nil nil nil 114 nil nil nil
115 query-replace-from-history-variable 115 query-replace-from-history-variable
116 nil t t)))) 116 nil t))))
117 (if (and (zerop (length from)) lastto lastfrom) 117 (if (and (zerop (length from)) query-replace-defaults)
118 (progn 118 (cons (car query-replace-defaults)
119 (set query-replace-from-history-variable 119 (query-replace-compile-replacement
120 (cdr (symbol-value query-replace-from-history-variable))) 120 (cdr query-replace-defaults) regexp-flag))
121 (cons lastfrom 121 (add-to-history query-replace-from-history-variable from nil t)
122 (query-replace-compile-replacement lastto regexp-flag)))
123 ;; Warn if user types \n or \t, but don't reject the input. 122 ;; Warn if user types \n or \t, but don't reject the input.
124 (and regexp-flag 123 (and regexp-flag
125 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) 124 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
@@ -177,10 +176,14 @@ the original string if not."
177 "Query and return the `to' argument of a query-replace operation." 176 "Query and return the `to' argument of a query-replace operation."
178 (query-replace-compile-replacement 177 (query-replace-compile-replacement
179 (save-excursion 178 (save-excursion
180 (read-from-minibuffer 179 (let* ((history-add-new-input nil)
181 (format "%s %s with: " prompt (query-replace-descr from)) 180 (to (read-from-minibuffer
182 nil nil nil 181 (format "%s %s with: " prompt (query-replace-descr from))
183 query-replace-to-history-variable from t t)) 182 nil nil nil
183 query-replace-to-history-variable from t)))
184 (add-to-history query-replace-to-history-variable to nil t)
185 (setq query-replace-defaults (cons from to))
186 to))
184 regexp-flag)) 187 regexp-flag))
185 188
186(defun query-replace-read-args (prompt regexp-flag &optional noerror) 189(defun query-replace-read-args (prompt regexp-flag &optional noerror)