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