如何让这个Emacs框架保持其缓冲区而不是调整大小?

时间:2011-03-01 07:30:09

标签: emacs

我的Emacs框架如下所示:

+---------------------------+
|             |             |
|             |             |
|             |      B      |
|      A      |             |
|             |             |
|             |             |
|             |-------------|
|             |      C      |
+---------------------------+

C通常是一个具有某种长时间运行过程的终端,如Web服务器或守护进程。不幸的是,各种各样的事情都喜欢在那个窗口中切换缓冲区,偶尔会调整大小。如何锁定窗口C的缓冲区和高度?

4 个答案:

答案 0 :(得分:12)

如果您不想被窗口窃取和调整大小烦恼,请在.emacs中添加以下行以获得最终解决方案,即使像gud这样的库会尝试打开新框架偷你的窗户

(有关以下advice)的信息,请参阅this answer

(defadvice pop-to-buffer (before cancel-other-window first)
  (ad-set-arg 1 nil))

(ad-activate 'pop-to-buffer)

;; Toggle window dedication
(defun toggle-window-dedicated ()
  "Toggle whether the current active window is dedicated or not"
  (interactive)
  (message
   (if (let (window (get-buffer-window (current-buffer)))
         (set-window-dedicated-p window 
                                 (not (window-dedicated-p window))))
       "Window '%s' is dedicated"
     "Window '%s' is normal")
   (current-buffer)))

;; Press [pause] key in each window you want to "freeze"
(global-set-key [pause] 'toggle-window-dedicated)

并将pop-up-windows变量自定义为nil

您也可以使用StickyWindows代替窗口专用功能。

答案 1 :(得分:11)

一种可能性是使用set-window-dedicated-p 将窗口专用于其缓冲区。这不会阻止窗口手动调整大小,只能防止窗口被display-buffer破坏。例如,

(add-hook 'shell-mode-hook
      (lambda ()
        (interactive)
        (set-window-dedicated-p (selected-window) 1)))

根据需要替换shell-mode-hook

答案 2 :(得分:1)

您可以使用winner-mode将更改撤消为窗口大小。

你也可以explicitly save and restore the window configuration in registers

答案 3 :(得分:1)

这个也适用(对于emacs 24)https://lists.gnu.org/archive/html/help-gnu-emacs/2007-05/msg00975.html

(define-minor-mode sticky-buffer-mode
  "Make the current window always display this buffer."
  nil " sticky" nil
  (set-window-dedicated-p (selected-window) sticky-buffer-mode))