2012-03-15 36 views
11

Tôi muốn làm cho cửa sổ biên dịch trong Emacs luôn luôn xuất hiện ở dưới cùng của một cửa sổ, và luôn luôn là một chiều cao nhất định. Cho đến nay tôi đặt những dòng sau trong emacs tập tin của tôi:Làm cách nào để làm cho cửa sổ biên dịch trong Emacs luôn luôn có kích thước nhất định?

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

... và nó làm việc cho khi tôi chỉ có một cửa sổ mở ra, nhưng ngay sau khi tôi chia màn hình thành hai cửa sổ theo chiều ngang (tức là, đường phân chia ở giữa đi từ trên xuống dưới), cửa sổ biên dịch dừng sự tôn trọng biến chiều cao và chia cửa sổ ngay ở giữa.

Làm cách nào để khắc phục sự cố này?

+0

[popwin] (https://github.com/m2ym/popwin-el) có thể hữu ích như đề xuất của Amardeep. – kenorb

Trả lời

13

Tôi sẽ sử dụng một cái gì đó như thế này, tự do chuyển thể từ 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) 

Nếu bộ đệm *compilation* không nhìn thấy được, điều này sẽ chia cửa sổ theo chiều dọc, thay đổi kích thước cửa sổ mới mở ra cho 10 dòng chiều cao, và mở bộ đệm *compilation* trong đó.

+2

Bạn có ý tưởng làm thế nào để vá nó để nó luôn luôn ở dưới cùng của khung * hiện tại *, không phải cửa sổ? Tôi có nghĩa là trường hợp sau đây: chỉnh sửa một cái gì đó, C-x 2 để chia cửa sổ trong một nửa, M-x biên dịch trong khi ở trong cửa sổ trên cùng. Mã của bạn mở trình biên dịch ở phần dưới cùng của chiến thắng hàng đầu, sẽ đẹp hơn khi mở nó ở cuối khung hình ... – Mekk

+1

@Mekk Tôi đã đăng phiên bản sửa đổi trong [gist] sau đây (https: // gist. github.com/ffevotte/d7e69cf147c014381003) – Francesco

+0

Cảm ơn bạn rất nhiều, trông thật tuyệt. Có một điều nữa sẽ tốt đẹp, nhưng ở đây tôi không chắc chắn liệu nó có thể làm cửa sổ chia sẻ biên dịch với vài chế độ có nguồn gốc tương tự hay không (trong trường hợp của tôi chủ yếu là * Ack * hoặc * Ag *, nhưng tôi giả sử * Xảy ra * hoặc * (một số) Grep * sẽ yêu cầu giống nhau). Tôi cố gắng tìm giải pháp cho bản thân nhưng tôi không biết cách nói với emacs "vui lòng mở trình biên dịch này bạn vừa tạo trong cửa sổ hiện đang bị chiếm bởi * Ack *) (vẫn còn một lần nữa cảm ơn mã hiện tại) – Mekk

1

Bạn có thể tùy chỉnh biến số compilation-window-height.

1

Kết hợp mã từ How can I prevent emacs from opening new window for compilation output? và mã từ http://www.emacswiki.org/emacs/CompilationMode, đây là tất cả các mã của tôi cho compile, nó cung cấp cho bạn 4 tính năng:

1). Sử dụng compile-again để chạy cùng một biên dịch tự động như lần trước, không có lời nhắc. Nếu không có thời gian qua, hoặc có một đối số tiền tố, nó hoạt động như biên dịch M-x.

2). compile sẽ chia cửa sổ hiện tại (luôn có kích thước nhất định), nó sẽ không ảnh hưởng đến các cửa sổ khác trong khung này.

3). nó sẽ tự động đóng bộ đệm *compilation* (cửa sổ) nếu không có lỗi, giữ nó nếu lỗi tồn tại.

4). nó sẽ làm nổi bật dòng lỗi và số dòng của mã nguồn trong bộ đệm *compilation*, sử dụng M-n/p để điều hướng mọi lỗi trong bộ đệm *compilation*, Enter trong dòng lỗi để chuyển đến dòng trong mã của bạn.

(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) 
Các vấn đề liên quan