2009-04-13 5 views
4

私がemacsで1つのウィンドウしか表示せず、M-xコンパイルを使うと、ウィンドウは2つに分割され、コンパイルバッファを簡単に見ることができます。しかし、より多くのウィンドウが表示されている場合、コンパイルログは他のものの1つを引き継ぎます。 Emacsにコンパイルログを表示するために新しいウィンドウを分割させるにはどうすればよいですか?Emacsでコンパイルログに新しいウィンドウを作成するにはどうすればいいですか?

編集:私が行ってきた私の読書のもう少しの情報。 compile.elがdisplay-bufferを呼び出すように見えます。これは現在の全幅のウィンドウのみを分割します。この動作を回避する方法はありますか?

答えて

4

お客様のニーズに合わせてTrey Jacksonのソリューションを変更することができます。

以下のスニペットは、特別なバッファーとして*compilation*をマークし、分割されたウィンドウに既に存在する場合でもカレントウィンドウを分割する表示機能としてカスタマイズされた機能を設定します。

1):

(setq special-display-buffer-names 
     '("*compilation*")) 

(setq special-display-function 
     (lambda (buffer &optional args) 
     (split-window) 
     (switch-to-buffer buffer) 
     (get-buffer-window buffer 0))) 
+0

全く動作しません。 – CodyChan

3

専用のトップレベルウィンドウ(Emacsはフレームと呼んでいます)を望んでいるなら、これはあなたのためのトリックです。このスニペットには配置ディレクティブが含まれていますが、変数'special-display-buffer-namesをカスタマイズすると、必要なものが得られます。

(setq special-display-buffer-names 
     `(("*compilation*" . ((name . "*compilation*") 
          ,@default-frame-alist 
          (left . (- 1)) 
          (top . 0))))) 
+0

私は用語を知っています。物理的なものとは対照的に、論理的なemacsウィンドウを実際に探しています。 –

1

http://www.emacswiki.org/emacs/CompilationModeからHow can I prevent emacs from opening new window for compilation output?からコードとコードの組み合わせ、これはそれがあなたの4つの機能を提供し、compileのためのすべての私のコードです。 compile-againを使用すると、前回と同じコンパイルを自動的に実行し、プロンプトは表示されません。最後の時間がないか、接頭引数がある場合、それはM-xコンパイルのように動作します。

2)。 compileは現在のウィンドウを分割しますが、このフレーム内の他のウィンドウには影響しません。

3)。エラーがなければバッファー(ウィンドウ)を自動クローズし、エラーが存在する場合はそのままにしておきます。

4)。 *compilation*バッファ内のソースコードのエラー行と行番号を強調表示し、M-n/pを使用して、エラーコード内のバッファー、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) 
0

smart-compileパッケージをEmacs内にインストールします。

あなたがC-x C-mを実行するのは初めてであれば、それは通常は十分である(デフォルトのコマンドを変更するように要求されます、あなたのソースコードをコンパイルするために使用C-x C-mあなた​​や.emacs

(require 'compile) 
(setq compilation-last-buffer nil) 
;; save all modified buffers without asking before compilation 
(setq compilation-ask-about-save nil) 
(defun compile-again (ARG) 
    "Run the same compile as the last time. 

With a prefix argument or no last time, this acts like M-x compile, 
and you can reconfigure the compile args." 
    (interactive "p") 
    ;; the following two lines create bug: split a new window every time 
    ;; (if (not (get-buffer-window "*compilation*")) 
    ;;  (split-window-below)) 
    (if (and (eq ARG 1) compilation-last-buffer) 
     (recompile) 
    (call-interactively 'smart-compile))) 
(bind-key* "C-x C-m" 'compile-again) 
;; create a new small frame to show the compilation info 
;; will be auto closed if no error 
(setq special-display-buffer-names 
     `(("*compilation*" . ((name . "*compilation*") 
          ,@default-frame-alist 
          (left . (- 1)) 
          (top . 0))))) 
(setq compilation-finish-functions 
     (lambda (buf str) 
     (if (null (string-match ".*exited abnormally.*" str)) 
      ;;no errors, make the compilation window go away in a few seconds 
      (progn 
       (run-at-time 
       "1 sec" nil 'delete-windows-on 
       (get-buffer-create "*compilation*")) 
       (message "No Compilation Errors!"))))) 

にこれを追加)、それ以外の場合は直接コンパイルに使用したコマンドが実行され、必要に応じてC-u C-x C-mを使用してコマンドを変更する必要があります。現在のディレクトリ内にMakefileがある場合は、使用するかどうかを確認するメッセージが表示されます。

多分この回答はあなたの質問には多すぎますが、試してみてください。

関連する問題