我希望实现编译缓冲区自动折叠为小尺寸(但不会在删除窗口时关闭),这样,在成功编译后,窗口会缩小到最小尺寸。
get-buffer-create
返回一个缓冲区。如何在与该缓冲区关联的窗口上使用 shrink-window
?还有一种方法可以存储先前的窗口大小吗?
这是我第一次尝试emacs lisp编程,感谢您的帮助。
这导致一个像这样的解决方案:当编译过程完成时调用的函数列表。 每个函数都带有两个参数:编译缓冲区和描述进程如何完成的字符串。
(add-hook 'compilation-finish-functions 'my-compilation-finish-function)
(defun my-compilation-finish-function (buffer resstring)
"Shrink the window if the process finished successfully."
(let ((compilation-window-height (if (string-match-p "finished" resstring) 5 nil)))
(compilation-set-window-height (get-buffer-window buffer 0))))
(defadvice compilation-handle-exit (around my-compilation-handle-exit-shrink-height activate)
(let ((compilation-window-height (if (zerop (car (ad-get-args 1))) 5 nil)))
(compilation-set-window-height (get-buffer-window (current-buffer) 0))
ad-do-it))
*compilation*
窗口,则在失败时它不会被调整为更大的尺寸。如果您想要调整大小,您需要指定一个高度而不是nil
。也许这会符合您的喜好(更改第一个示例):(if (string-match-p "finished" resstring) 5 (/ (frame-height) 2))
nil
"被替换为"(/ (frame-height) 2)
"。