1

I use display-buffer-alist to Configure buffer display. For example I have this snippet to display flycheck errors buffer.

(add-to-list 'display-buffer-alist
             `(,(rx bos "*Flycheck errors*" eos)
               (display-buffer-reuse-window
                display-buffer-below-selected)
               (reusable-frames . visible)
               (side            . bottom)
               (window-height   . 0.4)))

This works well, but when I want the same behaviour for the Messages buffer, it doesn't work. Why does this only work for certain buffers ?

And is it also possible to configure the display for buffers, that are opened by specific commands ? One example is shell-mode. When I open a new shell buffer, with another one already existing, my display modifications don't work because the name of the buffer is different.

  • Why are you using the second line to create "\\backtick\\*Flycheck errors\\*\\'" and are you do the same thing for the *Messages* buffer? It doesn't like like a correct regexp from my perspective, but I could be wrong? How about something simple like \\*flyckeck errors\\* or [*]flyckeck errors[*] – lawlist Nov 7 '16 at 15:43
  • I've also tried it that way. It doesn't make any difference. And I copied the second line from lunaryorns site. And if it works with the flycheck buffer why not with other buffers. – bertfred Nov 7 '16 at 16:04
  • I used re-builder to test your regexp and it did not highlight *Flycheck errors*, so I really have no idea how that regexp can work. In terms of why something works somewhere, but does not work elsewhere, it would help to know what it is that you expect to happen. It is possible that people looking at your code will draw a picture in their own mind, but it may help to spell it out for those of us who would like to help but would prefer not to guess -- just in case your code does always do what you expect to have occur. – lawlist Nov 7 '16 at 16:10
  • @lawlist You missed the rx. This is a regular expression in sexp form not a regular expression as string! The string "*Flycheck errors*" is taken literally. rx takes care of the escaping. – Tobias Nov 7 '16 at 16:13
  • 1
    Did you really try M-x (display-buffer "*Messages*")?? It works for me with your entry in display-buffer-alist and "*flycheck errors*" replaced by "*Messages*"! Could it be that you tried switch-to-buffer instead and expected the same effects as for display-buffer? They behave differently (at least for me). – Tobias Nov 7 '16 at 16:15
2

Citation of my comment:

Did you really try M-x (display-buffer "*Messages*")?? It works for me with your entry in display-buffer-alist and "*flycheck errors*" replaced by "*Messages*"! Could it be that you tried switch-to-buffer instead and expected the same effects as for display-buffer? They behave differently (at least for me).

And @bertfred's answer:

That was the problem. I have a custom function that displays the message buffer. However it works with eshell when I use

(defun switch-to-eshell () (interactive) (switch-to-buffer (eshell)))

eshell generates the buffer and shows it with pop-to-buffer-same-window which in turn calls pop-to-buffer and this calls display-buffer.

There are also occasions when switch-to-buffer calls pop-to-buffer. In that case your entries in display-buffer-alist become relevant. But normally, switch-to-buffer uses just the low-level routine set-buffer where the entries in display-buffer-alist are irrelevant.

Relevant citation from the help of switch-to-buffer:

If the selected window cannot display the specified buffer because it is a minibuffer window or strongly dedicated to another buffer, call ‘pop-to-buffer’ to select the buffer in another window. In interactive use, if the selected window is strongly dedicated to its buffer, the value of the option ‘switch-to-buffer-in-dedicated-window’ specifies how to proceed.


You also asked:

And is it also possible to configure the display for buffers, that are opened by specific commands ? One example is shell-mode. When I open a new shell buffer, with another one already existing, my display modifications don't work because the name of the buffer is different.

The documentation of generate-new-buffer-name describes how unique buffernames are generated:

generate-new-buffer-name is a built-in function in ‘C source code’.

(generate-new-buffer-name NAME &optional IGNORE)

Return a string that is the name of no existing buffer based on NAME. If there is no live buffer named NAME, then return NAME. Otherwise modify name by appending ‘<NUMBER>’, incrementing NUMBER (starting at 2) until an unused name is found, and then return that name. Optional second argument IGNORE specifies a name that is okay to use (if it is in the sequence to be tried) even if a buffer with that name exists.

If NAME begins with a space (i.e., a buffer that is not normally visible to users), then if buffer NAME already exists a random number is first appended to NAME, to speed up finding a non-existent buffer.

So (rx "SomeBufferName<" (one-or-more digit) ">") should do the job. Just replace SomeBufferName with the name of the first buffer of this special kind.

  • Thanks. That answers the first part of my question. Do you also know how I can keep this behaviour even if I've opened multiple buffers with the same command ? – bertfred Nov 7 '16 at 18:36
  • 1
    @bertfred Okay, I missed that one. Should be easy with regular expressions thou. – Tobias Nov 7 '16 at 18:43
  • Thanks for the effort. But I just found out that it is enough to remove the eos out of (rx bos "*Flycheck errors*" eos). rx.el seems to be really convenient. – bertfred Nov 7 '16 at 20:26

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.