diff options
| author | Eli Zaretskii | 2023-04-30 11:07:36 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2023-04-30 11:07:36 +0300 |
| commit | 7f94558b775e36042b28d3df6460463bd112dfda (patch) | |
| tree | cfe41c839177b54e07f645842559ae122ed8923b | |
| parent | 5a3f0e2c558d783caad6b356310217866e9cd47e (diff) | |
| download | emacs-7f94558b775e36042b28d3df6460463bd112dfda.tar.gz emacs-7f94558b775e36042b28d3df6460463bd112dfda.zip | |
Improve documentation of warnings
* doc/lispref/control.texi (Errors):
* doc/lispref/os.texi (Startup Summary):
* doc/lispref/display.texi (Warning Basics, Warning Variables)
(Warning Options, Delayed Warnings): Improve documentation of
warnings. Document the automatic delaying of warnings during
startup. (Bug#63181)
| -rw-r--r-- | doc/lispref/control.texi | 3 | ||||
| -rw-r--r-- | doc/lispref/display.texi | 214 | ||||
| -rw-r--r-- | doc/lispref/os.texi | 4 |
3 files changed, 135 insertions, 86 deletions
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 930903d5085..e621a28acda 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -1809,6 +1809,9 @@ wish the program to continue execution despite an error in a subroutine. | |||
| 1809 | In these cases, you would use @code{condition-case} to establish | 1809 | In these cases, you would use @code{condition-case} to establish |
| 1810 | @dfn{error handlers} to recover control in case of error. | 1810 | @dfn{error handlers} to recover control in case of error. |
| 1811 | 1811 | ||
| 1812 | For reporting problems without terminating the execution of the | ||
| 1813 | current command, consider issuing a warning instead. @xref{Warnings}. | ||
| 1814 | |||
| 1812 | Resist the temptation to use error handling to transfer control from | 1815 | Resist the temptation to use error handling to transfer control from |
| 1813 | one part of the program to another; use @code{catch} and @code{throw} | 1816 | one part of the program to another; use @code{catch} and @code{throw} |
| 1814 | instead. @xref{Catch and Throw}. | 1817 | instead. @xref{Catch and Throw}. |
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 8184021d998..f1b4b001889 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -752,7 +752,8 @@ echo area (which is really a special use of the minibuffer window; | |||
| 752 | @cindex warnings | 752 | @cindex warnings |
| 753 | 753 | ||
| 754 | @dfn{Warnings} are a facility for a program to inform the user of a | 754 | @dfn{Warnings} are a facility for a program to inform the user of a |
| 755 | possible problem, but continue running. | 755 | possible problem, but continue running (as opposed to signaling an |
| 756 | error, @pxref{Errors}). | ||
| 756 | 757 | ||
| 757 | @menu | 758 | @menu |
| 758 | * Warning Basics:: Warnings concepts and functions to report them. | 759 | * Warning Basics:: Warnings concepts and functions to report them. |
| @@ -765,69 +766,74 @@ possible problem, but continue running. | |||
| 765 | @subsection Warning Basics | 766 | @subsection Warning Basics |
| 766 | @cindex severity level | 767 | @cindex severity level |
| 767 | 768 | ||
| 768 | Every warning has a textual message, which explains the problem for | 769 | Every warning is a textual message, which explains the problem for |
| 769 | the user, and a @dfn{severity level} which is a symbol. Here are the | 770 | the user, with the associated @dfn{severity level} which is a symbol. |
| 770 | possible severity levels, in order of decreasing severity, and their | 771 | Here are the supported severity levels, in order of decreasing |
| 771 | meanings: | 772 | severity, and their meanings: |
| 772 | 773 | ||
| 773 | @table @code | 774 | @table @code |
| 774 | @item :emergency | 775 | @item :emergency |
| 775 | A problem that will seriously impair Emacs operation soon | 776 | A problem that will seriously impair Emacs operation soon |
| 776 | if you do not attend to it promptly. | 777 | if the user does not attend to it promptly. |
| 777 | @item :error | 778 | @item :error |
| 778 | A report of data or circumstances that are inherently wrong. | 779 | A report about data or circumstances that are inherently wrong. |
| 779 | @item :warning | 780 | @item :warning |
| 780 | A report of data or circumstances that are not inherently wrong, but | 781 | A report about data or circumstances that are not inherently wrong, |
| 781 | raise suspicion of a possible problem. | 782 | but raise suspicion of a possible problem. |
| 782 | @item :debug | 783 | @item :debug |
| 783 | A report of information that may be useful if you are debugging. | 784 | A report of information that may be useful if the user is currently |
| 785 | debugging the Lisp program which issues the warning. | ||
| 784 | @end table | 786 | @end table |
| 785 | 787 | ||
| 786 | When your program encounters invalid input data, it can either | 788 | When your program encounters invalid input data, it can either |
| 787 | signal a Lisp error by calling @code{error} or @code{signal} or report | 789 | signal a Lisp error by calling @code{error} or @code{signal} |
| 788 | a warning with severity @code{:error}. Signaling a Lisp error is the | 790 | (@pxref{Signaling Errors}) or report a warning with severity |
| 789 | easiest thing to do, but it means the program cannot continue | 791 | @code{:error}. Signaling a Lisp error is the easiest thing to do, but |
| 790 | processing. If you want to take the trouble to implement a way to | 792 | it means the signaling program cannot continue execution. If you want |
| 791 | continue processing despite the bad data, then reporting a warning of | 793 | to take the trouble of implementing a way to continue processing |
| 792 | severity @code{:error} is the right way to inform the user of the | 794 | despite the invalid data, then reporting a warning of severity |
| 793 | problem. For instance, the Emacs Lisp byte compiler can report an | 795 | @code{:error} is the right way of informing the user of the problem. |
| 794 | error that way and continue compiling other functions. (If the | 796 | For instance, the Emacs Lisp byte compiler can report an error that |
| 795 | program signals a Lisp error and then handles it with | 797 | way and continue compiling other functions. (If the program signals a |
| 796 | @code{condition-case}, the user won't see the error message; it could | 798 | Lisp error and then handles it with @code{condition-case}, the user |
| 797 | show the message to the user by reporting it as a warning.) | 799 | won't see the error message; reporting that as a warning instead |
| 798 | 800 | avoids that problem.) | |
| 799 | @c FIXME: Why use "(bytecomp)" instead of "'bytecomp" or simply | 801 | |
| 800 | @c "bytecomp" here? The parens are part of warning-type-format but | ||
| 801 | @c not part of the warning type. --xfq | ||
| 802 | @cindex warning type | 802 | @cindex warning type |
| 803 | Each warning has a @dfn{warning type} to classify it. The type is a | 803 | In addition to severity level, each warning has a @dfn{warning type} |
| 804 | list of symbols. The first symbol should be the custom group that you | 804 | to classify it. The warning type is either a symbol or a list of |
| 805 | use for the program's user options. For example, byte compiler | 805 | symbols. If it is a symbol, it should be the custom group that you |
| 806 | warnings use the warning type @code{(bytecomp)}. You can also | 806 | use for the program's user options; if it is a list, the first element |
| 807 | subcategorize the warnings, if you wish, by using more symbols in the | 807 | of the list should be that custom group. For example, byte compiler |
| 808 | list. | 808 | warnings use the warning type @code{(bytecomp)}. If the warning type |
| 809 | is a list, the elements of the list after the first one, which should | ||
| 810 | be arbitrary symbols, represent subcategories of the warning: they | ||
| 811 | will be displayed to the user to better explain the nature of the | ||
| 812 | warning. | ||
| 809 | 813 | ||
| 810 | @defun display-warning type message &optional level buffer-name | 814 | @defun display-warning type message &optional level buffer-name |
| 811 | This function reports a warning, using @var{message} as the message | 815 | This function reports a warning, using the string @var{message} as the |
| 812 | and @var{type} as the warning type. @var{level} should be the | 816 | warning text and @var{type} as the warning type. @var{level} should |
| 813 | severity level, with @code{:warning} being the default. | 817 | be the severity level, and defaults to @code{:warning} if omitted or |
| 818 | @code{nil}. | ||
| 814 | 819 | ||
| 815 | @var{buffer-name}, if non-@code{nil}, specifies the name of the buffer | 820 | @var{buffer-name}, if non-@code{nil}, specifies the name of the buffer |
| 816 | for logging the warning. By default, it is @file{*Warnings*}. | 821 | for logging the warning message. By default, it is @file{*Warnings*}. |
| 817 | @end defun | 822 | @end defun |
| 818 | 823 | ||
| 819 | @defun lwarn type level message &rest args | 824 | @defun lwarn type level message &rest args |
| 820 | This function reports a warning using the value of @code{(format-message | 825 | This function reports a warning using the value returned by |
| 821 | @var{message} @var{args}...)} as the message in the @file{*Warnings*} | 826 | @w{@code{(format-message @var{message} @var{args}@dots{})}} as the |
| 822 | buffer. In other respects it is equivalent to @code{display-warning}. | 827 | message text in the @file{*Warnings*} buffer. In other respects it is |
| 828 | equivalent to @code{display-warning}. | ||
| 823 | @end defun | 829 | @end defun |
| 824 | 830 | ||
| 825 | @defun warn message &rest args | 831 | @defun warn message &rest args |
| 826 | This function reports a warning using the value of @code{(format-message | 832 | This function reports a warning using the value returned by |
| 827 | @var{message} @var{args}...)} as the message, @code{(emacs)} as the | 833 | @w{@code{(format-message @var{message} @var{args}@dots{})}} as the |
| 828 | type, and @code{:warning} as the severity level. It exists for | 834 | message text, @code{emacs} as the warning type, and @code{:warning} as |
| 829 | compatibility only; we recommend not using it, because you should | 835 | the severity level. It exists for compatibility only; we recommend |
| 830 | specify a specific warning type. | 836 | not using it, because you should specify a specific warning type. |
| 831 | @end defun | 837 | @end defun |
| 832 | 838 | ||
| 833 | @node Warning Variables | 839 | @node Warning Variables |
| @@ -842,15 +848,16 @@ This list defines the meaning and severity order of the warning | |||
| 842 | severity levels. Each element defines one severity level, | 848 | severity levels. Each element defines one severity level, |
| 843 | and they are arranged in order of decreasing severity. | 849 | and they are arranged in order of decreasing severity. |
| 844 | 850 | ||
| 845 | Each element has the form @code{(@var{level} @var{string} | 851 | Each element has the form @w{@code{(@var{level} @var{string} |
| 846 | @var{function})}, where @var{level} is the severity level it defines. | 852 | [@var{function}])}}, where @var{level} is the severity level it |
| 847 | @var{string} specifies the textual description of this level. | 853 | defines. @var{string} specifies the textual description of this |
| 848 | @var{string} should use @samp{%s} to specify where to put the warning | 854 | level. @var{string} should use @samp{%s} to specify where to put the |
| 849 | type information, or it can omit the @samp{%s} so as not to include | 855 | warning type information, or it can omit the @samp{%s} so as not to |
| 850 | that information. | 856 | include that information. |
| 851 | 857 | ||
| 852 | The optional @var{function}, if non-@code{nil}, is a function to call | 858 | The optional @var{function}, if non-@code{nil}, is a function to call |
| 853 | with no arguments, to get the user's attention. | 859 | with no arguments, to get the user's attention. A notable example is |
| 860 | @code{ding} (@pxref{Beeping}). | ||
| 854 | 861 | ||
| 855 | Normally you should not change the value of this variable. | 862 | Normally you should not change the value of this variable. |
| 856 | @end defvar | 863 | @end defvar |
| @@ -859,18 +866,19 @@ Normally you should not change the value of this variable. | |||
| 859 | If non-@code{nil}, the value is a function to generate prefix text for | 866 | If non-@code{nil}, the value is a function to generate prefix text for |
| 860 | warnings. Programs can bind the variable to a suitable function. | 867 | warnings. Programs can bind the variable to a suitable function. |
| 861 | @code{display-warning} calls this function with the warnings buffer | 868 | @code{display-warning} calls this function with the warnings buffer |
| 862 | current, and the function can insert text in it. That text becomes | 869 | the current buffer, and the function can insert text into it. That |
| 863 | the beginning of the warning message. | 870 | text becomes the beginning of the warning message. |
| 864 | 871 | ||
| 865 | The function is called with two arguments, the severity level and its | 872 | The function is called with two arguments, the severity level and its |
| 866 | entry in @code{warning-levels}. It should return a list to use as the | 873 | entry in @code{warning-levels}. It should return a list to use |
| 867 | entry (this value need not be an actual member of | 874 | @emph{instead} of that entry (the value need not be an actual member |
| 868 | @code{warning-levels}). By constructing this value, the function can | 875 | of @code{warning-levels}, but it must have the same structure). By |
| 869 | change the severity of the warning, or specify different handling for | 876 | constructing this value, the function can change the severity of the |
| 870 | a given severity level. | 877 | warning, or specify different handling for a given severity level. |
| 871 | 878 | ||
| 872 | If the variable's value is @code{nil} then there is no function | 879 | If the variable's value is @code{nil}, there's no prefix text, before |
| 873 | to call. | 880 | the warning is displayed, starting with the @var{string} part of the |
| 881 | entry in @code{warning-levels} corresponding to the warning's level. | ||
| 874 | @end defvar | 882 | @end defvar |
| 875 | 883 | ||
| 876 | @defvar warning-series | 884 | @defvar warning-series |
| @@ -878,17 +886,18 @@ Programs can bind this variable to @code{t} to say that the next | |||
| 878 | warning should begin a series. When several warnings form a series, | 886 | warning should begin a series. When several warnings form a series, |
| 879 | that means to leave point on the first warning of the series, rather | 887 | that means to leave point on the first warning of the series, rather |
| 880 | than keep moving it for each warning so that it appears on the last one. | 888 | than keep moving it for each warning so that it appears on the last one. |
| 881 | The series ends when the local binding is unbound and | 889 | The series ends when the local binding of this variable is unbound and |
| 882 | @code{warning-series} becomes @code{nil} again. | 890 | @code{warning-series} becomes @code{nil} again. |
| 883 | 891 | ||
| 884 | The value can also be a symbol with a function definition. That is | 892 | The value can also be a symbol with a function definition. That is |
| 885 | equivalent to @code{t}, except that the next warning will also call | 893 | equivalent to @code{t}, except that the next warning will also call |
| 886 | the function with no arguments with the warnings buffer current. The | 894 | the function with no arguments with the warnings buffer the current |
| 887 | function can insert text which will serve as a header for the series | 895 | buffer. The function can, for example, insert text which will serve |
| 888 | of warnings. | 896 | as a header for the series of warnings. |
| 889 | 897 | ||
| 890 | Once a series has begun, the value is a marker which points to the | 898 | Once a series has begun, the value of this variable is a marker which |
| 891 | buffer position in the warnings buffer of the start of the series. | 899 | points to the buffer position in the warnings buffer of the start of |
| 900 | the series. | ||
| 892 | 901 | ||
| 893 | The variable's normal value is @code{nil}, which means to handle | 902 | The variable's normal value is @code{nil}, which means to handle |
| 894 | each warning separately. | 903 | each warning separately. |
| @@ -896,7 +905,7 @@ each warning separately. | |||
| 896 | 905 | ||
| 897 | @defvar warning-fill-prefix | 906 | @defvar warning-fill-prefix |
| 898 | When this variable is non-@code{nil}, it specifies a fill prefix to | 907 | When this variable is non-@code{nil}, it specifies a fill prefix to |
| 899 | use for filling each warning's text. | 908 | use for filling the text of each warning. |
| 900 | @end defvar | 909 | @end defvar |
| 901 | 910 | ||
| 902 | @defvar warning-fill-column | 911 | @defvar warning-fill-column |
| @@ -905,11 +914,11 @@ The column at which to fill warnings. | |||
| 905 | 914 | ||
| 906 | @defvar warning-type-format | 915 | @defvar warning-type-format |
| 907 | This variable specifies the format for displaying the warning type | 916 | This variable specifies the format for displaying the warning type |
| 908 | in the warning message. The result of formatting the type this way | 917 | in the warning text. The result of formatting the type this way |
| 909 | gets included in the message under the control of the string in the | 918 | gets included in the message under the control of the string in the |
| 910 | entry in @code{warning-levels}. The default value is @code{" (%s)"}. | 919 | entry in @code{warning-levels}. The default value is @code{" (%s)"}. |
| 911 | If you bind it to @code{""} then the warning type won't appear at | 920 | If you bind it to the empty string @code{""} then the warning type |
| 912 | all. | 921 | won't appear at all. |
| 913 | @end defvar | 922 | @end defvar |
| 914 | 923 | ||
| 915 | @node Warning Options | 924 | @node Warning Options |
| @@ -921,38 +930,71 @@ when a Lisp program reports a warning. | |||
| 921 | 930 | ||
| 922 | @defopt warning-minimum-level | 931 | @defopt warning-minimum-level |
| 923 | This user option specifies the minimum severity level that should be | 932 | This user option specifies the minimum severity level that should be |
| 924 | shown immediately to the user. The default is @code{:warning}, which | 933 | shown immediately to the user, by popping the warnings buffer in some |
| 925 | means to immediately display all warnings except @code{:debug} | 934 | window. The default is @code{:warning}, which means to show the |
| 926 | warnings. | 935 | warning buffer for any warning severity except @code{:debug}. The |
| 936 | warnings of lower severity levels will still be written into the | ||
| 937 | warnings buffer, but the buffer will not be forced onto display. | ||
| 927 | @end defopt | 938 | @end defopt |
| 928 | 939 | ||
| 929 | @defopt warning-minimum-log-level | 940 | @defopt warning-minimum-log-level |
| 930 | This user option specifies the minimum severity level that should be | 941 | This user option specifies the minimum severity level that should be |
| 931 | logged in the warnings buffer. The default is @code{:warning}, which | 942 | logged in the warnings buffer. Warnings of lower severity will be |
| 932 | means to log all warnings except @code{:debug} warnings. | 943 | completely ignored: not written to the warnings buffer and not |
| 944 | displayed. The default is @code{:warning}, which means to log | ||
| 945 | warnings of any severity except @code{:debug}. | ||
| 933 | @end defopt | 946 | @end defopt |
| 934 | 947 | ||
| 935 | @defopt warning-suppress-types | 948 | @defopt warning-suppress-types |
| 936 | This list specifies which warning types should not be displayed | 949 | This list specifies which warning types should not be displayed |
| 937 | immediately for the user. Each element of the list should be a list | 950 | immediately when they occur. Each element of the list should be a |
| 938 | of symbols. If its elements match the first elements in a warning | 951 | list of symbols. If an element of this list has the same elements as |
| 939 | type, then that warning is not displayed immediately. | 952 | the first elements in a warning type, then the warning of that type |
| 953 | will not be shown on display by popping the warnings buffer in some | ||
| 954 | window (the warning will still be logged in the warnings buffer). | ||
| 955 | |||
| 956 | For example, if the value of this variable is a list like this: | ||
| 957 | |||
| 958 | @lisp | ||
| 959 | ((foo) (bar subtype)) | ||
| 960 | @end lisp | ||
| 961 | |||
| 962 | @noindent | ||
| 963 | then warnings whose types are @code{foo} or @code{(foo)} or | ||
| 964 | @w{@code{(foo something)}} or @w{@code{(bar subtype other)}} will not | ||
| 965 | be shown to the user. | ||
| 940 | @end defopt | 966 | @end defopt |
| 941 | 967 | ||
| 942 | @defopt warning-suppress-log-types | 968 | @defopt warning-suppress-log-types |
| 943 | This list specifies which warning types should not be logged in the | 969 | This list specifies which warning types should be ignored: not logged |
| 944 | warnings buffer. Each element of the list should be a list of | 970 | in the warnings buffer and not shown to the user. The structure and |
| 945 | symbols. If it matches the first few elements in a warning type, then | 971 | the matching of warning types are the same as for |
| 946 | that warning is not logged. | 972 | @code{warning-suppress-types} above. |
| 947 | @end defopt | 973 | @end defopt |
| 948 | 974 | ||
| 975 | @cindex warnings, suppressing during startup | ||
| 976 | @cindex prevent warnings in init files | ||
| 977 | During startup, Emacs delays showing any warnings until after it | ||
| 978 | loads and processes the site-wide and user's init files | ||
| 979 | (@pxref{Startup Summary}). Let-binding (@pxref{Local Variables}) the | ||
| 980 | values of these options around some code in your init files which | ||
| 981 | might emit a warning will therefore not work, because it will not be | ||
| 982 | in effect by the time the warning is actually processed. Thus, if you | ||
| 983 | want to suppress some warnings during startup, change the values of | ||
| 984 | the above options in your init file early enough, or put those | ||
| 985 | let-binding forms in your @code{after-init-hook} or | ||
| 986 | @code{emacs-startup-hook} functions. @xref{Init File}. | ||
| 987 | |||
| 949 | @node Delayed Warnings | 988 | @node Delayed Warnings |
| 950 | @subsection Delayed Warnings | 989 | @subsection Delayed Warnings |
| 951 | @cindex delayed warnings | 990 | @cindex delayed warnings |
| 991 | @cindex warnings, delayed | ||
| 952 | 992 | ||
| 953 | Sometimes, you may wish to avoid showing a warning while a command is | 993 | Sometimes, you may wish to avoid showing a warning while a command is |
| 954 | running, and only show it only after the end of the command. You can | 994 | running, and only show it only after the end of the command. You can |
| 955 | use the function @code{delay-warning} for this. | 995 | use the function @code{delay-warning} for this. Emacs automatically |
| 996 | delays any warnings emitted during the early stages of startup, and | ||
| 997 | shows them only after the init files are processed. | ||
| 956 | 998 | ||
| 957 | @defun delay-warning type message &optional level buffer-name | 999 | @defun delay-warning type message &optional level buffer-name |
| 958 | This function is the delayed counterpart to @code{display-warning} | 1000 | This function is the delayed counterpart to @code{display-warning} |
| @@ -973,7 +1015,7 @@ with the same form, and the same meanings, as the argument list of | |||
| 973 | @code{display-warning}. Immediately after running | 1015 | @code{display-warning}. Immediately after running |
| 974 | @code{post-command-hook} (@pxref{Command Overview}), the Emacs | 1016 | @code{post-command-hook} (@pxref{Command Overview}), the Emacs |
| 975 | command loop displays all the warnings specified by this variable, | 1017 | command loop displays all the warnings specified by this variable, |
| 976 | then resets it to @code{nil}. | 1018 | then resets the variable to @code{nil}. |
| 977 | @end defvar | 1019 | @end defvar |
| 978 | 1020 | ||
| 979 | Programs which need to further customize the delayed warnings | 1021 | Programs which need to further customize the delayed warnings |
| @@ -982,7 +1024,9 @@ mechanism can change the variable @code{delayed-warnings-hook}: | |||
| 982 | @defvar delayed-warnings-hook | 1024 | @defvar delayed-warnings-hook |
| 983 | This is a normal hook which is run by the Emacs command loop, after | 1025 | This is a normal hook which is run by the Emacs command loop, after |
| 984 | @code{post-command-hook}, in order to process and display delayed | 1026 | @code{post-command-hook}, in order to process and display delayed |
| 985 | warnings. | 1027 | warnings. Emacs also runs this hook during startup, after loading the |
| 1028 | site-start and user init files (@pxref{Startup Summary}), because | ||
| 1029 | warnings emitted before that are automatically delayed. | ||
| 986 | 1030 | ||
| 987 | Its default value is a list of two functions: | 1031 | Its default value is a list of two functions: |
| 988 | 1032 | ||
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 3be7036f637..7c8b35236cd 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -182,7 +182,9 @@ is over, and, together with @code{before-init-time}, provides the | |||
| 182 | measurement of how long it took. | 182 | measurement of how long it took. |
| 183 | 183 | ||
| 184 | @item | 184 | @item |
| 185 | It runs the normal hook @code{after-init-hook}. | 185 | It runs the normal hooks @code{after-init-hook} and |
| 186 | @code{delayed-warnings-hook}. The latter shows any warnings emitted | ||
| 187 | during previous stages of startup, which are automatically delayed. | ||
| 186 | 188 | ||
| 187 | @item | 189 | @item |
| 188 | If the buffer @file{*scratch*} exists and is still in Fundamental mode | 190 | If the buffer @file{*scratch*} exists and is still in Fundamental mode |