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

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

Display compilation buffer only if compilation failed


From: Aurélien Aptel
Subject: Display compilation buffer only if compilation failed
Date: Sat, 11 Feb 2012 17:38:20 +0100

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 via email to

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