2

I have a background process which when finishes switches to a specific buffer. I don't want this process to interrupt my current isearch if I'm doing one, so I'd like to test if an isearch is in progress, and delay switching to that buffer if it is the case.

How can I do this? I tried checking this-command from the process handler, but it is nil for some reason even if I'm in an isearch.

Drew
  • 77,472
  • 10
  • 114
  • 243
Tom
  • 1,260
  • 8
  • 16

1 Answers1

2

I tried checking this-command from the process handler, but it is nil for some reason even if I'm in an isearch.

This is because the isearch process is not one command, but a series of commands. Each time you type C-s (for instance) during an isearch, that's an independent trip around the command loop.

The buffer-local variable isearch-mode is non-nil while an isearch is in process in a given buffer, and set to nil again by isearch-done, so simply checking that variable in the selected window's buffer is probably sufficient.

You could also use isearch-mode-hook and isearch-mode-end-hook to track the state, but I suspect that's unnecessary.

phils
  • 50,977
  • 3
  • 79
  • 122