emacs 以编程方式更改窗口大小

发布于 2024-08-20 07:25:54 字数 205 浏览 3 评论 0原文

我想实现编译缓冲区自动折叠为小尺寸(但不在删除窗口时关闭),以便在成功编译到窗口后缩小到最小尺寸。

get-buffer-create 返回一个缓冲区。如何在与该缓冲区关联的窗口上shr​​ink-window?另外,有没有办法存储以前的窗口大小?

这是我第一次尝试 emacs lisp 编程,谢谢你的帮助。

I would like to implement automatic collapse of compilation buffer to small size (but not close at a delete windows), such that upon successful compilation to window is shrunk to minimum size.

get-buffer-create returns a buffer. how can I shrink-window on window associated with that buffer? also, is there a way to store previous window size?

It is my first foray into emacs lisp programming, thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-08-27 07:25:54

我相信有两种方法可以解决这个问题。

第一种是使用钩子“compilation-finish-functions”,它
是:

[函数列表]编译过程完成时调用的函数。
每个函数都用两个参数调用:编译缓冲区,
以及描述该过程如何完成的字符串。

这导致了这样的解决方案:

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

我对该解决方案的唯一问题是它假设可以通过在结果字符串中查找字符串“finished”来确定成功。

另一种选择是建议 'compilation-handle-exit - 其中
明确地通过退出状态。我写了这个建议
当退出状态非零时缩小窗口。

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

I believe there are two ways to solve this problem.

The first is to use the hook `'compilation-finish-functions', which
is:

[A list of f]unctions to call when a compilation process finishes.
Each function is called with two arguments: the compilation buffer,
and a string describing how the process finished.

Which leads to a solution like this:

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

The only problem I have with that solution is that it assumes that success can be determined by finding the string "finished" in the result string.

The other alternative is to advise 'compilation-handle-exit - which
gets passed the exit-status explicitly. I wrote this advice which
shrinks the window when the exit status is non-zero.

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

Note: if the *compilation* window is still visible when you do your second compile, it will not be resized larger upon failure. If you want it to be resized, you'll need to specify a height instead of nil. Perhaps this would be to your liking (changing the first example):

(if (string-match-p "finished" resstring) 5 (/ (frame-height) 2))

The nil was replaced with (/ (frame-height) 2)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文