X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/bd358779861f265a7acff31ead40172735af693e..88312cfc5990060c2d5d54002774ef07e354dd12:/lisp/replace.el diff --git a/lisp/replace.el b/lisp/replace.el index 24cfccf60f..2c6b02364b 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -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 @@ -252,7 +252,7 @@ or capitalized.) 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 @@ -306,7 +306,7 @@ capitalized.) 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 @@ -390,7 +390,7 @@ are non-nil and REGEXP has no uppercase letters. 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 @@ -484,18 +484,19 @@ then its replacement is upcased or capitalized.) 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 \\\\[next-history-element] \ to pull the last incremental search string to the minibuffer @@ -522,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. @@ -530,7 +533,7 @@ are non-nil and REGEXP has no uppercase letters. 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 @@ -589,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.") (defvar regexp-history nil @@ -809,9 +814,12 @@ a previously found match." (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)) @@ -1449,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. @@ -1789,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)))) @@ -2087,9 +2102,8 @@ make, or the user didn't cancel the call." '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) @@ -2156,7 +2170,10 @@ make, or the user didn't cancel the call." (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"