How to force Emacs not to display buffer in a specific window?

前端 未结 4 1826
小鲜肉
小鲜肉 2020-12-12 23:05

My windows configuration looks like this:

          +----------+-----------+
      |          |           |
      |          |           |
      |          |         


        
4条回答
  •  渐次进展
    2020-12-12 23:18

    Well, someone already asked the same question for completion. And I wrote up an answer that seemed to work pretty well.

    It looks like you could use that same solution, except instead of adding to special-display-buffer-names, you can use the variable special-display-regexps. So something along the lines of:

    (add-to-list 'special-display-regexps '(".*" my-display-buffers))
    
    (defun my-display-buffers (buf)
      "put all buffers in a window other than the one in the bottom right"
      (let ((windows (delete (window-at (- (frame-width) 2) (- (frame-height) 4))
                             (delete (minibuffer-window) (window-list))))
        (if (<= 2 (length windows))
            (progn 
              (select-window (cadr windows))
              (split-window-vertically)))
        (let ((pop-up-windows t))
          (set-window-buffer (car windows) buf)
          (car windows)))))
    

    Obviously you'll have to modify the regexp to not match the *Help* and other buffers that you actually want in the lower right window.

    Regarding advising display-buffer, that would work. You can advise functions written in c, advice works in pretty much every case you'd want except when functions are called from c, or advising macros (which doesn't work b/c the macros are generally already expanded everywhere they're used).

提交回复
热议问题