all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Display compilation buffer only if compilation failed
@ 2012-02-11 16:38 Aurélien Aptel
  2012-02-11 17:29 ` Drew Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Aurélien Aptel @ 2012-02-11 16:38 UTC (permalink / raw)
  To: help-gnu-emacs

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?



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-02-11 20:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-11 16:38 Display compilation buffer only if compilation failed Aurélien Aptel
2012-02-11 17:29 ` 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

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.