all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: compilation/grep buffer advice
Date: Thu, 07 Aug 2008 21:19:23 -0600	[thread overview]
Message-ID: <g7gdvs$9k9$1@ger.gmane.org> (raw)
In-Reply-To: <87r6906gxj.fsf@nonospaz.fatphil.org>

Phil Carmody wrote:
> I like the idea of burying the result of a successful 
> compilation, but keeping errors visible, and started 
> using the code snippet that was recently posted here 
> to achieve that.
> 
> However, I got annoyed by it burying grep results too.
> This quick hack overcomes that limitation, but I'm not
> sure what kind of condition to include to test the buffer
> name:
> 
> (setq compilation-finish-function
>       (lambda (buf str)
>         (if (string-match "compilation" (buffer-name buf))
>             (if (string-match "exited abnormally" str)
>                 (message "compilation errors, press C-x ` to visit")
>               (run-at-time 1 nil 'delete-windows-on buf)
>               (message "NO COMPILATION ERRORS!"))
>           (message "didn't look like a compilation"))))

Rather than testing the buffer name, you could test the major-mode
variable: By default, M-x compile sets it to compilation-mode and
M-x grep sets it to grep-mode.  That's not comprehensive, as the
compilation-start function takes a MODE argument, but at least
major-mode is constrained to be a proper major mode whereas the buffer
name could be anything returned by compilation-start's NAME-FUNCTION.

> What other kinds of functions apart from grep use compilation 
> mode? Is it better to have 'compilation' a special case to be
> handled by optionally burying, or 'grep' the special case that
> does nothing? 

Compilation mode is highly generalized so that many other modes
can be implemented on top of it.  Such modes ought to set major-mode
via compilation-start's MODE, so I think you'd be better of testing
(eq major-mode 'compilation-mode).

You might also consider moving the test out of the
compilation-finish-function and into compilation-mode-hook:

(defun my-compilation-finish-function (buffer string)
   (if (string-match "exited abnormally" string)
       (message (substitute-command-keys
		"Compilation errors, type \\[next-error] to visit"))
     (run-at-time 1 nil 'delete-windows-on buffer)
     (message "No compilation errors")))

(add-hook 'compilation-mode-hook
	  (lambda ()
	    (if (eq major-mode 'compilation-mode)
		(set (make-local-variable 'compilation-finish-function)
		     'my-compilation-finish-function))))

-- 
Kevin Rodgers
Denver, Colorado, USA





  reply	other threads:[~2008-08-08  3:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-07 14:25 compilation/grep buffer advice Phil Carmody
2008-08-08  3:19 ` Kevin Rodgers [this message]
     [not found] ` <mailman.16056.1218165582.18990.help-gnu-emacs@gnu.org>
2008-08-08 10:20   ` Phil Carmody

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='g7gdvs$9k9$1@ger.gmane.org' \
    --to=kevin.d.rodgers@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.