aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2004-07-06 00:06:05 +0000
committerStefan Monnier2004-07-06 00:06:05 +0000
commit6f1df6d9d69af4e3895eebde2a48dd4bdba1832f (patch)
tree78abfb46c87adc0a96f604c7ce9cb9d3eb60b2fc
parentfe3b7e35ad6b06267d01a4649d2c512f714a45b2 (diff)
downloademacs-6f1df6d9d69af4e3895eebde2a48dd4bdba1832f.tar.gz
emacs-6f1df6d9d69af4e3895eebde2a48dd4bdba1832f.zip
(query-replace-descr): New fun.
(query-replace-read-from, query-replace-read-args): Default to the last from&to. (query-replace-read-to): Quote the `from' string when displaying it. (query-replace-regexp-eval): Immediately check read-only status. Use query-replace-read-from to get the \n checking. Quote the `from' string when displaying it. (map-query-replace-regexp, occur-read-primary-args): Quote the `from' string when displaying it.
-rw-r--r--lisp/ChangeLog34
-rw-r--r--lisp/replace.el76
2 files changed, 78 insertions, 32 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c3794650c1a..92552debee2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,7 +1,34 @@
12004-07-05 Stefan <monnier@iro.umontreal.ca>
2
3 * replace.el (query-replace-descr): New fun.
4 (query-replace-read-from, query-replace-read-args): Default to the
5 previous from&to.
6 (query-replace-read-to): Quote the `from' string when displaying it.
7 (query-replace-regexp-eval): Immediately check read-only status.
8 Use query-replace-read-from to get the \n checking.
9 Quote the `from' string when displaying it.
10 (map-query-replace-regexp, occur-read-primary-args):
11 Quote the `from' string when displaying it.
12
13 * isearch.el (isearch-query-replace): Pass the regexp-ness and
14 delimited-ness of the search to query-replace.
15
16 * replace.el (query-replace-read-from, query-replace-read-to):
17 New funs extracted from query-replace-read-args.
18 (query-replace-read-args): Use them.
19
20 * replace.el (query-replace-interactive, query-replace-read-args):
21 Remove the `initial' special value.
22 (query-replace-regexp-eval, map-query-replace-regexp): Simplify.
23 (occur-engine): Remove unused var `matchend'.
24
25 * isearch.el (isearch-query-replace, isearch-query-replace-regexp):
26 Use the search string without prompting.
27
12004-07-05 Kenichi Handa <handa@m17n.org> 282004-07-05 Kenichi Handa <handa@m17n.org>
2 29
3 * international/mule.el (decode-coding-inserted-region): Set 30 * international/mule.el (decode-coding-inserted-region):
4 last-coding-system-used only when coding is nil. 31 Set last-coding-system-used only when coding is nil.
5 32
62004-07-03 Eli Zaretskii <eliz@gnu.org> 332004-07-03 Eli Zaretskii <eliz@gnu.org>
7 34
@@ -14,8 +41,7 @@
14 41
152004-07-03 KOSEKI Yoshinori <kose@meadowy.org> 422004-07-03 KOSEKI Yoshinori <kose@meadowy.org>
16 43
17 * iimage.el (turn-on-iimage-mode, iimage-mode): Add autoload 44 * iimage.el (turn-on-iimage-mode, iimage-mode): Add autoload cookies.
18 cookies.
19 (iimage-mode-image-search-path): New user option to search the 45 (iimage-mode-image-search-path): New user option to search the
20 image file. 46 image file.
21 (iimage-locate-file): New funcion. Emacs21.3 or earlier does not 47 (iimage-locate-file): New funcion. Emacs21.3 or earlier does not
diff --git a/lisp/replace.el b/lisp/replace.el
index 380dd83c87e..a7c8b859402 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1,7 +1,7 @@
1;;; replace.el --- replace commands for Emacs 1;;; replace.el --- replace commands for Emacs
2 2
3;; Copyright (C) 1985, 86, 87, 92, 94, 96, 1997, 2000, 2001, 2002, 3;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1996, 1997, 2000, 2001, 2002,
4;; 2003, 2004 Free Software Foundation, Inc. 4;; 2003, 2004 Free Software Foundation, Inc.
5 5
6;; Maintainer: FSF 6;; Maintainer: FSF
7 7
@@ -64,37 +64,54 @@ strings or patterns."
64 :group 'matching 64 :group 'matching
65 :version "21.4") 65 :version "21.4")
66 66
67(defun query-replace-descr (string)
68 (mapconcat 'isearch-text-char-description string ""))
69
67(defun query-replace-read-from (string regexp-flag) 70(defun query-replace-read-from (string regexp-flag)
68 "Query and return the `from' argument of a query-replace operation." 71 "Query and return the `from' argument of a query-replace operation.
72The return value can also be a pair (FROM . TO) indicating that the user
73wants to replace FROM with TO."
69 (if query-replace-interactive 74 (if query-replace-interactive
70 (car (if regexp-flag regexp-search-ring search-ring)) 75 (car (if regexp-flag regexp-search-ring search-ring))
71 (let* ((from 76 (let* ((lastfrom (car (symbol-value query-replace-from-history-variable)))
77 (lastto (car (symbol-value query-replace-to-history-variable)))
78 (from
72 ;; The save-excursion here is in case the user marks and copies 79 ;; The save-excursion here is in case the user marks and copies
73 ;; a region in order to specify the minibuffer input. 80 ;; a region in order to specify the minibuffer input.
74 ;; That should not clobber the region for the query-replace itself. 81 ;; That should not clobber the region for the query-replace itself.
75 (save-excursion 82 (save-excursion
83 (when (equal lastfrom lastto)
84 ;; Typically, this is because the two histlists are shared.
85 (setq lastfrom (cadr (symbol-value
86 query-replace-from-history-variable))))
76 (read-from-minibuffer 87 (read-from-minibuffer
77 (format "%s: " string) 88 (if (and lastto lastfrom)
89 (format "%s (default %s -> %s): " string
90 (query-replace-descr lastfrom)
91 (query-replace-descr lastto))
92 (format "%s: " string))
78 nil nil nil 93 nil nil nil
79 query-replace-from-history-variable 94 query-replace-from-history-variable
80 nil t)))) 95 nil t))))
81 ;; Warn if user types \n or \t, but don't reject the input. 96 (if (and (zerop (length from)) lastto lastfrom)
82 (and regexp-flag 97 (cons lastfrom lastto)
83 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from) 98 ;; Warn if user types \n or \t, but don't reject the input.
84 (let ((match (match-string 3 from))) 99 (and regexp-flag
85 (cond 100 (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
86 ((string= match "\\n") 101 (let ((match (match-string 3 from)))
87 (message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead")) 102 (cond
88 ((string= match "\\t") 103 ((string= match "\\n")
89 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB"))) 104 (message "Note: `\\n' here doesn't match a newline; to do that, type C-q C-j instead"))
90 (sit-for 2))) 105 ((string= match "\\t")
91 from))) 106 (message "Note: `\\t' here doesn't match a tab; to do that, just type TAB")))
107 (sit-for 2)))
108 from))))
92 109
93(defun query-replace-read-to (from string regexp-flag) 110(defun query-replace-read-to (from string regexp-flag)
94 "Query and return the `from' argument of a query-replace operation." 111 "Query and return the `from' argument of a query-replace operation."
95 (let ((to (save-excursion 112 (let ((to (save-excursion
96 (read-from-minibuffer 113 (read-from-minibuffer
97 (format "%s %s with: " string from) 114 (format "%s %s with: " string (query-replace-descr from))
98 nil nil nil 115 nil nil nil
99 query-replace-to-history-variable from t)))) 116 query-replace-to-history-variable from t))))
100 (when (and regexp-flag 117 (when (and regexp-flag
@@ -137,7 +154,8 @@ strings or patterns."
137 (unless noerror 154 (unless noerror
138 (barf-if-buffer-read-only)) 155 (barf-if-buffer-read-only))
139 (let* ((from (query-replace-read-from string regexp-flag)) 156 (let* ((from (query-replace-read-from string regexp-flag))
140 (to (query-replace-read-to from string regexp-flag))) 157 (to (if (consp from) (prog1 (cdr from) (setq from (car from)))
158 (query-replace-read-to from string regexp-flag))))
141 (list from to current-prefix-arg))) 159 (list from to current-prefix-arg)))
142 160
143(defun query-replace (from-string to-string &optional delimited start end) 161(defun query-replace (from-string to-string &optional delimited start end)
@@ -269,14 +287,16 @@ Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
269only matches that are surrounded by word boundaries. 287only matches that are surrounded by word boundaries.
270Fourth and fifth arg START and END specify the region to operate on." 288Fourth and fifth arg START and END specify the region to operate on."
271 (interactive 289 (interactive
272 (let* ((from (if query-replace-interactive 290 (barf-if-buffer-read-only)
273 (car regexp-search-ring) 291 (let* ((from
274 (read-from-minibuffer "Query replace regexp: " 292 ;; Let-bind the history var to disable the "foo -> bar" default.
275 nil nil nil 293 ;; Maybe we shouldn't disable this default, but for now I'll
276 query-replace-from-history-variable 294 ;; leave it off. --Stef
277 nil t))) 295 (let ((query-replace-to-history-variable nil))
296 (query-replace-read-from "Query replace regexp" t)))
278 (to (list (read-from-minibuffer 297 (to (list (read-from-minibuffer
279 (format "Query replace regexp %s with eval: " from) 298 (format "Query replace regexp %s with eval: "
299 (query-replace-descr from))
280 nil nil t query-replace-to-history-variable from t)))) 300 nil nil t query-replace-to-history-variable from t))))
281 ;; We make TO a list because replace-match-string-symbols requires one, 301 ;; We make TO a list because replace-match-string-symbols requires one,
282 ;; and the user might enter a single token. 302 ;; and the user might enter a single token.
@@ -317,7 +337,7 @@ Fourth and fifth arg START and END specify the region to operate on."
317 'query-replace-history nil t))) 337 'query-replace-history nil t)))
318 (to (read-from-minibuffer 338 (to (read-from-minibuffer
319 (format "Query replace %s with (space-separated strings): " 339 (format "Query replace %s with (space-separated strings): "
320 from) 340 (query-replace-descr from))
321 nil nil nil 341 nil nil nil
322 'query-replace-history from t))) 342 'query-replace-history from t)))
323 (list from to 343 (list from to
@@ -760,7 +780,7 @@ If the value is nil, don't highlight the buffer names specially."
760 (read-from-minibuffer 780 (read-from-minibuffer
761 (if default 781 (if default
762 (format "List lines matching regexp (default `%s'): " 782 (format "List lines matching regexp (default `%s'): "
763 default) 783 (query-replace-descr default))
764 "List lines matching regexp: ") 784 "List lines matching regexp: ")
765 nil 785 nil
766 nil 786 nil
@@ -1538,5 +1558,5 @@ make, or the user didn't cancel the call."
1538 (if (facep 'query-replace) 1558 (if (facep 'query-replace)
1539 'query-replace 'region))))) 1559 'query-replace 'region)))))
1540 1560
1541;;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4 1561;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4
1542;;; replace.el ends here 1562;;; replace.el ends here