all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Aurélien Aptel" <aurelien.aptel+emacs@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Display compilation buffer only if compilation failed
Date: Sat, 11 Feb 2012 17:38:20 +0100	[thread overview]
Message-ID: <CA+5B0FM5LW0uhfqdJj5a0K24_HNNzimJxoAhOq2e3Vv9s2Rutg@mail.gmail.com> (raw)

Hi all,

I want Emacs to display the compilation buffer only if the compilation failed.
Here's what I have so far:

(defun my-compile-success-p (buffer)
  (with-current-buffer buffer
    (save-excursion
      (goto-char (point-max))
      (previous-line)
      (beginning-of-line)
      (when (search-forward "Compilation finished" nil t)
        t))))

(defun my-recompile-switch-if-error ()
  (interactive)
  (let ((buf (save-window-excursion ; prevent display-buffer
               (recompile)))) ; returns compilation buffer
    (when (not (my-compile-success-p buf))
      (display-buffer buf))))


But it doesn't work...
I have a file named obfu.c which compiles successfully when I run M-x
recompile.

(my-compile-success-p "*compilation*")
=> t

If I insert garbage in obfu.c, save, and recompile:

(my-compile-success-p "*compilation*")
=> nil

So my-compile-success-p seems to work.

Now if I switch back to a successful compilation:

(buffer-name (with-current-buffer "obfu.c" (recompile)))
=> "*compilation*"

(my-compile-success-p "*compilation*")
=> t

(my-compile-success-p (buffer-name
                       (with-current-buffer "obfu.c"
                         (recompile))))
=> nil

wtf?



             reply	other threads:[~2012-02-11 16:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-11 16:38 Aurélien Aptel [this message]
2012-02-11 17:29 ` Display compilation buffer only if compilation failed Drew Adams
2012-02-11 18:06   ` Aurélien Aptel
2012-02-11 18:13     ` Aurélien Aptel
2012-02-11 18:20       ` Drew Adams
2012-02-11 20:24         ` Aurélien Aptel

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

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

  git send-email \
    --in-reply-to=CA+5B0FM5LW0uhfqdJj5a0K24_HNNzimJxoAhOq2e3Vv9s2Rutg@mail.gmail.com \
    --to=aurelien.aptel+emacs@gmail.com \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.