4

I have this notification system in emacs that opens a new buffer with a reminder and relevant info at specified times. However, if I am using my browser I can't see it.

Therefore I am wondering whether it is possible to open a new emacs frame that steals the focus from other apps?

  • Is it possible to steal the focus from other apps in general, without creating a new frame? If there was a variable for the current frame, (select-frame-set-input-focus current-frame-variable) could be used. This would be super neat for this package I'm thinking of creating. – The Unfun Cat Feb 28 '15 at 8:16
  • 1
    There is: (select-frame-set-input-focus (selected-frame)) I love you emacs!!!! – The Unfun Cat Feb 28 '15 at 8:20
1

This should work:

(run-with-timer
 3 nil
 (lambda ()
   (select-frame-set-input-focus (new-frame)))) 
1

What @abo-abo says is almost enough to do what you want (since you explicitly ask not only that the frame be shown on top but also that it be focused).

What it leaves out is that raising a frame does not necessarily focus it (select it for input focus). The behavior can depend on your window manager.

On MS Windows, you can set or bind variable w32-grab-focus-on-raise to cause raising to always also focus.

And you can add a call to select-frame-set-input-focus to your code. That explicitly focuses the frame.

  • The last line did the trick. UV. – The Unfun Cat Feb 28 '15 at 8:10
  • I accepted abo-abos answer since he was first, but your help and comments were much appreciated. Is this yours: emacswiki.org/emacs/frame-fns.el ? I leafed through it and it improved my understanding of how frames work greatly. Thanks. – The Unfun Cat Feb 28 '15 at 8:22
  • You did the right thing - my post was meant to complement @abo-abo's. And yes, hope it helps. – Drew Feb 28 '15 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.