I have this code:
(defun my-test ()
(interactive)
(save-excursion
(let ((inhibit-quit t))
(with-local-quit
(goto-char (point-min))
(while (search-forward "foo" nil t)
(let ((b (copy-marker (match-beginning 0)))
(e (copy-marker (match-end 0))))
(query-replace "foo" "bar" nil b e))))
(setq quit-flag nil)
(goto-char (point-min))
(while (search-forward "bar" nil t)
(let ((b (copy-marker (match-beginning 0)))
(e (copy-marker (match-end 0))))
(query-replace "bar" "foo" nil b e))))))
My purpose is to have the option to quit, with C-g
, the first loop without ending the function execution. The code works but it seems a little strange to me the need to setting quit-flag
to nil
after the with-local-quit
macro.
I'm doing it in the right way?
The info on https://www.gnu.org/software/emacs/manual/html_node/elisp/Quitting.html are not clear to me (but I have my limits).