emacs编译缓冲区自动关闭?

Ice*_*man 14 emacs buffer compile-mode

我希望在没有错误且没有警告的情况下自动关闭编译缓冲区,但是我想在有警告时显示它.有人可以帮帮我吗?来自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)
Run Code Online (Sandbox Code Playgroud)

jpk*_*tta 18

我使用以下内容进行编译.如果有警告或错误,它会保留编译缓冲区,否则会将其隐藏(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)
Run Code Online (Sandbox Code Playgroud)