/[emacs]/emacs/lisp/replace.el
ViewVC logotype

Diff of /emacs/lisp/replace.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.163 by lektu, Tue Feb 4 12:00:39 2003 UTC revision 1.164 by rms, Mon Feb 24 16:45:47 2003 UTC
# Line 87  strings or patterns." Line 87  strings or patterns."
87      (setq to (read-from-minibuffer (format "%s %s with: " string from)      (setq to (read-from-minibuffer (format "%s %s with: " string from)
88                                     nil nil nil                                     nil nil nil
89                                     query-replace-to-history-variable from t))                                     query-replace-to-history-variable from t))
90      (if (and transient-mark-mode mark-active)      (list from to current-prefix-arg)))
         (list from to current-prefix-arg (region-beginning) (region-end))  
       (list from to current-prefix-arg nil nil))))  
91    
92  (defun query-replace (from-string to-string &optional delimited start end)  (defun query-replace (from-string to-string &optional delimited start end)
93    "Replace some occurrences of FROM-STRING with TO-STRING.    "Replace some occurrences of FROM-STRING with TO-STRING.
# Line 116  only matches surrounded by word boundari Line 114  only matches surrounded by word boundari
114  Fourth and fifth arg START and END specify the region to operate on.  Fourth and fifth arg START and END specify the region to operate on.
115    
116  To customize possible responses, change the \"bindings\" in `query-replace-map'."  To customize possible responses, change the \"bindings\" in `query-replace-map'."
117    (interactive (query-replace-read-args "Query replace" nil))    (interactive (let ((common
118                          (query-replace-read-args "Query replace" nil)))
119                     (list (nth 0 common) (nth 1 common) (nth 2 common)
120                           ;; These are done separately here
121                           ;; so that command-history will record these expressions
122                           ;; rather than the values they had this time.
123                           (if (and transient-mark-mode mark-active)
124                               (region-beginning))
125                           (if (and transient-mark-mode mark-active)
126                               (region-end)))))
127    (perform-replace from-string to-string t nil delimited nil nil start end))    (perform-replace from-string to-string t nil delimited nil nil start end))
128    
129  (define-key esc-map "%" 'query-replace)  (define-key esc-map "%" 'query-replace)
# Line 148  Fourth and fifth arg START and END speci Line 155  Fourth and fifth arg START and END speci
155  In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,  In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
156  and `\\=\\N' (where N is a digit) stands for  and `\\=\\N' (where N is a digit) stands for
157   whatever what matched the Nth `\\(...\\)' in REGEXP."   whatever what matched the Nth `\\(...\\)' in REGEXP."
158    (interactive (query-replace-read-args "Query replace regexp" t))    (interactive
159       (let ((common
160              (query-replace-read-args "Query replace regexp" t)))
161         (list (nth 0 common) (nth 1 common) (nth 2 common)
162               ;; These are done separately here
163               ;; so that command-history will record these expressions
164               ;; rather than the values they had this time.
165               (if (and transient-mark-mode mark-active)
166                   (region-beginning))
167               (if (and transient-mark-mode mark-active)
168                   (region-end)))))
169    
170    (perform-replace regexp to-string t t delimited nil nil start end))    (perform-replace regexp to-string t t delimited nil nil start end))
171  (define-key esc-map [?\C-%] 'query-replace-regexp)  (define-key esc-map [?\C-%] 'query-replace-regexp)
172    
# Line 181  Third arg DELIMITED (prefix arg if inter Line 199  Third arg DELIMITED (prefix arg if inter
199  only matches that are surrounded by word boundaries.  only matches that are surrounded by word boundaries.
200  Fourth and fifth arg START and END specify the region to operate on."  Fourth and fifth arg START and END specify the region to operate on."
201    (interactive    (interactive
202     (let (from to start end)     (let (from to)
      (when (and transient-mark-mode mark-active)  
        (setq start (region-beginning)  
              end (region-end)))  
203       (if query-replace-interactive       (if query-replace-interactive
204           (setq from (car regexp-search-ring))           (setq from (car regexp-search-ring))
205         (setq from (read-from-minibuffer "Query replace regexp: "         (setq from (read-from-minibuffer "Query replace regexp: "
# Line 197  Fourth and fifth arg START and END speci Line 212  Fourth and fifth arg START and END speci
212       ;; We make TO a list because replace-match-string-symbols requires one,       ;; We make TO a list because replace-match-string-symbols requires one,
213       ;; and the user might enter a single token.       ;; and the user might enter a single token.
214       (replace-match-string-symbols to)       (replace-match-string-symbols to)
215       (list from (car to) current-prefix-arg start end)))       (list from (car to) current-prefix-arg
216               (if (and transient-mark-mode mark-active)
217                   (region-beginning))
218               (if (and transient-mark-mode mark-active)
219                   (region-end)))))
220    (perform-replace regexp (cons 'replace-eval-replacement to-expr)    (perform-replace regexp (cons 'replace-eval-replacement to-expr)
221                     t t delimited nil nil start end))                     t t delimited nil nil start end))
222    
# Line 222  A prefix argument N says to use each rep Line 241  A prefix argument N says to use each rep
241  before rotating to the next.  before rotating to the next.
242  Fourth and fifth arg START and END specify the region to operate on."  Fourth and fifth arg START and END specify the region to operate on."
243    (interactive    (interactive
244     (let (from to start end)     (let (from to)
      (when (and transient-mark-mode mark-active)  
        (setq start (region-beginning)  
              end (region-end)))  
245       (setq from (if query-replace-interactive       (setq from (if query-replace-interactive
246                      (car regexp-search-ring)                      (car regexp-search-ring)
247                    (read-from-minibuffer "Map query replace (regexp): "                    (read-from-minibuffer "Map query replace (regexp): "
# Line 236  Fourth and fifth arg START and END speci Line 252  Fourth and fifth arg START and END speci
252                         from)                         from)
253                 nil nil nil                 nil nil nil
254                 'query-replace-history from t))                 'query-replace-history from t))
255       (list from to start end current-prefix-arg)))       (list from to current-prefix-arg
256               (if (and transient-mark-mode mark-active)
257                   (region-beginning))
258               (if (and transient-mark-mode mark-active)
259                   (region-end)))))
260    (let (replacements)    (let (replacements)
261      (if (listp to-strings)      (if (listp to-strings)
262          (setq replacements to-strings)          (setq replacements to-strings)
# Line 277  What you probably want is a loop like th Line 297  What you probably want is a loop like th
297  which will run faster and will not set the mark or print anything.  which will run faster and will not set the mark or print anything.
298  \(You may need a more complex loop if FROM-STRING can match the null string  \(You may need a more complex loop if FROM-STRING can match the null string
299  and TO-STRING is also null.)"  and TO-STRING is also null.)"
300    (interactive (query-replace-read-args "Replace string" nil))    (interactive
301       (let ((common
302              (query-replace-read-args "Replace string" nil)))
303         (list (nth 0 common) (nth 1 common) (nth 2 common)
304               (if (and transient-mark-mode mark-active)
305                   (region-beginning))
306               (if (and transient-mark-mode mark-active)
307                   (region-end)))))
308    (perform-replace from-string to-string nil nil delimited nil nil start end))    (perform-replace from-string to-string nil nil delimited nil nil start end))
309    
310  (defun replace-regexp (regexp to-string &optional delimited start end)  (defun replace-regexp (regexp to-string &optional delimited start end)
# Line 304  What you probably want is a loop like th Line 331  What you probably want is a loop like th
331    (while (re-search-forward REGEXP nil t)    (while (re-search-forward REGEXP nil t)
332      (replace-match TO-STRING nil nil))      (replace-match TO-STRING nil nil))
333  which will run faster and will not set the mark or print anything."  which will run faster and will not set the mark or print anything."
334    (interactive (query-replace-read-args "Replace regexp" t))    (interactive
335       (let ((common
336              (query-replace-read-args "Replace regexp" t)))
337         (list (nth 0 common) (nth 1 common) (nth 2 common)
338               (if (and transient-mark-mode mark-active)
339                   (region-beginning))
340               (if (and transient-mark-mode mark-active)
341                   (region-end)))))
342    (perform-replace regexp to-string nil t delimited nil nil start end))    (perform-replace regexp to-string nil t delimited nil nil start end))
343    
344    

Legend:
Removed from v.1.163  
changed lines
  Added in v.1.164

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26