如何强制Emacs不在特定窗口中显示缓冲区?

时间:2009-06-16 15:05:44

标签: emacs lisp elisp advising-functions

我的Windows配置如下所示:

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

我使用右下方窗口进行特殊显示(如帮助,完成等),但是当我调用使用find-file-other-window的命令(display-buffer等)时,emacs坚持使用该窗口,并调整该窗口的大小。这很烦人...有没有办法可以强制emacs不要使用那个窗口?我在考虑建议display-buffer,但这是c中的一个功能。有什么想法吗?

编辑:

在很大程度上基于Trey的回答,这对我来说是有用的:

(setq special-display-function 'my-display-buffer)
(setq special-display-regexps '(".*"))

(defun display-special-buffer (buf)
  "put the special buffers in the right spot (bottom rigt)"
    (let ((target-window (window-at (- (frame-width) 4) (- (frame-height) 4)))
          (pop-up-windows t))
      (set-window-buffer target-window buf)
      target-window))

(defun my-display-buffer (buf)
  "put all buffers in a window other than the one in the bottom right"
  (message (buffer-name  buf))
  (if (member (buffer-name buf) special-display-buffer-names)
      (display-special-buffer buf)
      (progn
        (let ((pop-up-windows t)
              (windows (delete (window-at (- (frame-width) 4) (- (frame-height) 4))
                         (delete (minibuffer-window) (window-list)))))
          (message (buffer-name (window-buffer (car windows))))
          (set-window-buffer (car (cdr windows)) buf)
          (car (cdr windows))))))

4 个答案:

答案 0 :(得分:18)

好吧,有人已经问过same question for completion。我写了answer似乎运作得很好。

看起来您可以使用相同的解决方案,除了添加到special-display-buffer-names之外,您可以使用变量special-display-regexps。所以有些东西:

(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)))))

显然,你必须修改正则表达式,使其与右下窗口中你想要的*Help*和其他缓冲区不匹配。

关于建议display-buffer,这可行。您可以建议使用c编写的函数,建议几乎可以在您想要的每种情况下使用,除非函数从c中调用,或者建议使用宏(这不适用于b / c宏通常是已经扩展到任何地方使用它们。

答案 1 :(得分:3)

也许这样的事情可行:

(defun display-buffer-avoiding-lr-corner (buffer &optional not-this-window)
  (save-selected-window
    (when (buffer-file-name buffer)
      (select-window (window-at (- (frame-width) 1)
                                (- (frame-height) 2))))
    (let ((display-buffer-function nil))
      (display-buffer buffer not-this-window))))

(setq display-buffer-function 'display-buffer-avoiding-lr-corner)

答案 2 :(得分:2)

  

我正在考虑建议显示缓冲区,但它是c中的一个函数。

"display-buffer is an interactive Lisp function in `window.el'."

此外,无论如何,您都可以建议C函数。

答案 3 :(得分:2)

也许你有必要让set-window-dedicated-p专用的右下窗口。然后,您可以根据需要在find-file-other-window等操作中忽略此窗口。