unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "François Fleuret" <francois.fleuret@inria.fr>
Subject: Re: Open compilation window only on errors?
Date: 29 Sep 2003 16:45:15 +0200	[thread overview]
Message-ID: <s021xtzhcw4.fsf@wasabi.inria.fr> (raw)
In-Reply-To: mailman.813.1064689050.21628.help-gnu-emacs@gnu.org


Matthew Calhoun wrote on 27 Sep 2003 19:57:18 MET:

> When I compile using M-x compile, Emacs opens a new window for the
> compilation buffer when it's finished. This is great when there are
> warnings or errors, but when there aren't I would like to prevent
> Emacs from opening the new window, and instead maybe just put a
> message in the minibuffer indicating that compilation was
> successful. Is there a variable I can set for this, or does anyone
> have elisp code that does something similar?

This is my own recipe (sort of dirty, but has been working for months
here), maybe it can help:

;; <f1> runs the compilation according to the compile-command (and
;; thus does not ask any confirmation), shows the compilation buffer
;; during compilation AND removes it if the compilation ends with no
;; error (i.e. it restores the window configuration as it was before
;; <f1> was pressed)

;; <shift-f1> asks for a compilation command and runs the compilation
;; but does not restore the window configuration (i.e. the compilation
;; buffer's window will still be visible, as usual)

;; <f2> goes to the next compilation error (as C-x ` does on the
;; standard configuration)

(defun restore-windows-if-no-error (buffer msg)
  "Restores the window configuration according to `window-configuration-before-compilation'
if msg matches \"^finished\".

This function can be used by adding in your .emacs

\(setq compilation-finish-function \'restore-windows-if-no-error\)."

  (if (string-match "^finished" msg)
      (when (boundp 'window-configuration-before-compilation)
        (progn
          (set-window-configuration window-configuration-before-compilation)
          (message (concat "Compilation '" compile-command "' finished with no error (compilation window removed)"))
          )))

  (makunbound 'window-configuration-before-compilation)
  )

(setq compilation-finish-function 'restore-windows-if-no-error)

(defun fast-compile () "Compiles without asking anything" (interactive)
  (let ((compilation-read-command nil))
    (setq window-configuration-before-compilation (current-window-configuration))
    (compile compile-command)))

(define-key global-map [f1] 'fast-compile)
(define-key global-map [(shift f1)] 'compile)
(define-key global-map [f2] 'next-error)

-- 
François Fleuret

IMEDIA Research Group                            Tel +33 1 39 63 55 83
INRIA, France                                    Fax +33 1 39 63 59 95

  parent reply	other threads:[~2003-09-29 14:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.813.1064689050.21628.help-gnu-emacs@gnu.org>
2003-09-29  9:45 ` Open compilation window only on errors? Jens Schmidt
2003-10-13  8:05   ` Matthew Calhoun
2003-09-29 14:45 ` François Fleuret [this message]
2003-09-29 22:10 ` Kevin Rodgers
     [not found] <mailman.1571.1066032399.21628.help-gnu-emacs@gnu.org>
2003-10-13 17:24 ` Kevin Rodgers
2003-09-27 18:57 Matthew Calhoun

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=s021xtzhcw4.fsf@wasabi.inria.fr \
    --to=francois.fleuret@inria.fr \
    /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).