/[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.186 by rms, Sat Jul 24 21:34:47 2004 UTC revision 1.187 by dak, Sun Aug 1 12:59:09 2004 UTC
# Line 94  wants to replace FROM with TO." Line 94  wants to replace FROM with TO."
94                 query-replace-from-history-variable                 query-replace-from-history-variable
95                 nil t))))                 nil t))))
96        (if (and (zerop (length from)) lastto lastfrom)        (if (and (zerop (length from)) lastto lastfrom)
97            (cons lastfrom lastto)            (cons lastfrom
98                    (query-replace-compile-replacement lastto regexp-flag))
99          ;; Warn if user types \n or \t, but don't reject the input.          ;; Warn if user types \n or \t, but don't reject the input.
100          (and regexp-flag          (and regexp-flag
101               (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)               (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
# Line 107  wants to replace FROM with TO." Line 108  wants to replace FROM with TO."
108                 (sit-for 2)))                 (sit-for 2)))
109          from))))          from))))
110    
111  (defun query-replace-read-to (from string regexp-flag)  (defun query-replace-compile-replacement (to regexp-flag)
112    "Query and return the `from' argument of a query-replace operation."    "Maybe convert a regexp replacement TO to Lisp.
113    (let ((to (save-excursion  Returns a list suitable for `perform-replace' if necessary,
114                (read-from-minibuffer  the original string if not."
115                 (format "%s %s with: " string (query-replace-descr from))    (if (and regexp-flag
116                 nil nil nil             (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))
                query-replace-to-history-variable from t))))  
     (when (and regexp-flag  
                (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to))  
117        (let (pos list char)        (let (pos list char)
118          (while          (while
119              (progn              (progn
# Line 142  wants to replace FROM with TO." Line 140  wants to replace FROM with TO."
140                                (cdr pos))))                                (cdr pos))))
141                         (setq to (substring to end)))))                         (setq to (substring to end)))))
142                (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)))                (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\[,#]" to)))
143          (setq to (nreverse (delete "" (cons to list)))))          (setq to (nreverse (delete "" (cons to list))))
144        (replace-match-string-symbols to)          (replace-match-string-symbols to)
145        (setq to (cons 'replace-eval-replacement          (cons 'replace-eval-replacement
146                       (if (> (length to) 1)                (if (cdr to)
147                           (cons 'concat to)                    (cons 'concat to)
148                         (car to)))))                  (car to))))
149      to))      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))
161    
162  (defun query-replace-read-args (string regexp-flag &optional noerror)  (defun query-replace-read-args (string regexp-flag &optional noerror)
163    (unless noerror    (unless noerror
164      (barf-if-buffer-read-only))      (barf-if-buffer-read-only))

Legend:
Removed from v.1.186  
changed lines
  Added in v.1.187

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