5

Is there a way to automatically switch focus to any new windows?

For example, if I C-h f some-function, that creates a new window. But the focus remains where I was, so when I'm done reading and hit q, I just type a q in whatever buffer I was in previously.

Ideally, I'd like to always switch focus to a new window whenever one is created.

Ideas?

  • How about delete-other-windows aka C-x 1 or delete-window aka C-x 0 -- gnu.org/software/emacs/manual/html_node/emacs/… There is a variable help-window-select for the *Help* buffer that controls whether you switch to it or not when it is displayed: emacs.stackexchange.com/a/3357/2287 Some, buffers like the *Help* buffer and the *Backtrace* buffer already have q set up to delete the window if it is selected. – lawlist Apr 22 '16 at 2:25
  • The author of each function that causes a particular window to be displayed has made a decision how that should work, and sometimes there are user options to alter that behavior. Most people aren't really interested in "taking the bull by the horns" by modifying the various functions to do what is desired -- in fact, I'm probably one of the only people in this forum who does that. Most people try to set up some rules in the display-buffer-alist using the things like the buffer-name to help control how and where windows are displayed. There is no hard set rule and there are exceptions. – lawlist Apr 22 '16 at 2:32
  • 1
    I recommend popwin or shackle for this. – InHarmsWay Apr 22 '16 at 3:09
  • 2
    For your example, (setq help-window-select t). – xuchunyang Apr 22 '16 at 8:37
1

Here is how to solve the problem. The problem you describe has two parts, really. One part is to change focus (like you describe), so the "q" is sent to the Help window. The second part is to get back to your original window.

I solved the issue by forcing the Help window to pop up over top of my current window, so that I can just type "q" to dispatch the help window and return to my original buffer. The method shown below can be extended to any of the usual whatever Apropos, Help, etc windows. Good luck.

(add-to-list 'display-buffer-alist '("*Apropos*" display-buffer-same-window)) (add-to-list 'display-buffer-alist '("*Help*" display-buffer-same-window))

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.