annotate lisp/warnings.el @ 46575:30fda32839de

New file.
author Richard M. Stallman <rms@gnu.org>
date Sat, 20 Jul 2002 21:54:53 +0000
parents
children e07579b3efcc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46575
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; warnings.el --- log and display warnings
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2002 Free Software Foundation, Inc.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Maintainer: FSF
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: internal
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; This file implements the entry points `warn', `lwarn'
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; and `display-warnings'.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Code:
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defvar warning-levels
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 '((:emergency "Emergency: " ding)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (:error "Error: ")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (:warning "Warning: ")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (:debug "Debug: "))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 "List of severity level definitions for `define-warnings'.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 Each element looks like (LEVEL STRING FUNCTION) and
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 defines LEVEL as a severity level. STRING is the description
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 to use in the buffer, and FUNCTION (which may be omitted)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 if non-nil is a function to call with no arguments
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 to get the user's attention.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 :debug level is ignored by default (see `warning-minimum-level').")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (put 'warning-levels 'risky-local-variable t)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; These are for compatibility with XEmacs.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; I don't think there is any chance of finding meaningful distinctions
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; to distinguish so many levels.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defvar warning-level-aliases
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 '((emergency . :emergency)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (error . :error)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (warning . :warning)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (notice . :warning)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (info . :warning)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (critical . :emergency)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (alarm . :emergency))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 "Alist of aliases for severity levels for `display-warning'.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 Each element looks like (ALIAS . LEVEL) and defines
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ALIAS as equivalent to LEVEL.")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (defcustom warning-minimum-level :warning
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 "Minimum severity level for displaying the warning buffer.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 If a warning's severity level is lower than this,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 the warning is logged in the warnings buffer, but the buffer
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 is not immediately displayed. See also `warning-minimum-log-level'."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 :group 'warnings
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 :type '(choice (const :emergency) (const :error) (const :warning))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 :version "21.4")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (defvaralias 'display-warning-minimum-level 'warning-minimum-level)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (defcustom warning-minimum-log-level :warning
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 "Minimum severity level for logging a warning.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 If a warning severity level is lower than this,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 the warning is completely ignored."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 :group 'warnings
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 :type '(choice (const :emergency) (const :error) (const :warning))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 :version "21.4")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (defvaralias 'log-warning-minimum-level 'warning-minimum-log-level)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (defcustom warning-suppress-log nil
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 "List of warning types that should not be logged.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 If any element of this list matches the GROUP argument to `display-warning',
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 the warning is completely ignored.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 The element must match the first elements of GROUP.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 Thus, (foo bar) as an element matches (foo bar)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 or (foo bar ANYTHING...) as GROUP.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 If GROUP is a symbol FOO, that is equivalent to the list (FOO)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 so only the element (FOO) will match it."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 :group 'warnings
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 :type '(repeat (repeat symbol))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 :version "21.4")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (defcustom warning-suppress nil
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 "Custom groups for warnings not to display immediately.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 If any element of this list matches the GROUP argument to `display-warning',
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 the warning is logged nonetheless, but the warnings buffer is
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 not immediately displayed.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 The element must match an initial segment of the list GROUP.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 Thus, (foo bar) as an element matches (foo bar)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 or (foo bar ANYTHING...) as GROUP.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 If GROUP is a symbol FOO, that is equivalent to the list (FOO),
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 so only the element (FOO) will match it.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 See also `warning-suppress-log'."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 :group 'warnings
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 :type '(repeat (repeat symbol))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 :version "21.4")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defvar warning-prefix-function nil
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 "Function to generate warning prefixes.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 This function, if non-nil, is called with two arguments,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 the severity level and its entry in `warning-levels',
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 and should return the entry that should actually be used.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 The warnings buffer is current when this function is called
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 and the function can insert text in it. This text becomes
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 the beginning of the warning.")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (defun warning-numeric-level (level)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 "Return a numeric measure of the warning severity level LEVEL."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (let* ((elt (assq level warning-levels))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (link (memq elt warning-levels)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (length link)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (defvar warning-series nil
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 "Non-nil means treat multiple `display-warning' calls as a series.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 An integer is a position in the warnings buffer
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 which is the start of the current series.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 t means the next warning begins a series (and stores an integer here).
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 A symbol with a function definition is like t, except
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 also call that function before the next warning.")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (put 'warning-series 'risky-local-variable t)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (defvar warning-fill-prefix nil
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 "Non-nil means fill each warning text using this string as `fill-prefix'.")
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (defun warning-suppress-p (group suppress-list)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 "Non-nil if a warning with group GROUP should be suppressed.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 SUPPRESS-LIST is the list of kinds of warnings to suppress."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (let (some-match)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (dolist (elt suppress-list)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (if (symbolp group)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ;; If GROUP is a symbol, the ELT must be (GROUP).
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (if (and (consp elt)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (eq (car elt) group)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (null (cdr elt)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (setq some-match t))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; If GROUP is a list, ELT must match it or some initial segment of it.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (let ((tem1 group)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (tem2 elt)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (match t))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; Check elements of ELT until we run out of them.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (while tem2
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (if (not (equal (car tem1) (car tem2)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (setq match nil))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (setq tem1 (cdr tem1)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 tem2 (cdr tem2)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; If ELT is an initial segment of GROUP, MATCH is t now.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; So set SOME-MATCH.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (if match
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (setq some-match t)))))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; If some element of SUPPRESS-LIST matched,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; we return t.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 some-match))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defun display-warning (group message &optional level buffer-name)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 "Display a warning message, MESSAGE.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 GROUP should be a custom group name (a symbol).
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 or else a list of symbols whose first element is a custom group name.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 \(The rest of the symbols represent subcategories, for warning purposes
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 only, and you can use whatever symbols you like.)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 LEVEL should be either :warning, :error, or :emergency.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 :emergency -- a problem that will seriously impair Emacs operation soon
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 if you do not attend to it promptly.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 :error -- data or circumstances that are inherently wrong.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 :warning -- data or circumstances that are not inherently wrong,
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 but raise suspicion of a possible problem.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 :debug -- info for debugging only.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 BUFFER-NAME, if specified, is the name of the buffer for logging the
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 warning. By default, it is `*Warnings*'.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 See the `warnings' custom group for user customization features.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 See also `warning-series', `warning-prefix-function' and
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 `warning-fill-prefix' for additional programming features."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (unless level
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (setq level :warning))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (if (assq level warning-level-aliases)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (setq level (cdr (assq level warning-level-aliases))))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (or (< (warning-numeric-level level)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (warning-numeric-level warning-minimum-log-level))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (warning-suppress-p group warning-suppress-log)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (let* ((groupname (if (consp group) (car group) group))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (buffer (get-buffer-create (or buffer-name "*Warnings*")))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (level-info (assq level warning-levels))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 start end)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (with-current-buffer buffer
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (goto-char (point-max))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (when (and warning-series (symbolp warning-series))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (setq warning-series
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (prog1 (point)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (unless (eq warning-series t)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (funcall warning-series)))))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (unless (bolp)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (newline))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (setq start (point))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (if warning-prefix-function
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (setq level-info (funcall warning-prefix-function
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 level level-info)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (insert (nth 1 level-info) message)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (newline)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (when (and warning-fill-prefix (not (string-match "\n" message)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (let ((fill-prefix warning-fill-prefix)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (fill-column 78))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (fill-region start (point))))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (setq end (point))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (when warning-series
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (goto-char warning-series)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (if (nth 2 level-info)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (funcall (nth 2 level-info)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (if noninteractive
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; Noninteractively, take the text we inserted
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; in the warnings buffer and print it.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ;; Do this unconditionally, since there is no way
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ;; to view logged messages unless we output them.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (with-current-buffer buffer
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (message "%s" (buffer-substring start end)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;; Interactively, decide whether the warning merits
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; immediate display.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (or (< (warning-numeric-level level)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (warning-numeric-level warning-minimum-level))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (warning-suppress-p group warning-suppress)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (let ((window (display-buffer buffer)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (when warning-series
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (set-window-start window warning-series))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (sit-for 0)))))))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (defun lwarn (group level message &rest args)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 "Display a warning message made from (format MESSAGE ARGS...).
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 Aside from generating the message with `format',
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 this is equivalent to `display-message'.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 GROUP should be a custom group name (a symbol).
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 or else a list of symbols whose first element is a custom group name.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 \(The rest of the symbols represent subcategories and
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 can be whatever you like.)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 LEVEL should be either :warning, :error, or :emergency.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 :emergency -- a problem that will seriously impair Emacs operation soon
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 if you do not attend to it promptly.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 :error -- invalid data or circumstances.
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 :warning -- suspicious data or circumstances."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (display-warning group (apply 'format message args) level))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (defun warn (message &rest args)
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 "Display a warning message made from (format MESSAGE ARGS...).
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 Aside from generating the message with `format',
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 this is equivalent to `display-message', using
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 `emacs' as the group and `:warning' as the level."
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (display-warning 'emacs (apply 'format message args)))
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
30fda32839de New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;;; warnings.el ends here