emacs以编程方式更改窗口大小 [英] emacs programmatically change window size

查看:169
本文介绍了emacs以编程方式更改窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将编译缓冲区的自动崩溃实现为小尺寸(但在删除窗口不能关闭),这样在窗口的成功编译缩小到最小大小之后。



get-buffer-create 返回缓冲区。在与该缓冲区相关联的窗口上如何可以 shrink-window ?还有一种方法来存储以前的窗口大小?



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

解决方案

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



第一个是使用钩子''编译完成功能',
是:


[f]编译过程完成。
每个函数都调用两个参数:编译缓冲区
和描述进程完成的字符串。


这导致一个这样的解决方案:

 (add-hook'compilation-finish-functions'my-compilation-finish -  $)
(defun my-compilation-finish-function(buffer resstring)
如果进程成功,收缩窗口
(let((compilation-window-height (string-match-pfinishedresstring)5 nil)))
(compilation-set-window-height(get-buffer-window buffer 0))))

我使用该解决方案的唯一问题是,它假设可以通过在结果字符串中查找字符串finished来确定成功。另一个选择是建议'compilation-handle-exit - 其中
通过退出状态明确。我写了这个建议,
在退出状态不为零时缩小窗口。

 (defadvice编译句柄-exit(在my-compilation-handle-exit-shrink-height激活周围)
(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))
/ pre>

注意:如果您进行第二次编译时仍然可以看到 * compilation * 窗口,失败时不能调整大小。如果你想要调整大小,你需要指定一个高度而不是 nil 。也许这就是你的喜好(改变第一个例子):

 (if(string-match-pfinishedresstring )5(/(frame-height)2))

nil 被替换为(/(frame-height)2)


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.

解决方案

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)

这篇关于emacs以编程方式更改窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆