emacscollective / borg

Assimilate Emacs packages as Git submodules
https://emacsmirror.net/manual/borg
GNU General Public License v3.0
255 stars 28 forks source link

Disabling display of the `borg-build-mode` buffer #145

Closed grtcdr closed 1 year ago

grtcdr commented 1 year ago

Hi Jonas,

Many of us use display-buffer-alist to modify the placement of our windows. I expected I'd be able to hide *Borg Build* buffers [^1], but that doesn't work with either of the following configurations:

;; Using a regular expression:
(setq display-buffer-alist
   '(("\\*Borg Build\\*"
      (display-buffer-no-window)))

;; Using cons cells:
(setq display-buffer-alist
   '((major-mode . borg-build-mode)
     (display-buffer-no-window)))

I expect this is happening because borg--build-interactive isn't directly using display-buffer but other buffer display functions that hardcode its window placement. Would you be open to relying on display-buffer instead?

Thank you for your time and work,

[^1]: It's unlikely that I'd shutdown Emacs while the process is still running, and even then, Emacs will warn me in the presence of a running process or an unsaved buffer because I've configured the user service to shutdown via (save-buffers-kill-emacs).

tarsius commented 1 year ago

borg--build-interactive calls pop-to-buffer-same-window, which just calls pop-to-buffer while specifying an ACTION. That calls display-buffer, passing ACTION along, and if, and only if, that returns a window, it additionally selects that.

The docstring of display-buffer contains (emphasis mine):

display-buffer builds a list of action functions and an action alist by combining any action functions and alists specified by display-buffer-overriding-action, display-buffer-alist, the ACTION argument, display-buffer-base-action, and display-buffer-fallback-action (in order).

So display-buffer-alist overrides the ACTION argument, rendering your request moot. Your goal can be accomplished without requiring any changes to Borg.

Your second approach won't work in this case because the mode is set after displaying the buffer. (That may be something I should change.)

The problem with your first approach is that specifying the "do nothing" action is not enough. Additionally you have to specify that it is okay for an action to do nothing: :stuck_out_tongue_winking_eye:, i.e.:

(setq display-buffer-alist
      '(("\\`\\*Borg Build\\*\\'"
         display-buffer-no-window
         (allow-no-window . t))))
grtcdr commented 1 year ago

Thanks for that eye-opening explanation and for the solution. It worked for me :)

That may be something I should change

That would be a very welcome change, actually, since cons cells are much more readable (to me at least).

tarsius commented 1 year ago

The major-mode is now set before the buffer is displayed.

grtcdr commented 1 year ago

Thanks for that.

tarsius commented 1 year ago

You're welcome!