2

How to set up Emacs so that once one "help" window (e.g. describe, info, man) is displayed, all subsequent "help" buffers open in the same window?

For example, if I open a describe-function buffer and then click on the link to find the function's definition, it opens in the same window, rather than opening in a (now different) other window.

Edit:

One way to just about get what I want is:

(setq display-buffer-alist
      `((,(rx bos (or "*Apropos*" "*Help*" "*helpful" "*info*" "*Summary*") (0+ not-newline))
         (display-buffer-reuse-mode-window display-buffer-pop-up-window)
         (mode apropos-mode help-mode helpful-mode Info-mode Man-mode))))

My remaining questions are:

  1. Is there a simpler way to do it?
  2. Is there a way to ensure that the help window is selected?
mnewt
  • 258
  • 2
  • 9
  • Possible duplicate of [How to make man replace the same buffer?](https://emacs.stackexchange.com/questions/45174/how-to-make-man-replace-the-same-buffer) – manandearth Nov 25 '18 at 17:57
  • Thanks for the link but it's not the same. I want to reuse the same window but not kill the buffer. – mnewt Nov 25 '18 at 20:10
  • It is not a full answer, but I just don't have a reputation for putting this into a comment. Following variable might be also relevant `switch-to-buffer-preserve-window-point nil`. I had some troubles with buffers and windows after migrated to emacs26. – stlk Jan 09 '19 at 23:52

1 Answers1

1

Make *Help* use a dedicated window.

One easy way to do this is to customize option special-display-buffer-names to add "*Help*" to the list value. Takes about 20 seconds...


(And yes, I don't support the idea that this option is "obsolete", personally. It should continue to be supported forever, just like the other special-display-* options. That we now have a fine general tool for doing this and much more, display-buffer-alist is not a good reason to forego the simple, easy-to-use special-display-* options. Just one opinion.)


C-h v special-display-buffer-names:

List of names of buffers that should be displayed specially.

Displaying a buffer with display-buffer or pop-to-buffer, if its name is in this list, displays the buffer in a way specified by special-display-function. special-display-popup-frame (the default for special-display-function) usually displays the buffer in a separate frame made with the parameters specified by special-display-frame-alist. If special-display-function has been set to some other function, that function is called with the buffer as first, and nil as second argument.

Alternatively, an element of this list can be specified as (BUFFER-NAME FRAME-PARAMETERS), where BUFFER-NAME is a buffer name and FRAME-PARAMETERS an alist of (PARAMETER . VALUE) pairs. special-display-popup-frame will interpret such pairs as frame parameters when it creates a special frame, overriding the corresponding values from special-display-frame-alist.

As a special case, if FRAME-PARAMETERS contains (same-window . t) special-display-popup-frame displays that buffer in the selected window. If FRAME-PARAMETERS contains (same-frame . t), it displays that buffer in a window on the selected frame.

If special-display-function specifies some other function than special-display-popup-frame, that function is called with the buffer named BUFFER-NAME as first, and FRAME-PARAMETERS as second argument.

Finally, an element of this list can be also specified as (BUFFER-NAME FUNCTION OTHER-ARGS). In that case, special-display-popup-frame will call FUNCTION with the buffer named BUFFER-NAME as first argument, and OTHER-ARGS as the second.

Any alternative function specified here is responsible for setting up the quit-restore parameter of the window used.

If this variable appears "not to work", because you added a name to it but the corresponding buffer is displayed in the selected window, look at the values of same-window-buffer-names and same-window-regexps. Those variables take precedence over this one.

See also special-display-regexps.

You can customize this variable.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Thanks for this. I fear I'm being dense but I don't get how this solves the problem. If I add `"*Help*"` to `special-display-buffer-names`, nothing seems to change. First help buffer pops to a new window, subsequent help buffer pops to a different window. Are you suggesting writing a custom `special-display-function` which takes care of the logic of identifying help buffers, or is there some more straightforward way to do it? – mnewt Dec 10 '18 at 06:20
  • I don't understand. Try starting Emacs with `emacs -Q` (no init file). Then `M-x customize-option special-display-buffer-names`. Then click `INS` and insert the text `*Help*` (no `"` chars). Then set that value for the current session (or save it for future settings, if you want). You should then get only one `*Help*` window/buffer, which gets reused. – Drew Dec 10 '18 at 14:36
  • I am not getting the same result. When I follow your steps, I get help buffers in a separate frame, as I would expect since the default value of `special-display-function` is `special-display-popup-frame`. Is there some built in function that I should assign it to that would create or reuse a window in the same frame? – mnewt Dec 11 '18 at 21:21
  • If you already have buffer `*Help*` displayed in a given frame the Emacs uses its window. If you do not then it displays `*Help*` in a separate frame. `emacs -Q` `C-h v special-display-buffer-names` splits the initial window, showing `*Help*` in the second window. Then setting (e.g. customizing) the variable makes Emacs reuse that `*Help*` window, instead of showing it in a separate frame. It behaves exactly like the doc says it does. – Drew Dec 12 '18 at 00:51