emacs compile buffer auto close?

前端 未结 2 667
余生分开走
余生分开走 2020-12-14 10:45

I want to auto close the compile buffer when there is no error and no warning,but i want to show it when there is warnings. Anyone can help me? This code from emacswiki only

2条回答
  •  盖世英雄少女心
    2020-12-14 11:07

    jpkotta, it does work most of the times. Sometimes, even if there is a warning, it doesn't switch to compilation buffer. So I made a change to your form & it does work now:

    (defun bury-compile-buffer-if-successful (buffer string)
      "Bury a compilation buffer if succeeded without warnings "
      (if (and
           (string-match "compilation" (buffer-name buffer))
           (string-match "finished" string)
           (not
            (with-current-buffer buffer
              **(goto-char 1)**
              (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)
    

提交回复
热议问题