I believe that there are two ways to solve this problem.
First, you need to use hook 'compilation-completion functions, which is:
[List f] to be called upon completion of the compilation process. Each function is called with two arguments: a compilation buffer, and a line describing the completion process.
This leads to this solution:
(add-hook 'compilation-finish-functions 'my-compilation-finish-function) (defun my-compilation-finish-function (buffer resstring) "Shrink the window if the process finished successfully." (let ((compilation-window-height (if (string-match-p "finished" resstring) 5 nil))) (compilation-set-window-height (get-buffer-window buffer 0))))
The only problem I am facing is that it suggests that success can be determined by finding the string βfinishedβ in the resulting string.
Another alternative is advising 'compilation-handle-exit - which receives explicitly exit status. I wrote this tip that compresses a window when the exit status is not zero.
(defadvice compilation-handle-exit (around my-compilation-handle-exit-shrink-height activate) (let ((compilation-window-height (if (zerop (car (ad-get-args 1))) 5 nil))) (compilation-set-window-height (get-buffer-window (current-buffer) 0)) ad-do-it))
Note: if the *compilation* window is still displayed when you execute the second compiler, it will not change anymore upon failure. If you want the size to be resized, you need to specify the height instead of nil . Perhaps this is to your taste (modification of the first example):
(if (string-match-p "finished" resstring) 5 (/ (frame-height) 2))
nil been replaced by (/ (frame-height) 2)
Trey jackson
source share