如何让Emacs中的编译窗口始终保持一定的大小?

问题描述:

我想让Emacs中的编译窗口始终显示在窗口的底部,并始终保持一定的高度。到目前为止,我把下面的线在我的.emacs文件:如何让Emacs中的编译窗口始终保持一定的大小?

(setq split-height-threshold 0) 
(setq compilation-window-height 10) 

...它确实为我只有一个窗口打开,但只要我水平分割屏幕分成两个窗口的工作(即是,中间的分界线从顶部到底部),编译窗口停止关于高度变量,并将窗口分开在中间。

我该如何解决这个问题?

+0

[popwin](https://github.com/m2ym/popwin-el)可能会像Amardeep所建议的那样有用。 – kenorb 2015-02-19 23:15:48

我会用这样的事情,从EmacsWiki*调整:

(defun my-compilation-hook() 
    (when (not (get-buffer-window "*compilation*")) 
    (save-selected-window 
     (save-excursion 
     (let* ((w (split-window-vertically)) 
       (h (window-height w))) 
      (select-window w) 
      (switch-to-buffer "*compilation*") 
      (shrink-window (- h compilation-window-height))))))) 
(add-hook 'compilation-mode-hook 'my-compilation-hook) 

如果*compilation*缓冲区是不可见的,这会垂直分割窗口,调整新打开的窗口到10号线的高度,打开其中的*compilation*缓冲区。

+2

你有没有想法如何修补它,所以它总是在当前* frame *的底部,而不是窗口?我的意思是以下情况:编辑一些东西,C-x 2将窗口拆分成一半,M-x在停留在顶部窗口时编译。你的代码打开编译在顶部胜利的底部,将更好地让它在框架的底部打开... – Mekk 2015-01-31 10:41:39

+1

@Mekk我已经发布了修改后的版本[gist](https:// gist。 github.com/ffevotte/d7e69cf147c014381003) – Francesco 2015-02-01 08:14:13

+0

非常感谢,看起来很酷。 还有一件事会很好,但我不确定它是否可行 - 使用几个类似派生模式编译共享窗口(在我的例子中,主要是* Ack *或* Ag *,但我想*发生*或*(某些)Grep *需要相同)。我试图自己寻找解决方案,但我不知道如何告诉emacs“请打开这个编译你刚才在* Ack *占用的窗口中创建) (仍然,再次感谢你的当前代码) – Mekk 2015-02-03 21:31:03

您可以自定义变量compilation-window-height

组合来自How can I prevent emacs from opening new window for compilation output?代码和代码http://www.emacswiki.org/emacs/CompilationMode,这是我compile所有的代码,它为您提供了4个特点:

1)。使用compile-again自动运行与上次相同的编译,无提示。如果没有最后一次,或者有一个前缀参数,它就像M-x编译一样。 2)。 compile将分割当前窗口(总是有一定的大小),它不会影响这个框架中的其他窗口。 3)。如果没有错误,它会自动关闭缓冲区(窗口),如果存在错误则保留它。 4)。它会突出显示*compilation*缓冲区中源代码的错误行和行号,使用M-n/p导航错误行中的*compilation*缓冲区,Enter中的每个错误以跳转到代码中的行。

(require 'compile) 
(setq compilation-last-buffer nil) 
(defun compile-again (ARG) 
    "Run the same compile as the last time. 

If there is no last time, or there is a prefix argument, this acts like M-x compile." 
    (interactive "p") 
    (if (and (eq ARG 1) 
      compilation-last-buffer) 
     (progn 
     (set-buffer compilation-last-buffer) 
     (revert-buffer t t)) 
    (progn 
     (call-interactively 'compile) 
     (setq cur (selected-window)) 
     (setq w (get-buffer-window "*compilation*")) 
     (select-window w) 
     (setq h (window-height w)) 
     (shrink-window (- h 10)) 
     (select-window cur)))) 
(global-set-key (kbd "C-x C-m") 'compile-again) 
(defun my-compilation-hook() 
    "Make sure that the compile window is splitting vertically." 
    (progn 
    (if (not (get-buffer-window "*compilation*")) 
     (progn 
      (split-window-vertically))))) 
(add-hook 'compilation-mode-hook 'my-compilation-hook) 
(defun compilation-exit-autoclose (STATUS code msg) 
    "Close the compilation window if there was no error at all." 
    ;; If M-x compile exists with a 0 
    (when (and (eq STATUS 'exit) (zerop code)) 
    ;; then bury the *compilation* buffer, so that C-x b doesn't go there 
    (bury-buffer) 
    ;; and delete the *compilation* window 
    (delete-window (get-buffer-window (get-buffer "*compilation*")))) 
    ;; Always return the anticipated result of compilation-exit-message-function 
    (cons msg code)) 
(setq compilation-exit-message-function 'compilation-exit-autoclose) 
(defvar all-overlays()) 
(defun delete-this-overlay(overlay is-after begin end &optional len) 
    (delete-overlay overlay) 
) 
(defun highlight-current-line() 
"Highlight current line." 
    (interactive) 
    (setq current-point (point)) 
    (beginning-of-line) 
    (setq beg (point)) 
    (forward-line 1) 
    (setq end (point)) 
    ;; Create and place the overlay 
    (setq error-line-overlay (make-overlay 1 1)) 

    ;; Append to list of all overlays 
    (setq all-overlays (cons error-line-overlay all-overlays)) 

    (overlay-put error-line-overlay 
       'face '(background-color . "red")) 
    (overlay-put error-line-overlay 
       'modification-hooks (list 'delete-this-overlay)) 
    (move-overlay error-line-overlay beg end) 
    (goto-char current-point)) 
(defun delete-all-overlays() 
    "Delete all overlays" 
    (while all-overlays 
    (delete-overlay (car all-overlays)) 
    (setq all-overlays (cdr all-overlays)))) 
(defun highlight-error-lines(compilation-buffer process-result) 
    (interactive) 
    (delete-all-overlays) 
    (condition-case nil 
     (while t 
     (next-error) 
     (highlight-current-line)) 
    (error nil))) 
(setq compilation-finish-functions 'highlight-error-lines)