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

标签 emacs lisp elisp advising-functions

我的 windows 配置如下所示:

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

我使用右下角的窗口进行特殊显示(如帮助、完成等),但是当我调用命令时 emacs 坚持使用该窗口(find-file-other-window 等) .) 使用 display-buffer,并调整该窗口的大小。这很烦人......有没有办法强制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))))))

最佳答案

嗯,已经有人问过 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 宏通常是已经扩展到所有使用它们的地方)。

关于emacs - 如何强制 Emacs 不在特定窗口中显示缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1002091/

相关文章:

emacs - 如何在 Emacs 中使用不同的键选择文本?

emacs 模式特定的自定义键绑定(bind) : local-set-key vs define-key

Emacs 颜色。为什么它在当前行是灰色的?禅本主题

emacs - 自动备份服务器上的 emacs 文件编辑

lisp - 在 Lisp 中将数字从某个基数转换为基数 10

lisp - 如何在 LISP 中不递归两次

emacs - 如何在与latexmk兼容的elisp中测试当前文件是否已更改

python - Emacs defadvice on python-mode 函数

html - CL-WHO HTML 生成器到文件

emacs - 使 Windows 路径在 Emacs Lisp 中有用