;;; 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
Ignore read-only matches if `query-replace-skip-read-only' is non-nil,
ignore hidden matches if `search-invisible' is nil, and ignore more
-matches using a non-nil `isearch-filter-predicates'.
+matches using `isearch-filter-predicate'.
If `replace-lax-whitespace' is non-nil, a space or spaces in the string
to be replaced will match a sequence of whitespace chars defined by the
Ignore read-only matches if `query-replace-skip-read-only' is non-nil,
ignore hidden matches if `search-invisible' is nil, and ignore more
-matches using a non-nil `isearch-filter-predicates'.
+matches using `isearch-filter-predicate'.
If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
to be replaced will match a sequence of whitespace chars defined by the
Ignore read-only matches if `query-replace-skip-read-only' is non-nil,
ignore hidden matches if `search-invisible' is nil, and ignore more
-matches using a non-nil `isearch-filter-predicates'.
+matches using `isearch-filter-predicate'.
If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
to be replaced will match a sequence of whitespace chars defined by the
Ignore read-only matches if `query-replace-skip-read-only' is non-nil,
ignore hidden matches if `search-invisible' is nil, and ignore more
-matches using a non-nil `isearch-filter-predicates'.
+matches using `isearch-filter-predicate'.
If `replace-lax-whitespace' is non-nil, a space or spaces in the string
to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'.
-In Transient Mark mode, if the mark is active, operate on the contents
-of the region. Otherwise, operate from point to the end of the buffer.
-
Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
only matches surrounded by word boundaries.
-Fourth and fifth arg START and END specify the region to operate on.
+
+Operates on the region between START and END (if both are nil, from point
+to the end of the buffer). Interactively, if Transient Mark mode is
+enabled and the mark is active, operates on the contents of the region;
+otherwise from point to the end of the buffer.
Use \\<minibuffer-local-map>\\[next-history-element] \
to pull the last incremental search string to the minibuffer
(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.
Ignore read-only matches if `query-replace-skip-read-only' is non-nil,
ignore hidden matches if `search-invisible' is nil, and ignore more
-matches using a non-nil `isearch-filter-predicates'.
+matches using `isearch-filter-predicate'.
If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
to be replaced will match a sequence of whitespace chars defined by the
(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
(keep-lines-read-args "How many matches for regexp"))
(save-excursion
(if rstart
- (progn
- (goto-char (min rstart rend))
- (setq rend (max rstart rend)))
+ (if rend
+ (progn
+ (goto-char (min rstart rend))
+ (setq rend (max rstart rend)))
+ (goto-char rstart)
+ (setq rend (point-max)))
(if (and interactive transient-mark-mode mark-active)
(setq rstart (region-beginning)
rend (region-end))
;; 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.
(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))))
'read-only nil))))
(setq skip-read-only-count (1+ skip-read-only-count)))
;; Optionally filter out matches.
- ((not (run-hook-with-args-until-failure
- 'isearch-filter-predicates
- (nth 0 real-match-data) (nth 1 real-match-data)))
+ ((not (funcall isearch-filter-predicate
+ (nth 0 real-match-data) (nth 1 real-match-data)))
(setq skip-filtered-count (1+ skip-filtered-count)))
;; Optionally ignore invisible matches.
((not (or (eq search-invisible t)
(with-output-to-temp-buffer "*Help*"
(princ
(concat "Query replacing "
- (if delimited-flag "word " "")
+ (if delimited-flag
+ (or (and (symbolp delimited-flag)
+ (get delimited-flag 'isearch-message-prefix))
+ "word ") "")
(if regexp-flag "regexp " "")
from-string " with "
next-replacement ".\n\n"