43 |
Each element looks like (LEVEL STRING FUNCTION) and |
Each element looks like (LEVEL STRING FUNCTION) and |
44 |
defines LEVEL as a severity level. STRING specifies the |
defines LEVEL as a severity level. STRING specifies the |
45 |
description of this level. STRING should use `%s' to |
description of this level. STRING should use `%s' to |
46 |
specify where to put the warning group information, |
specify where to put the warning type information, |
47 |
or it can omit the `%s' so as not to include that information. |
or it can omit the `%s' so as not to include that information. |
48 |
|
|
49 |
The optional FUNCTION, if non-nil, is a function to call |
The optional FUNCTION, if non-nil, is a function to call |
91 |
|
|
92 |
(defcustom warning-suppress-log-types nil |
(defcustom warning-suppress-log-types nil |
93 |
"List of warning types that should not be logged. |
"List of warning types that should not be logged. |
94 |
If any element of this list matches the GROUP argument to `display-warning', |
If any element of this list matches the TYPE argument to `display-warning', |
95 |
the warning is completely ignored. |
the warning is completely ignored. |
96 |
The element must match the first elements of GROUP. |
The element must match the first elements of TYPE. |
97 |
Thus, (foo bar) as an element matches (foo bar) |
Thus, (foo bar) as an element matches (foo bar) |
98 |
or (foo bar ANYTHING...) as GROUP. |
or (foo bar ANYTHING...) as TYPE. |
99 |
If GROUP is a symbol FOO, that is equivalent to the list (FOO), |
If TYPE is a symbol FOO, that is equivalent to the list (FOO), |
100 |
so only the element (FOO) will match it." |
so only the element (FOO) will match it." |
101 |
:group 'warnings |
:group 'warnings |
102 |
:type '(repeat (repeat symbol)) |
:type '(repeat (repeat symbol)) |
103 |
:version "21.4") |
:version "21.4") |
104 |
|
|
105 |
(defcustom warning-suppress-types nil |
(defcustom warning-suppress-types nil |
106 |
"Custom groups for warnings not to display immediately. |
"List of warning types not to display immediately. |
107 |
If any element of this list matches the GROUP argument to `display-warning', |
If any element of this list matches the TYPE argument to `display-warning', |
108 |
the warning is logged nonetheless, but the warnings buffer is |
the warning is logged nonetheless, but the warnings buffer is |
109 |
not immediately displayed. |
not immediately displayed. |
110 |
The element must match an initial segment of the list GROUP. |
The element must match an initial segment of the list TYPE. |
111 |
Thus, (foo bar) as an element matches (foo bar) |
Thus, (foo bar) as an element matches (foo bar) |
112 |
or (foo bar ANYTHING...) as GROUP. |
or (foo bar ANYTHING...) as TYPE. |
113 |
If GROUP is a symbol FOO, that is equivalent to the list (FOO), |
If TYPE is a symbol FOO, that is equivalent to the list (FOO), |
114 |
so only the element (FOO) will match it. |
so only the element (FOO) will match it. |
115 |
See also `warning-suppress-log-types'." |
See also `warning-suppress-log-types'." |
116 |
:group 'warnings |
:group 'warnings |
155 |
;;; safely, testing the existing value, before they call one of the |
;;; safely, testing the existing value, before they call one of the |
156 |
;;; warnings functions. |
;;; warnings functions. |
157 |
;;;###autoload |
;;;###autoload |
158 |
(defvar warning-group-format " (%s)" |
(defvar warning-type-format " (%s)" |
159 |
"Format for displaying the warning group in the warning message. |
"Format for displaying the warning type in the warning message. |
160 |
The result of formatting the group this way gets included in the |
The result of formatting the type this way gets included in the |
161 |
message under the control of the string in `warning-levels'.") |
message under the control of the string in `warning-levels'.") |
162 |
|
|
163 |
(defun warning-numeric-level (level) |
(defun warning-numeric-level (level) |
166 |
(link (memq elt warning-levels))) |
(link (memq elt warning-levels))) |
167 |
(length link))) |
(length link))) |
168 |
|
|
169 |
(defun warning-suppress-p (group suppress-list) |
(defun warning-suppress-p (type suppress-list) |
170 |
"Non-nil if a warning with group GROUP should be suppressed. |
"Non-nil if a warning with type TYPE should be suppressed. |
171 |
SUPPRESS-LIST is the list of kinds of warnings to suppress." |
SUPPRESS-LIST is the list of kinds of warnings to suppress." |
172 |
(let (some-match) |
(let (some-match) |
173 |
(dolist (elt suppress-list) |
(dolist (elt suppress-list) |
174 |
(if (symbolp group) |
(if (symbolp type) |
175 |
;; If GROUP is a symbol, the ELT must be (GROUP). |
;; If TYPE is a symbol, the ELT must be (TYPE). |
176 |
(if (and (consp elt) |
(if (and (consp elt) |
177 |
(eq (car elt) group) |
(eq (car elt) type) |
178 |
(null (cdr elt))) |
(null (cdr elt))) |
179 |
(setq some-match t)) |
(setq some-match t)) |
180 |
;; If GROUP is a list, ELT must match it or some initial segment of it. |
;; If TYPE is a list, ELT must match it or some initial segment of it. |
181 |
(let ((tem1 group) |
(let ((tem1 type) |
182 |
(tem2 elt) |
(tem2 elt) |
183 |
(match t)) |
(match t)) |
184 |
;; Check elements of ELT until we run out of them. |
;; Check elements of ELT until we run out of them. |
187 |
(setq match nil)) |
(setq match nil)) |
188 |
(setq tem1 (cdr tem1) |
(setq tem1 (cdr tem1) |
189 |
tem2 (cdr tem2))) |
tem2 (cdr tem2))) |
190 |
;; If ELT is an initial segment of GROUP, MATCH is t now. |
;; If ELT is an initial segment of TYPE, MATCH is t now. |
191 |
;; So set SOME-MATCH. |
;; So set SOME-MATCH. |
192 |
(if match |
(if match |
193 |
(setq some-match t))))) |
(setq some-match t))))) |
196 |
some-match)) |
some-match)) |
197 |
|
|
198 |
;;;###autoload |
;;;###autoload |
199 |
(defun display-warning (group message &optional level buffer-name) |
(defun display-warning (type message &optional level buffer-name) |
200 |
"Display a warning message, MESSAGE. |
"Display a warning message, MESSAGE. |
201 |
GROUP should be a custom group name (a symbol), |
TYPE is the warning type: either a custom group name (a symbol), |
202 |
or else a list of symbols whose first element is a custom group name. |
or a list of symbols whose first element is a custom group name. |
203 |
\(The rest of the symbols represent subcategories, for warning purposes |
\(The rest of the symbols represent subcategories, for warning purposes |
204 |
only, and you can use whatever symbols you like.) |
only, and you can use whatever symbols you like.) |
205 |
|
|
224 |
(setq level (cdr (assq level warning-level-aliases)))) |
(setq level (cdr (assq level warning-level-aliases)))) |
225 |
(or (< (warning-numeric-level level) |
(or (< (warning-numeric-level level) |
226 |
(warning-numeric-level warning-minimum-log-level)) |
(warning-numeric-level warning-minimum-log-level)) |
227 |
(warning-suppress-p group warning-suppress-log-types) |
(warning-suppress-p type warning-suppress-log-types) |
228 |
(let* ((groupname (if (consp group) (car group) group)) |
(let* ((typename (if (consp type) (car type) type)) |
229 |
(buffer (get-buffer-create (or buffer-name "*Warnings*"))) |
(buffer (get-buffer-create (or buffer-name "*Warnings*"))) |
230 |
(level-info (assq level warning-levels)) |
(level-info (assq level warning-levels)) |
231 |
start end) |
start end) |
243 |
(setq level-info (funcall warning-prefix-function |
(setq level-info (funcall warning-prefix-function |
244 |
level level-info))) |
level level-info))) |
245 |
(insert (format (nth 1 level-info) |
(insert (format (nth 1 level-info) |
246 |
(format warning-group-format groupname)) |
(format warning-type-format typename)) |
247 |
message) |
message) |
248 |
(newline) |
(newline) |
249 |
(when (and warning-fill-prefix (not (string-match "\n" message))) |
(when (and warning-fill-prefix (not (string-match "\n" message))) |
273 |
;; immediate display. |
;; immediate display. |
274 |
(or (< (warning-numeric-level level) |
(or (< (warning-numeric-level level) |
275 |
(warning-numeric-level warning-minimum-level)) |
(warning-numeric-level warning-minimum-level)) |
276 |
(warning-suppress-p group warning-suppress-types) |
(warning-suppress-p type warning-suppress-types) |
277 |
(let ((window (display-buffer buffer))) |
(let ((window (display-buffer buffer))) |
278 |
(when (and (markerp warning-series) |
(when (and (markerp warning-series) |
279 |
(eq (marker-buffer warning-series) buffer)) |
(eq (marker-buffer warning-series) buffer)) |
281 |
(sit-for 0))))))) |
(sit-for 0))))))) |
282 |
|
|
283 |
;;;###autoload |
;;;###autoload |
284 |
(defun lwarn (group level message &rest args) |
(defun lwarn (type level message &rest args) |
285 |
"Display a warning message made from (format MESSAGE ARGS...). |
"Display a warning message made from (format MESSAGE ARGS...). |
286 |
Aside from generating the message with `format', |
Aside from generating the message with `format', |
287 |
this is equivalent to `display-warning'. |
this is equivalent to `display-warning'. |
288 |
|
|
289 |
GROUP should be a custom group name (a symbol). |
TYPE is the warning type: either a custom group name (a symbol). |
290 |
or else a list of symbols whose first element is a custom group name. |
or a list of symbols whose first element is a custom group name. |
291 |
\(The rest of the symbols represent subcategories and |
\(The rest of the symbols represent subcategories and |
292 |
can be whatever you like.) |
can be whatever you like.) |
293 |
|
|
296 |
if you do not attend to it promptly. |
if you do not attend to it promptly. |
297 |
:error -- invalid data or circumstances. |
:error -- invalid data or circumstances. |
298 |
:warning -- suspicious data or circumstances." |
:warning -- suspicious data or circumstances." |
299 |
(display-warning group (apply 'format message args) level)) |
(display-warning type (apply 'format message args) level)) |
300 |
|
|
301 |
;;;###autoload |
;;;###autoload |
302 |
(defun warn (message &rest args) |
(defun warn (message &rest args) |
303 |
"Display a warning message made from (format MESSAGE ARGS...). |
"Display a warning message made from (format MESSAGE ARGS...). |
304 |
Aside from generating the message with `format', |
Aside from generating the message with `format', |
305 |
this is equivalent to `display-warning', using |
this is equivalent to `display-warning', using |
306 |
`emacs' as the group and `:warning' as the level." |
`emacs' as the type and `:warning' as the level." |
307 |
(display-warning 'emacs (apply 'format message args))) |
(display-warning 'emacs (apply 'format message args))) |
308 |
|
|
309 |
(provide 'warnings) |
(provide 'warnings) |