Commit 3c9c9d38 authored by Juri Linkov's avatar Juri Linkov
Browse files

* lisp/replace.el (perform-replace): Add `skip-read-only-count',

`skip-filtered-count', `skip-invisible-count' let-bound to 0.
Increment them for corresponding conditions and report the number
of skipped occurrences in the final message. 
(query-replace, query-replace-regexp, query-replace-regexp-eval)
(replace-string, replace-regexp): Doc fix.

Fixes: debbugs:11746
parent 38b787fa
2013-05-29 Juri Linkov <juri@jurta.org>
* replace.el (perform-replace): Add `skip-read-only-count',
`skip-filtered-count', `skip-invisible-count' let-bound to 0.
Increment them for corresponding conditions and report the number
of skipped occurrences in the final message. (Bug#11746)
(query-replace, query-replace-regexp, query-replace-regexp-eval)
(replace-string, replace-regexp): Doc fix.
2013-05-29 Stefan Monnier <monnier@iro.umontreal.ca> 2013-05-29 Stefan Monnier <monnier@iro.umontreal.ca>
   
* emacs-lisp/trace.el (trace--read-args): Provide a default. * emacs-lisp/trace.el (trace--read-args): Provide a default.
......
...@@ -250,6 +250,10 @@ letters. \(Transferring the case pattern means that if the old text ...@@ -250,6 +250,10 @@ letters. \(Transferring the case pattern means that if the old text
matched is all caps, or capitalized, then its replacement is upcased matched is all caps, or capitalized, then its replacement is upcased
or capitalized.) 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'.
If `replace-lax-whitespace' is non-nil, a space or spaces in the string 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 to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'. regexp in `search-whitespace-regexp'.
...@@ -300,6 +304,10 @@ pattern of the old text to the new text, if `case-replace' and ...@@ -300,6 +304,10 @@ pattern of the old text to the new text, if `case-replace' and
all caps, or capitalized, then its replacement is upcased or all caps, or capitalized, then its replacement is upcased or
capitalized.) 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'.
If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp 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 to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'. regexp in `search-whitespace-regexp'.
...@@ -380,6 +388,10 @@ that reads REGEXP. ...@@ -380,6 +388,10 @@ that reads REGEXP.
Preserves case in each replacement if `case-replace' and `case-fold-search' Preserves case in each replacement if `case-replace' and `case-fold-search'
are non-nil and REGEXP has no uppercase letters. 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'.
If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp 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 to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'. regexp in `search-whitespace-regexp'.
...@@ -470,6 +482,10 @@ are non-nil and FROM-STRING has no uppercase letters. ...@@ -470,6 +482,10 @@ are non-nil and FROM-STRING has no uppercase letters.
\(Preserving case means that if the string matched is all caps, or capitalized, \(Preserving case means that if the string matched is all caps, or capitalized,
then its replacement is upcased or capitalized.) 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'.
If `replace-lax-whitespace' is non-nil, a space or spaces in the string 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 to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'. regexp in `search-whitespace-regexp'.
...@@ -512,6 +528,10 @@ and TO-STRING is also null.)" ...@@ -512,6 +528,10 @@ and TO-STRING is also null.)"
Preserve case in each match if `case-replace' and `case-fold-search' Preserve case in each match if `case-replace' and `case-fold-search'
are non-nil and REGEXP has no uppercase letters. 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'.
If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp 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 to be replaced will match a sequence of whitespace chars defined by the
regexp in `search-whitespace-regexp'. regexp in `search-whitespace-regexp'.
...@@ -1934,6 +1954,9 @@ make, or the user didn't cancel the call." ...@@ -1934,6 +1954,9 @@ make, or the user didn't cancel the call."
(keep-going t) (keep-going t)
(stack nil) (stack nil)
(replace-count 0) (replace-count 0)
(skip-read-only-count 0)
(skip-filtered-count 0)
(skip-invisible-count 0)
(nonempty-match nil) (nonempty-match nil)
(multi-buffer nil) (multi-buffer nil)
(recenter-last-op nil) ; Start cycling order with initial position. (recenter-last-op nil) ; Start cycling order with initial position.
...@@ -2042,20 +2065,24 @@ make, or the user didn't cancel the call." ...@@ -2042,20 +2065,24 @@ make, or the user didn't cancel the call."
(and (/= (nth 0 match) (nth 1 match)) (and (/= (nth 0 match) (nth 1 match))
match)))))) match))))))
;; Optionally ignore matches that have a read-only property. (cond
(when (and (or (not query-replace-skip-read-only) ;; Optionally ignore matches that have a read-only property.
(not (text-property-not-all ((not (or (not query-replace-skip-read-only)
(nth 0 real-match-data) (nth 1 real-match-data) (not (text-property-not-all
'read-only nil))) (nth 0 real-match-data) (nth 1 real-match-data)
;; Optionally filter out matches. 'read-only nil))))
(run-hook-with-args-until-failure (setq skip-read-only-count (1+ skip-read-only-count)))
'isearch-filter-predicates ;; Optionally filter out matches.
(nth 0 real-match-data) (nth 1 real-match-data)) ((not (run-hook-with-args-until-failure
;; Optionally ignore invisible matches. 'isearch-filter-predicates
(or (eq search-invisible t) (nth 0 real-match-data) (nth 1 real-match-data)))
(not (isearch-range-invisible (setq skip-filtered-count (1+ skip-filtered-count)))
(nth 0 real-match-data) (nth 1 real-match-data))))) ;; Optionally ignore invisible matches.
((not (or (eq search-invisible t)
(not (isearch-range-invisible
(nth 0 real-match-data) (nth 1 real-match-data)))))
(setq skip-invisible-count (1+ skip-invisible-count)))
(t
;; Calculate the replacement string, if necessary. ;; Calculate the replacement string, if necessary.
(when replacements (when replacements
(set-match-data real-match-data) (set-match-data real-match-data)
...@@ -2260,13 +2287,31 @@ make, or the user didn't cancel the call." ...@@ -2260,13 +2287,31 @@ make, or the user didn't cancel the call."
(match-end 0) (match-end 0)
(current-buffer)) (current-buffer))
(match-data t))) (match-data t)))
stack))))) stack))))))
(replace-dehighlight)) (replace-dehighlight))
(or unread-command-events (or unread-command-events
(message "Replaced %d occurrence%s" (message "Replaced %d occurrence%s%s"
replace-count replace-count
(if (= replace-count 1) "" "s"))) (if (= replace-count 1) "" "s")
(if (> (+ skip-read-only-count
skip-filtered-count
skip-invisible-count) 0)
(format " (skipped %s)"
(mapconcat
'identity
(delq nil (list
(if (> skip-read-only-count 0)
(format "%s read-only"
skip-read-only-count))
(if (> skip-invisible-count 0)
(format "%s invisible"
skip-invisible-count))
(if (> skip-filtered-count 0)
(format "%s filtered out"
skip-filtered-count))))
", "))
"")))
(or (and keep-going stack) multi-buffer))) (or (and keep-going stack) multi-buffer)))
;;; replace.el ends here ;;; replace.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment