Mercurial > emacs
comparison lisp/emacs-lisp/warnings.el @ 88123:375f2633d815
New directory
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 08 Sep 2003 11:56:09 +0000 |
parents | 695cf19ef79e |
children | 68c22ea6027c |
comparison
equal
deleted
inserted
replaced
52428:27bc8b966642 | 88123:375f2633d815 |
---|---|
41 (:debug "Debug%s: ")) | 41 (:debug "Debug%s: ")) |
42 "List of severity level definitions for `display-warning'. | 42 "List of severity level definitions for `display-warning'. |
43 Each element looks like (LEVEL STRING FUNCTION) and | 43 Each element looks like (LEVEL STRING FUNCTION) and |
44 defines LEVEL as a severity level. STRING specifies the | 44 defines LEVEL as a severity level. STRING specifies the |
45 description of this level. STRING should use `%s' to | 45 description of this level. STRING should use `%s' to |
46 specify where to put the warning type information, | 46 specify where to put the warning group information, |
47 or it can omit the `%s' so as not to include that information. | 47 or it can omit the `%s' so as not to include that information. |
48 | 48 |
49 The optional FUNCTION, if non-nil, is a function to call | 49 The optional FUNCTION, if non-nil, is a function to call |
50 with no arguments, to get the user's attention. | 50 with no arguments, to get the user's attention. |
51 | 51 |
89 :version "21.4") | 89 :version "21.4") |
90 (defvaralias 'log-warning-minimum-level 'warning-minimum-log-level) | 90 (defvaralias 'log-warning-minimum-level 'warning-minimum-log-level) |
91 | 91 |
92 (defcustom warning-suppress-log-types nil | 92 (defcustom warning-suppress-log-types nil |
93 "List of warning types that should not be logged. | 93 "List of warning types that should not be logged. |
94 If any element of this list matches the TYPE argument to `display-warning', | 94 If any element of this list matches the GROUP argument to `display-warning', |
95 the warning is completely ignored. | 95 the warning is completely ignored. |
96 The element must match the first elements of TYPE. | 96 The element must match the first elements of GROUP. |
97 Thus, (foo bar) as an element matches (foo bar) | 97 Thus, (foo bar) as an element matches (foo bar) |
98 or (foo bar ANYTHING...) as TYPE. | 98 or (foo bar ANYTHING...) as GROUP. |
99 If TYPE is a symbol FOO, that is equivalent to the list (FOO), | 99 If GROUP is a symbol FOO, that is equivalent to the list (FOO), |
100 so only the element (FOO) will match it." | 100 so only the element (FOO) will match it." |
101 :group 'warnings | 101 :group 'warnings |
102 :type '(repeat (repeat symbol)) | 102 :type '(repeat (repeat symbol)) |
103 :version "21.4") | 103 :version "21.4") |
104 | 104 |
105 (defcustom warning-suppress-types nil | 105 (defcustom warning-suppress-types nil |
106 "List of warning types not to display immediately. | 106 "Custom groups for warnings not to display immediately. |
107 If any element of this list matches the TYPE argument to `display-warning', | 107 If any element of this list matches the GROUP argument to `display-warning', |
108 the warning is logged nonetheless, but the warnings buffer is | 108 the warning is logged nonetheless, but the warnings buffer is |
109 not immediately displayed. | 109 not immediately displayed. |
110 The element must match an initial segment of the list TYPE. | 110 The element must match an initial segment of the list GROUP. |
111 Thus, (foo bar) as an element matches (foo bar) | 111 Thus, (foo bar) as an element matches (foo bar) |
112 or (foo bar ANYTHING...) as TYPE. | 112 or (foo bar ANYTHING...) as GROUP. |
113 If TYPE is a symbol FOO, that is equivalent to the list (FOO), | 113 If GROUP is a symbol FOO, that is equivalent to the list (FOO), |
114 so only the element (FOO) will match it. | 114 so only the element (FOO) will match it. |
115 See also `warning-suppress-log-types'." | 115 See also `warning-suppress-log-types'." |
116 :group 'warnings | 116 :group 'warnings |
117 :type '(repeat (repeat symbol)) | 117 :type '(repeat (repeat symbol)) |
118 :version "21.4") | 118 :version "21.4") |
153 | 153 |
154 ;;; The autoload cookie is so that programs can bind this variable | 154 ;;; The autoload cookie is so that programs can bind this variable |
155 ;;; safely, testing the existing value, before they call one of the | 155 ;;; safely, testing the existing value, before they call one of the |
156 ;;; warnings functions. | 156 ;;; warnings functions. |
157 ;;;###autoload | 157 ;;;###autoload |
158 (defvar warning-type-format " (%s)" | 158 (defvar warning-group-format " (%s)" |
159 "Format for displaying the warning type in the warning message. | 159 "Format for displaying the warning group in the warning message. |
160 The result of formatting the type this way gets included in the | 160 The result of formatting the group this way gets included in the |
161 message under the control of the string in `warning-levels'.") | 161 message under the control of the string in `warning-levels'.") |
162 | 162 |
163 (defun warning-numeric-level (level) | 163 (defun warning-numeric-level (level) |
164 "Return a numeric measure of the warning severity level LEVEL." | 164 "Return a numeric measure of the warning severity level LEVEL." |
165 (let* ((elt (assq level warning-levels)) | 165 (let* ((elt (assq level warning-levels)) |
166 (link (memq elt warning-levels))) | 166 (link (memq elt warning-levels))) |
167 (length link))) | 167 (length link))) |
168 | 168 |
169 (defun warning-suppress-p (type suppress-list) | 169 (defun warning-suppress-p (group suppress-list) |
170 "Non-nil if a warning with type TYPE should be suppressed. | 170 "Non-nil if a warning with group GROUP should be suppressed. |
171 SUPPRESS-LIST is the list of kinds of warnings to suppress." | 171 SUPPRESS-LIST is the list of kinds of warnings to suppress." |
172 (let (some-match) | 172 (let (some-match) |
173 (dolist (elt suppress-list) | 173 (dolist (elt suppress-list) |
174 (if (symbolp type) | 174 (if (symbolp group) |
175 ;; If TYPE is a symbol, the ELT must be (TYPE). | 175 ;; If GROUP is a symbol, the ELT must be (GROUP). |
176 (if (and (consp elt) | 176 (if (and (consp elt) |
177 (eq (car elt) type) | 177 (eq (car elt) group) |
178 (null (cdr elt))) | 178 (null (cdr elt))) |
179 (setq some-match t)) | 179 (setq some-match t)) |
180 ;; If TYPE is a list, ELT must match it or some initial segment of it. | 180 ;; If GROUP is a list, ELT must match it or some initial segment of it. |
181 (let ((tem1 type) | 181 (let ((tem1 group) |
182 (tem2 elt) | 182 (tem2 elt) |
183 (match t)) | 183 (match t)) |
184 ;; Check elements of ELT until we run out of them. | 184 ;; Check elements of ELT until we run out of them. |
185 (while tem2 | 185 (while tem2 |
186 (if (not (equal (car tem1) (car tem2))) | 186 (if (not (equal (car tem1) (car tem2))) |
187 (setq match nil)) | 187 (setq match nil)) |
188 (setq tem1 (cdr tem1) | 188 (setq tem1 (cdr tem1) |
189 tem2 (cdr tem2))) | 189 tem2 (cdr tem2))) |
190 ;; If ELT is an initial segment of TYPE, MATCH is t now. | 190 ;; If ELT is an initial segment of GROUP, MATCH is t now. |
191 ;; So set SOME-MATCH. | 191 ;; So set SOME-MATCH. |
192 (if match | 192 (if match |
193 (setq some-match t))))) | 193 (setq some-match t))))) |
194 ;; If some element of SUPPRESS-LIST matched, | 194 ;; If some element of SUPPRESS-LIST matched, |
195 ;; we return t. | 195 ;; we return t. |
196 some-match)) | 196 some-match)) |
197 | 197 |
198 ;;;###autoload | 198 ;;;###autoload |
199 (defun display-warning (type message &optional level buffer-name) | 199 (defun display-warning (group message &optional level buffer-name) |
200 "Display a warning message, MESSAGE. | 200 "Display a warning message, MESSAGE. |
201 TYPE is the warning type: either a custom group name (a symbol), | 201 GROUP should be a custom group name (a symbol), |
202 or a list of symbols whose first element is a custom group name. | 202 or else a list of symbols whose first element is a custom group name. |
203 \(The rest of the symbols represent subcategories, for warning purposes | 203 \(The rest of the symbols represent subcategories, for warning purposes |
204 only, and you can use whatever symbols you like.) | 204 only, and you can use whatever symbols you like.) |
205 | 205 |
206 LEVEL should be either :warning, :error, or :emergency. | 206 LEVEL should be either :warning, :error, or :emergency. |
207 :emergency -- a problem that will seriously impair Emacs operation soon | 207 :emergency -- a problem that will seriously impair Emacs operation soon |
222 (setq level :warning)) | 222 (setq level :warning)) |
223 (if (assq level warning-level-aliases) | 223 (if (assq level warning-level-aliases) |
224 (setq level (cdr (assq level warning-level-aliases)))) | 224 (setq level (cdr (assq level warning-level-aliases)))) |
225 (or (< (warning-numeric-level level) | 225 (or (< (warning-numeric-level level) |
226 (warning-numeric-level warning-minimum-log-level)) | 226 (warning-numeric-level warning-minimum-log-level)) |
227 (warning-suppress-p type warning-suppress-log-types) | 227 (warning-suppress-p group warning-suppress-log-types) |
228 (let* ((typename (if (consp type) (car type) type)) | 228 (let* ((groupname (if (consp group) (car group) group)) |
229 (buffer (get-buffer-create (or buffer-name "*Warnings*"))) | 229 (buffer (get-buffer-create (or buffer-name "*Warnings*"))) |
230 (level-info (assq level warning-levels)) | 230 (level-info (assq level warning-levels)) |
231 start end) | 231 start end) |
232 (with-current-buffer buffer | 232 (with-current-buffer buffer |
233 (goto-char (point-max)) | 233 (goto-char (point-max)) |
241 (setq start (point)) | 241 (setq start (point)) |
242 (if warning-prefix-function | 242 (if warning-prefix-function |
243 (setq level-info (funcall warning-prefix-function | 243 (setq level-info (funcall warning-prefix-function |
244 level level-info))) | 244 level level-info))) |
245 (insert (format (nth 1 level-info) | 245 (insert (format (nth 1 level-info) |
246 (format warning-type-format typename)) | 246 (format warning-group-format groupname)) |
247 message) | 247 message) |
248 (newline) | 248 (newline) |
249 (when (and warning-fill-prefix (not (string-match "\n" message))) | 249 (when (and warning-fill-prefix (not (string-match "\n" message))) |
250 (let ((fill-prefix warning-fill-prefix) | 250 (let ((fill-prefix warning-fill-prefix) |
251 (fill-column 78)) | 251 (fill-column 78)) |
271 (message "%s" (buffer-substring start (point))))) | 271 (message "%s" (buffer-substring start (point))))) |
272 ;; Interactively, decide whether the warning merits | 272 ;; Interactively, decide whether the warning merits |
273 ;; immediate display. | 273 ;; immediate display. |
274 (or (< (warning-numeric-level level) | 274 (or (< (warning-numeric-level level) |
275 (warning-numeric-level warning-minimum-level)) | 275 (warning-numeric-level warning-minimum-level)) |
276 (warning-suppress-p type warning-suppress-types) | 276 (warning-suppress-p group warning-suppress-types) |
277 (let ((window (display-buffer buffer))) | 277 (let ((window (display-buffer buffer))) |
278 (when (and (markerp warning-series) | 278 (when (and (markerp warning-series) |
279 (eq (marker-buffer warning-series) buffer)) | 279 (eq (marker-buffer warning-series) buffer)) |
280 (set-window-start window warning-series)) | 280 (set-window-start window warning-series)) |
281 (sit-for 0))))))) | 281 (sit-for 0))))))) |
282 | 282 |
283 ;;;###autoload | 283 ;;;###autoload |
284 (defun lwarn (type level message &rest args) | 284 (defun lwarn (group level message &rest args) |
285 "Display a warning message made from (format MESSAGE ARGS...). | 285 "Display a warning message made from (format MESSAGE ARGS...). |
286 Aside from generating the message with `format', | 286 Aside from generating the message with `format', |
287 this is equivalent to `display-warning'. | 287 this is equivalent to `display-warning'. |
288 | 288 |
289 TYPE is the warning type: either a custom group name (a symbol). | 289 GROUP should be a custom group name (a symbol). |
290 or a list of symbols whose first element is a custom group name. | 290 or else a list of symbols whose first element is a custom group name. |
291 \(The rest of the symbols represent subcategories and | 291 \(The rest of the symbols represent subcategories and |
292 can be whatever you like.) | 292 can be whatever you like.) |
293 | 293 |
294 LEVEL should be either :warning, :error, or :emergency. | 294 LEVEL should be either :warning, :error, or :emergency. |
295 :emergency -- a problem that will seriously impair Emacs operation soon | 295 :emergency -- a problem that will seriously impair Emacs operation soon |
296 if you do not attend to it promptly. | 296 if you do not attend to it promptly. |
297 :error -- invalid data or circumstances. | 297 :error -- invalid data or circumstances. |
298 :warning -- suspicious data or circumstances." | 298 :warning -- suspicious data or circumstances." |
299 (display-warning type (apply 'format message args) level)) | 299 (display-warning group (apply 'format message args) level)) |
300 | 300 |
301 ;;;###autoload | 301 ;;;###autoload |
302 (defun warn (message &rest args) | 302 (defun warn (message &rest args) |
303 "Display a warning message made from (format MESSAGE ARGS...). | 303 "Display a warning message made from (format MESSAGE ARGS...). |
304 Aside from generating the message with `format', | 304 Aside from generating the message with `format', |
305 this is equivalent to `display-warning', using | 305 this is equivalent to `display-warning', using |
306 `emacs' as the type and `:warning' as the level." | 306 `emacs' as the group and `:warning' as the level." |
307 (display-warning 'emacs (apply 'format message args))) | 307 (display-warning 'emacs (apply 'format message args))) |
308 | 308 |
309 (provide 'warnings) | 309 (provide 'warnings) |
310 | 310 |
311 ;;; arch-tag: faaad1c8-7b2a-4161-af38-5ab4afde0496 | |
312 ;;; warnings.el ends here | 311 ;;; warnings.el ends here |