【发布时间】:2011-11-29 11:12:31
【问题描述】:
当我调用编译命令时,如何防止emacs打开新窗口? 我想将它绑定到特定的现有窗口。
【问题讨论】:
标签: emacs
当我调用编译命令时,如何防止emacs打开新窗口? 我想将它绑定到特定的现有窗口。
【问题讨论】:
标签: emacs
根据您对 Luke 的 cmets,我建议您查看我使用的此功能。我喜欢它,因为如果没有错误,它会掩埋编译缓冲区,否则它将保留它以便您可以看到它们。
您可以查看该页面的 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)
您可以随时切换回编译缓冲区以查看任何警告。
【讨论】:
您可以通过将compilation-buffer-name-function 设置为一个采用主要模式名称并返回缓冲区名称的函数来选择编译缓冲区的名称:
但是,查看compliation-start 的源代码,编译缓冲区似乎总是在输出写入之前被清除(通过调用erase-buffer)。
编辑:如果我正确理解了这个问题,您需要通过注释掉一行来破解compile.el 文件中的函数compilation-start:
【讨论】:
defadvice它。
(defadvice compilation-start (around inhidbit-display (command &optional mode name-function highlight-regexp)) (flet ((display-buffer)) (fset 'display-buffer 'ignore) ad-do-it)) (ad-activate 'compilation-start) (ad-deactivate 'compilation-start) 如果您愿意,您也可以将您的函数设置在'ignore 的位置。它将采用display-buffer 参数。
不太确定您在问什么,但如果您希望缓冲区“编译”在当前窗口中显示,而不是在其他窗口中显示,那么:
(add-to-list 'same-window-buffer-names "*compilation*")
【讨论】:
结合 @zdav 的 anwser 和来自 http://www.emacswiki.org/emacs/CompilationMode 的代码,这是我为 compile 提供的所有代码,它为您提供 4 个功能:
1)。使用compile-again自动运行和上次一样的编译,没有提示。如果没有最后一次,或者有前缀参数,它的行为就像 M-x 编译。
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)
【讨论】:
我对另一种情况(人模式)提出了类似的问题,但也许代码在这里也有用: Managing Emacs *Man* buffer location? (特别是https://gist.github.com/Mekk/aad77cf3401a17e5df0d,但请检查上面的问题)
【讨论】: