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

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

Re: compilation/grep buffer advice


From: Kevin Rodgers
Subject: Re: compilation/grep buffer advice
Date: Thu, 07 Aug 2008 21:19:23 -0600
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)

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

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