help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Show *compilation* only if build did not succeed


From: Amin Bandali
Subject: Show *compilation* only if build did not succeed
Date: Sat, 22 Dec 2018 10:12:35 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Hello,

I use a literate init.org configuration for my GNU Emacs, which I
automatically tangle into init.el on each save and then call ‘make’
using something like (compile "make ti").

Here’s my problem: invoking compile creates a new window, and that
annoys me to no end, esp. since I save my init.org frequently while
editing.  So I’ve wrapped the call to compile in a call to
save-window-excursion which causes compile to not create a window.  But
ideally the window would be created if compilation did not succeed.

Recently I found the following snippet¹ on Stack Overflow:

#+begin_src emacs-lisp
(defun brian-compile-finish (buffer outstr)
  (unless (string-match "finished" outstr)
    (switch-to-buffer-other-window buffer))
  t)

(setq compilation-finish-functions 'brian-compile-finish)

(require 'cl)

(defadvice compilation-start
  (around inhibit-display
      (command &optional mode name-function highlight-regexp)) 
  (if (not (string-match "^\\(find\\|grep\\)" command))
      (flet ((display-buffer)
         (set-window-point)
         (goto-char)) 
    (fset 'display-buffer 'ignore)
    (fset 'goto-char 'ignore)
    (fset 'set-window-point 'ignore)
    (save-window-excursion 
      ad-do-it))
    ad-do-it))

(ad-activate 'compilation-start)
#+end_src

But the problem with the above is that, if you look at the defadvice, it
uses flet, which has been obsolete since 24.3, and so I get an annoying
warning on every startup (I byte-compile my init.el).

Are there any “modern” solutions for achieving this?  If not, it would
be great if one could customize the behaviour of when compile would
create a window, depending on the build result or if the build takes
longer than a certain time threshold.

Thanks,
amin

Footnotes:
¹  https://stackoverflow.com/a/17788551




reply via email to

[Prev in Thread] Current Thread [Next in Thread]