Commit b591f338 authored by Juri Linkov's avatar Juri Linkov
Browse files

(multi-query-replace-map): New variable.

(perform-replace): Add processing of new multi-buffer keys bound
to `automatic-all' and `exit-current'.  Set `query-flag' to nil
if last input char was `automatic-all'.  Set new local variable
`multi-buffer' to t when one of new two keys were typed.  Return
non-nil value of `multi-buffer' that tells to calling functions
to continue replacement on the next file.
parent 4542adfb
...@@ -1372,6 +1372,20 @@ The valid answers include `act', `skip', `act-and-show', ...@@ -1372,6 +1372,20 @@ The valid answers include `act', `skip', `act-and-show',
`exit', `act-and-exit', `edit', `delete-and-edit', `recenter', `exit', `act-and-exit', `edit', `delete-and-edit', `recenter',
`automatic', `backup', `exit-prefix', and `help'.") `automatic', `backup', `exit-prefix', and `help'.")
(defvar multi-query-replace-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map query-replace-map)
(define-key map "Y" 'automatic-all)
(define-key map "N" 'exit-current)
map)
"Keymap that defines additional bindings for multi-buffer replacements.
It extends its parent map `query-replace-map' with new bindings to
operate on a set of buffers/files. The difference with its parent map
is the additional answers `automatic-all' to replace all remaining
matches in all remaining buffers with no more questions, and
`exit-current' to skip remaining matches in the current buffer
and to continue with the next buffer in the sequence.")
(defun replace-match-string-symbols (n) (defun replace-match-string-symbols (n)
"Process a list (and any sub-lists), expanding certain symbols. "Process a list (and any sub-lists), expanding certain symbols.
Symbol Expands To Symbol Expands To
...@@ -1527,6 +1541,7 @@ make, or the user didn't cancel the call." ...@@ -1527,6 +1541,7 @@ make, or the user didn't cancel the call."
(stack nil) (stack nil)
(replace-count 0) (replace-count 0)
(nonempty-match nil) (nonempty-match nil)
(multi-buffer nil)
;; If non-nil, it is marker saying where in the buffer to stop. ;; If non-nil, it is marker saying where in the buffer to stop.
(limit nil) (limit nil)
...@@ -1548,6 +1563,11 @@ make, or the user didn't cancel the call." ...@@ -1548,6 +1563,11 @@ make, or the user didn't cancel the call."
(goto-char (min start end)) (goto-char (min start end))
(deactivate-mark)) (deactivate-mark))
;; If last typed key in previous call of multi-buffer perform-replace
;; was `automatic-all', don't ask more questions in next files
(when (eq (lookup-key map (vector last-input-char)) 'automatic-all)
(setq query-flag nil multi-buffer t))
;; REPLACEMENTS is either a string, a list of strings, or a cons cell ;; REPLACEMENTS is either a string, a list of strings, or a cons cell
;; containing a function and its first argument. The function is ;; containing a function and its first argument. The function is
;; called to generate each replacement like this: ;; called to generate each replacement like this:
...@@ -1705,6 +1725,8 @@ make, or the user didn't cancel the call." ...@@ -1705,6 +1725,8 @@ make, or the user didn't cancel the call."
((eq def 'exit) ((eq def 'exit)
(setq keep-going nil) (setq keep-going nil)
(setq done t)) (setq done t))
((eq def 'exit-current)
(setq multi-buffer t keep-going nil done t))
((eq def 'backup) ((eq def 'backup)
(if stack (if stack
(let ((elt (pop stack))) (let ((elt (pop stack)))
...@@ -1744,14 +1766,15 @@ make, or the user didn't cancel the call." ...@@ -1744,14 +1766,15 @@ make, or the user didn't cancel the call."
real-match-data (replace-match-data real-match-data (replace-match-data
t real-match-data) t real-match-data)
replaced t))) replaced t)))
((eq def 'automatic) ((or (eq def 'automatic) (eq def 'automatic-all))
(or replaced (or replaced
(setq noedit (setq noedit
(replace-match-maybe-edit (replace-match-maybe-edit
next-replacement nocasify literal next-replacement nocasify literal
noedit real-match-data) noedit real-match-data)
replace-count (1+ replace-count))) replace-count (1+ replace-count)))
(setq done t query-flag nil replaced t)) (setq done t query-flag nil replaced t)
(if (eq def 'automatic-all) (setq multi-buffer t)))
((eq def 'skip) ((eq def 'skip)
(setq done t)) (setq done t))
((eq def 'recenter) ((eq def 'recenter)
...@@ -1838,7 +1861,7 @@ make, or the user didn't cancel the call." ...@@ -1838,7 +1861,7 @@ make, or the user didn't cancel the call."
(message "Replaced %d occurrence%s" (message "Replaced %d occurrence%s"
replace-count replace-count
(if (= replace-count 1) "" "s"))) (if (= replace-count 1) "" "s")))
(and keep-going stack))) (or (and keep-going stack) multi-buffer)))
(defvar replace-overlay nil) (defvar replace-overlay nil)
......
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