gpt4 book ai didi

emacs 编译缓冲区自动关闭?

转载 作者:行者123 更新时间:2023-12-03 21:48:09 24 4
gpt4 key购买 nike

我想在没有错误和警告时自动关闭编译缓冲区,但我想在有警告时显示它。任何人都可以帮助我吗?此代码来自 emacswiki只做第一个要求。如何改变它?

  ;; Helper for compilation. Close the compilation window if
;; there was no error at all.
(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 秒后)。

(defun bury-compile-buffer-if-successful (buffer string)
"Bury a compilation buffer if succeeded without warnings "
(when (and
(buffer-live-p buffer)
(string-match "compilation" (buffer-name buffer))
(string-match "finished" string)
(not
(with-current-buffer buffer
(goto-char (point-min))
(search-forward "warning" nil t))))
(run-with-timer 1 nil
(lambda (buf)
(bury-buffer buf)
(switch-to-prev-buffer (get-buffer-window buf) 'kill))
buffer)))
(add-hook 'compilation-finish-functions 'bury-compile-buffer-if-successful)

关于emacs 编译缓冲区自动关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11043004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com