From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Aur=C3=A9lien_Aptel?= Newsgroups: gmane.emacs.help Subject: Display compilation buffer only if compilation failed Date: Sat, 11 Feb 2012 17:38:20 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1328978314 21223 80.91.229.3 (11 Feb 2012 16:38:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 11 Feb 2012 16:38:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 11 17:38:34 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RwFy2-0003rP-F1 for geh-help-gnu-emacs@m.gmane.org; Sat, 11 Feb 2012 17:38:30 +0100 Original-Received: from localhost ([::1]:42115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwFy1-0004fC-Rv for geh-help-gnu-emacs@m.gmane.org; Sat, 11 Feb 2012 11:38:29 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:46884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwFxx-0004ev-3Y for help-gnu-emacs@gnu.org; Sat, 11 Feb 2012 11:38:25 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RwFxs-0001l9-Rh for help-gnu-emacs@gnu.org; Sat, 11 Feb 2012 11:38:25 -0500 Original-Received: from mail-tul01m020-f169.google.com ([209.85.214.169]:63791) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwFxs-0001l0-NF for help-gnu-emacs@gnu.org; Sat, 11 Feb 2012 11:38:20 -0500 Original-Received: by obbta7 with SMTP id ta7so6142630obb.0 for ; Sat, 11 Feb 2012 08:38:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=J5hUeuGqQWc7kR2vCKnv/5cdnxTDLJmZVN63nGYksiQ=; b=UxcvLc/s/TXjGjd4aB9pAxnz5QR4V2gosD+7vsZntX+UuG+ggaiyiAf0ZRu805q4Cr xYdA+hx4p9UiA2KtGrgGPtn6g+/M6TQhyaNtcMZVAnHMP//4KTN72EyiFzMvozVO7ttb 3lsRB6cmuN4/ds3+ir2C2ZMBPkU5HVLMzNOGo= Original-Received: by 10.60.2.162 with SMTP id 2mr2126102oev.46.1328978300136; Sat, 11 Feb 2012 08:38:20 -0800 (PST) Original-Received: by 10.182.11.166 with HTTP; Sat, 11 Feb 2012 08:38:20 -0800 (PST) X-Google-Sender-Auth: vbCrtYYnldOd2aQKFGv4KmuhFPY X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83702 Archived-At: 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?