]> code.delx.au - gnu-emacs/blobdiff - lisp/replace.el
lisp/gnus/gnus-icalendar.el (gnus-icalendar-identities): Make changing the value...
[gnu-emacs] / lisp / replace.el
index d92fb6809efcc8aa98ac51a6e62690beeaf5d1e1..2c6b02364b2ec5a7d3a8d5d7827bf578a7731e02 100644 (file)
@@ -1,7 +1,7 @@
 ;;; replace.el --- replace commands for Emacs
 
-;; Copyright (C) 1985-1987, 1992, 1994, 1996-1997, 2000-2013 Free
-;; Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1992, 1994, 1996-1997, 2000-2013
+;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Package: emacs
@@ -523,6 +523,8 @@ and TO-STRING is also null.)"
           (if (and transient-mark-mode mark-active)
               (region-end)))))
   (perform-replace from-string to-string nil nil delimited nil nil start end))
+(put 'replace-string 'interactive-only
+     "use `search-forward' and `replace-match' instead.")
 
 (defun replace-regexp (regexp to-string &optional delimited start end)
   "Replace things after point matching REGEXP with TO-STRING.
@@ -590,6 +592,8 @@ which will run faster and will not set the mark or print anything."
           (if (and transient-mark-mode mark-active)
               (region-end)))))
   (perform-replace regexp to-string nil t delimited nil nil start end))
+(put 'replace-regexp 'interactive-only
+     "use `re-search-forward' and `replace-match' instead.")
 
 \f
 (defvar regexp-history nil
@@ -1453,7 +1457,9 @@ See also `multi-occur'."
                            ;; so as to override faces copied from the buffer.
                            `(face ,match-face)))
                         curstring)
-                       (setq start (match-end 0))))
+                       ;; Avoid infloop (Bug#7593).
+                       (let ((end (match-end 0)))
+                         (setq start (if (= start end) (1+ start) end)))))
                    ;; Generate the string to insert for this match
                    (let* ((match-prefix
                            ;; Using 7 digits aligns tabs properly.
@@ -1793,7 +1799,12 @@ type them using Lisp syntax."
 
 (defun replace-eval-replacement (expression count)
   (let* ((replace-count count)
-         (replacement (eval expression)))
+         err
+         (replacement
+          (condition-case err
+              (eval expression)
+            (error
+             (error "Error evaluating replacement expression: %S" err)))))
     (if (stringp replacement)
         replacement
       (prin1-to-string replacement t))))