unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Amin Bandali <bandali@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Show *compilation* only if build did not succeed
Date: Sat, 22 Dec 2018 10:12:35 -0500	[thread overview]
Message-ID: <87h8f5fvdo.fsf@aminb.org> (raw)

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	other threads:[~2018-12-22 15:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-22 15:12 Amin Bandali [this message]
2018-12-22 16:49 ` Show *compilation* only if build did not succeed Stefan Monnier
2018-12-22 17:52   ` Amin Bandali
2018-12-22 18:21     ` Stefan Monnier
2018-12-22 19:09       ` Amin Bandali
2018-12-23 14:29         ` Stefan Monnier
2018-12-23 14:59           ` Amin Bandali

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h8f5fvdo.fsf@aminb.org \
    --to=bandali@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).