I'm trying to write a little compilation monitor frame that gets compilation updates written to it without the overhead of seeing absolutely everything going on in the compile. I've been working with frames a little bit, and it's mostly a huge pain.
I'd like to figure out if the frame that I'm creating exists yet. I've come up with two ways to do that:
1) Loop through all the frames in (frame-list) and do a string match on the title.
2) This doofy bit of code:
(if (not (select-frame-by-name "COMPILATION MONITOR"))
(selected-frame)
(print "ERROR" (get-buffer "*monitor*"))))
select-frame-by-name returns an error if it can't find a frame, which isn't actually a value, as near as I can tell. It just quietly exits. But if it DOES find the frame that I want, it returns nil, and focuses the frame. (Then I can return the frame if I need it using 'selected-frame'. Ignore the error reporting to my buffer--that's not terribly relevant here.)
Is there some better way? With buffers, I can use get-buffer-create to create something new if it doesn't exist and use it if it does. Am I missing something in frame creation? Maybe what I need to know is how the error handling code works, so I can catch the error that select-frame-by-name throws when it can't find what I want?
get-frame-name
andget-a-frame
. For a more complex example of creating/locating/targeting specific frames with buffers, see the following related thread entitled How to intercept a file before it opens and decide which frame: stackoverflow.com/questions/18346785/… – lawlist Dec 23 '15 at 19:21get-a-frame
does what you want. – Drew Dec 24 '15 at 17:34