Add 2011 to FSF/AIST copyright years.
[bpt/emacs.git] / lisp / emacs-lisp / warnings.el
index 1f57367..180296f 100644 (file)
@@ -1,16 +1,16 @@
 ;;; warnings.el --- log and display warnings
 
-;; Copyright (C) 2002 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: internal
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -159,7 +157,7 @@ also call that function before the next warning.")
 ;;; safely, testing the existing value, before they call one of the
 ;;; warnings functions.
 ;;;###autoload
-(defvar warning-type-format " (%s)"
+(defvar warning-type-format (purecopy " (%s)")
   "Format for displaying the warning type in the warning message.
 The result of formatting the type this way gets included in the
 message under the control of the string in `warning-levels'.")
@@ -209,6 +207,7 @@ only, and you can use whatever symbols you like.)
 
 LEVEL should be either :debug, :warning, :error, or :emergency
 \(but see `warning-minimum-level' and `warning-minimum-log-level').
+Default is :warning.
 
 :emergency -- a problem that will seriously impair Emacs operation soon
              if you do not attend to it promptly.
@@ -217,8 +216,9 @@ LEVEL should be either :debug, :warning, :error, or :emergency
              but raise suspicion of a possible problem.
 :debug     -- info for debugging only.
 
-BUFFER-NAME, if specified, is the name of the buffer for logging the
-warning.  By default, it is `*Warnings*'.
+BUFFER-NAME, if specified, is the name of the buffer for logging
+the warning.  By default, it is `*Warnings*'.  If this function
+has to create the buffer, it disables undo in the buffer.
 
 See the `warnings' custom group for user customization features.
 
@@ -226,16 +226,22 @@ See also `warning-series', `warning-prefix-function' and
 `warning-fill-prefix' for additional programming features."
   (unless level
     (setq level :warning))
+  (unless buffer-name
+    (setq buffer-name "*Warnings*"))
   (if (assq level warning-level-aliases)
       (setq level (cdr (assq level warning-level-aliases))))
   (or (< (warning-numeric-level level)
          (warning-numeric-level warning-minimum-log-level))
       (warning-suppress-p type warning-suppress-log-types)
       (let* ((typename (if (consp type) (car type) type))
-            (buffer (get-buffer-create (or buffer-name "*Warnings*")))
+             (old (get-buffer buffer-name))
+            (buffer (get-buffer-create buffer-name))
             (level-info (assq level warning-levels))
             start end)
        (with-current-buffer buffer
+          ;; If we created the buffer, disable undo.
+          (unless old
+            (setq buffer-undo-list t))
          (goto-char (point-max))
          (when (and warning-series (symbolp warning-series))
            (setq warning-series
@@ -262,7 +268,7 @@ See also `warning-series', `warning-prefix-function' and
            (goto-char warning-series)))
        (if (nth 2 level-info)
            (funcall (nth 2 level-info)))
-       (if noninteractive
+     (cond (noninteractive
            ;; Noninteractively, take the text we inserted
            ;; in the warnings buffer and print it.
            ;; Do this unconditionally, since there is no way
@@ -274,17 +280,28 @@ See also `warning-series', `warning-prefix-function' and
                (goto-char end)
                (if (bolp)
                    (forward-char -1))
-               (message "%s" (buffer-substring start (point)))))
-         ;; Interactively, decide whether the warning merits
-         ;; immediate display.
-         (or (< (warning-numeric-level level)
-                (warning-numeric-level warning-minimum-level))
-             (warning-suppress-p type warning-suppress-types)
-             (let ((window (display-buffer buffer)))
-               (when (and (markerp warning-series)
-                          (eq (marker-buffer warning-series) buffer))
-                 (set-window-start window warning-series))
-               (sit-for 0)))))))
+               (message "%s" (buffer-substring start (point))))))
+          ((and (daemonp) (null after-init-time))
+           ;; Warnings assigned during daemon initialization go into
+           ;; the messages buffer.
+           (message "%s"
+                    (with-current-buffer buffer
+                      (save-excursion
+                        (goto-char end)
+                        (if (bolp)
+                            (forward-char -1))
+                        (buffer-substring start (point))))))
+          (t
+           ;; Interactively, decide whether the warning merits
+           ;; immediate display.
+           (or (< (warning-numeric-level level)
+                  (warning-numeric-level warning-minimum-level))
+               (warning-suppress-p type warning-suppress-types)
+               (let ((window (display-buffer buffer)))
+                 (when (and (markerp warning-series)
+                            (eq (marker-buffer warning-series) buffer))
+                   (set-window-start window warning-series))
+                 (sit-for 0))))))))
 \f
 ;;;###autoload
 (defun lwarn (type level message &rest args)
@@ -292,7 +309,7 @@ See also `warning-series', `warning-prefix-function' and
 Aside from generating the message with `format',
 this is equivalent to `display-warning'.
 
-TYPE is the warning type: either a custom group name (a symbol).
+TYPE is the warning type: either a custom group name (a symbol),
 or a list of symbols whose first element is a custom group name.
 \(The rest of the symbols represent subcategories and
 can be whatever you like.)
@@ -317,5 +334,5 @@ this is equivalent to `display-warning', using
 
 (provide 'warnings)
 
-;;; arch-tag: faaad1c8-7b2a-4161-af38-5ab4afde0496
+;; arch-tag: faaad1c8-7b2a-4161-af38-5ab4afde0496
 ;;; warnings.el ends here