I'm trying to find a way to quickly close the window that I just created by running 'grep' (i.e. a kind of compilation window).
I'd like the solution to be independent of my current window layout and also of which window that's currently in focus. This so I can always use the same keyboard shortcut.
I thought I could find an Emacs command to switch to the most recently created window, i.e. the one just created by 'grep'. Then I could just use that command followed by 'q' to close the 'grep' window. However, I haven't been able to find such a command.
Unfortunately the 'other-window' command (C-x o) doesn't work as well as I'd like in the following configuration. Here the Emacs frame is split into two windows (C-x 3) with the cursor in the right window (W2). I.e. it initially looks like this:
.-------.-------.
| W1 | W2 _ |
| | |
| | |
| | |
'-------'-------'
Then, after the grep command, it looks like this, with focus still on 'w2':
.-------.-------.
| W1 | W2 _ |
| | |
|-------| |
| *grep*| |
'-------'-------'
The annoyance is now that 'C-x o' switches to 'W1' rather than 'grep'.
Now, when I'm in 'W2' I can use e.g. 'C-- C-x o' to switch to 'grep'. But unfortunately, but if the cursor is instead in 'W1', then 'C-- C-x o' leaves me in 'W2' rather than 'grep'. So I'll then have to remember which command to use depending on my location.
Note: I could create a shortcut that closes the 'grep' window/buffer, but it'd be nice if the solution here works also for other compilation-like windows.
Update/clarification:
If the Emacs frame isn't as tall, e.g. on a laptop, this window setup:
.-------.-------.
| W1 | W2 _ |
| | |
'-------'-------'
results in 'W1' being replaced by 'grep' instead of a 'grep' window being added. I.e. it results in this:
.-------.-------.
| grep | W2 _ |
| | |
'-------'-------'
In this case, as some of the answers suggest deleting the 'grep' window, the resulting window setup ends up being this:
.---------------.
| W2 _ |
| |
'---------------'
So it turns out I don't necessarily/always want to delete the window containing the 'grep' buffer.