4

emacs でウィンドウを 1 つだけ表示して Mx コンパイルを使用すると、ウィンドウが 2 つに分割され、コンパイル バッファを簡単に監視できます。ただし、複数のウィンドウを表示すると、コンパイル ログが他のウィンドウの 1 つを引き継ぐので、イライラします。emacs を常に新しいウィンドウに分割してコンパイル ログを表示するにはどうすればよいですか?

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

4

4 に答える 4

4

Trey Jacksonが提供するソリューションをニーズに合わせて変更できます。

次のスニペットは*compilation*、 buffer を特別なものとしてマークし、カスタマイズされた関数を表示関数として設定して、既に分割ウィンドウにある場合でも現在のウィンドウを分割します。

(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)))
于 2009-04-14T08:48:11.593 に答える
3

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

(setq special-display-buffer-names
      `(("*compilation*" . ((name . "*compilation*")
                            ,@default-frame-alist
                            (left . (- 1))
                            (top . 0)))))
于 2009-04-14T02:05:27.050 に答える
2

からのコードの結合Emacs がコンパイル出力用に新しいウィンドウを開くのを防ぐにはどうすればよいですか? およびhttp://www.emacswiki.org/emacs/CompilationModeからのコード、これは のすべての私のコードでcompileあり、4 つの機能を提供します。

1)。compile-againプロンプトなしで、前回と同じコンパイルを自動的に実行するために使用します。前回がない場合、または前置引数がある場合は、Mx コンパイルのように動作します。

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

3)。*compilation*エラーがない場合はバッファ(ウィンドウ)を自動的に閉じ、エラーがある場合は保持します。

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)
于 2015-02-01T22:44:32.617 に答える
0

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

init.elこれをまたはに追加します.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-x C-mします。初めて実行する場合はC-x C-m、デフォルトのコマンドを変更するように求められます (通常はこれで十分です)。それ以外の場合は、コンパイルに使用したコマンドを直接実行し、使用する必要がありますC-u C-x C-m。必要に応じてコマンドを変更してください。現在のディレクトリ内にある場合はMakefile、それを認識して使用するかどうかを尋ねるプロンプトが表示されます。

この答えはあなたの質問には多すぎるかもしれませんが、試してみてください。

于 2016-11-24T14:53:51.033 に答える