如何强制 Emacs 不在特定窗口中显示缓冲区? [英] How to force Emacs not to display buffer in a specific window?

查看:23
本文介绍了如何强制 Emacs 不在特定窗口中显示缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 配置如下所示:

My windows configuration looks like this:

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

我使用右下方的窗口进行特殊显示(如帮助、完成等),但 emacs 坚持在我调用命令时使用该窗口(find-file-other-window 等).) 使用 display-buffer,并调整该窗口的大小.这很烦人......有没有办法强制emacs不使用该窗口?我正在考虑为 display-buffer 提供建议,但它是 c 中的一个函数.对此有何想法?

And I use the lower right window for special displays (like help, completion etc.), but emacs insists on using that window when I call commands (find-file-other-window, etc.) that use display-buffer, and resize that window as well. It's annoying... Is there a way that I can force emacs NOT to use that windows? I was thinking of advising display-buffer, but it's a function in c. Any thoughts on this?

主要基于 Trey 的回答,到目前为止,这对我有用:

Based heavily on Trey's answer, this is what works for me so far:

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

推荐答案

嗯,已经有人问过 同样的完成问题.我写了一个 answer这似乎工作得很好.

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

看起来您可以使用相同的解决方案,除了可以使用变量 special-display-regexps 而不是添加到 special-display-buffer-names.所以类似的东西:

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

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

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.

关于建议 display-buffer,那是可行的.您可以建议用 c 编写的函数,建议几乎适用于您想要的所有情况,除非从 c 中调用函数或建议宏(这在 b/c 中不起作用,宏通常是已经在所有使用它们的地方扩展).

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

这篇关于如何强制 Emacs 不在特定窗口中显示缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆