2012-03-15 64 views
11

我想讓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

回答

13

我會用這樣的事情,從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

1

您可以自定義變量compilation-window-height

1

組合來自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) 
相關問題