Skip to main content
added 107 characters in body
Source Link
Gabriele
  • 1.7k
  • 11
  • 22

I have this function:

(defun my-replacements ()
  (interactive)
  (query-replace "foo" "bar" nil (point-min) (point-max))
  (query-replace "baz" "quz" nil (point-min) (point-max))
  (query-replace "fred" "thud" nil (point-min) (point-max)))

If I run it and accidentally type, for example, 'k' during one of the replacements, the function is interrupted, skipping all the remaining replacements.

I know that query-replace accepts only events binded in the query-replace-map and from the manual I know that:

Aside from this, any other character exits the query-replace, and is then reread as part of a key sequence. Thus, if you type C-k, it exits the query-replace and then kills to end of line. In particular, C-g simply exits the query-replace.

I would like to circumvent this behavior by ensuring that events not defined in the query-replace-map are simply ignored. Is there a way to achieve this?

I thought it could be done with a macro, e.g.:

(with-ignore-qr-unbinded-events
  MY CODE HERE)

but I have no idea how to do it.

As a feature request, I would like to add an optional argument to the function so that I can have control over this behavior. Does it make sense to you?

Edit. I just realized that a better idea would be using a variable to control this feature I request.

I have this function:

(defun my-replacements ()
  (interactive)
  (query-replace "foo" "bar" nil (point-min) (point-max))
  (query-replace "baz" "quz" nil (point-min) (point-max))
  (query-replace "fred" "thud" nil (point-min) (point-max)))

If I run it and accidentally type, for example, 'k' during one of the replacements, the function is interrupted, skipping all the remaining replacements.

I know that query-replace accepts only events binded in the query-replace-map and from the manual I know that:

Aside from this, any other character exits the query-replace, and is then reread as part of a key sequence. Thus, if you type C-k, it exits the query-replace and then kills to end of line. In particular, C-g simply exits the query-replace.

I would like to circumvent this behavior by ensuring that events not defined in the query-replace-map are simply ignored. Is there a way to achieve this?

I thought it could be done with a macro, e.g.:

(with-ignore-qr-unbinded-events
  MY CODE HERE)

but I have no idea how to do it.

As a feature request, I would like to add an optional argument to the function so that I can have control over this behavior. Does it make sense to you?

I have this function:

(defun my-replacements ()
  (interactive)
  (query-replace "foo" "bar" nil (point-min) (point-max))
  (query-replace "baz" "quz" nil (point-min) (point-max))
  (query-replace "fred" "thud" nil (point-min) (point-max)))

If I run it and accidentally type, for example, 'k' during one of the replacements, the function is interrupted, skipping all the remaining replacements.

I know that query-replace accepts only events binded in the query-replace-map and from the manual I know that:

Aside from this, any other character exits the query-replace, and is then reread as part of a key sequence. Thus, if you type C-k, it exits the query-replace and then kills to end of line. In particular, C-g simply exits the query-replace.

I would like to circumvent this behavior by ensuring that events not defined in the query-replace-map are simply ignored. Is there a way to achieve this?

I thought it could be done with a macro, e.g.:

(with-ignore-qr-unbinded-events
  MY CODE HERE)

but I have no idea how to do it.

As a feature request, I would like to add an optional argument to the function so that I can have control over this behavior. Does it make sense to you?

Edit. I just realized that a better idea would be using a variable to control this feature I request.

edited tags
Link
Drew
  • 79.1k
  • 10
  • 123
  • 257
Source Link
Gabriele
  • 1.7k
  • 11
  • 22

query-replace: ignore events not binded in query-replace-map

I have this function:

(defun my-replacements ()
  (interactive)
  (query-replace "foo" "bar" nil (point-min) (point-max))
  (query-replace "baz" "quz" nil (point-min) (point-max))
  (query-replace "fred" "thud" nil (point-min) (point-max)))

If I run it and accidentally type, for example, 'k' during one of the replacements, the function is interrupted, skipping all the remaining replacements.

I know that query-replace accepts only events binded in the query-replace-map and from the manual I know that:

Aside from this, any other character exits the query-replace, and is then reread as part of a key sequence. Thus, if you type C-k, it exits the query-replace and then kills to end of line. In particular, C-g simply exits the query-replace.

I would like to circumvent this behavior by ensuring that events not defined in the query-replace-map are simply ignored. Is there a way to achieve this?

I thought it could be done with a macro, e.g.:

(with-ignore-qr-unbinded-events
  MY CODE HERE)

but I have no idea how to do it.

As a feature request, I would like to add an optional argument to the function so that I can have control over this behavior. Does it make sense to you?