如何防止emacs打开编辑输出的新窗口?

时间:2011-11-29 11:12:32

标签: emacs

当我调用编译命令时,如何防止emacs打开新窗口? 我想将它绑定到特定的现有窗口。

5 个答案:

答案 0 :(得分:8)

根据您对Luke的评论,我建议您查看我使用的这个功能。我喜欢它,因为如果没有错误它会掩盖编译缓冲区,否则它会将它保留下来以便您可以看到它们。

您可以查看emacs wiki以获取该页面,但这里是代码:

;; Helper for compilation. Close the compilation window if
;; there was no error at all. (emacs wiki)
(defun compilation-exit-autoclose (status code msg)
  ;; 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))
;; Specify my function (maybe I should have done a lambda function)
(setq compilation-exit-message-function 'compilation-exit-autoclose)

您始终可以切换回编译缓冲区以查看任何警告。

答案 1 :(得分:3)

您可以通过将compilation-buffer-name-function设置为采用主模式名称并返回缓冲区名称的函数来选择编译缓冲区的名称:

(setq compilation-buffer-name-function 
      '(lambda (maj-mode)
     "existing-buffer-name"))

但是,查看compliation-start的源代码,看起来编译缓冲区在写入输出之前总是被清除(通过调用erase-buffer)。

修改:如果我理解正确,您需要通过注释掉一行来破解compilation-start文件中的compile.el功能:

    ;; Pop up the compilation buffer.
    ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01638.html
    ;; (setq outwin (display-buffer outbuf)) 

答案 2 :(得分:1)

不太确定你在问什么,但如果你想在当前窗口中显示缓冲区`编译',而不是在另一个窗口中显示,那么:

(add-to-list 'same-window-buffer-names "*compilation*")

答案 3 :(得分:0)

结合@zdav的anwser和来自http://www.emacswiki.org/emacs/CompilationMode的代码,这是compile的全部代码,它为您提供了4个功能:

1)。使用compile-again自动运行与上次相同的编译,无提示。如果没有最后一次,或者有一个前缀参数,它就像M-x compile。

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)

答案 4 :(得分:0)

我问了另一个案例的类似问题(Man模式),但也许代码也可以在这里使用: Managing Emacs *Man* buffer location? (特别是https://gist.github.com/Mekk/aad77cf3401a17e5df0d但请查看上面的问题)