【问题标题】:emacs programmatically change window sizeemacs 以编程方式更改窗口大小
【发布时间】:2010-02-05 04:48:30
【问题描述】:

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

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

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

【问题讨论】:

    标签: emacs lisp window size buffer


    【解决方案1】:

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

    第一个是使用钩子`'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)

    【讨论】:

      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 2013-09-06
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多