aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2023-04-30 11:07:36 +0300
committerEli Zaretskii2023-04-30 11:07:36 +0300
commit7f94558b775e36042b28d3df6460463bd112dfda (patch)
treecfe41c839177b54e07f645842559ae122ed8923b
parent5a3f0e2c558d783caad6b356310217866e9cd47e (diff)
downloademacs-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.texi3
-rw-r--r--doc/lispref/display.texi214
-rw-r--r--doc/lispref/os.texi4
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.
1809In these cases, you would use @code{condition-case} to establish 1809In 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
1813current 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
1813one part of the program to another; use @code{catch} and @code{throw} 1816one part of the program to another; use @code{catch} and @code{throw}
1814instead. @xref{Catch and Throw}. 1817instead. @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
755possible problem, but continue running. 755possible problem, but continue running (as opposed to signaling an
756error, @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
769the user, and a @dfn{severity level} which is a symbol. Here are the 770the user, with the associated @dfn{severity level} which is a symbol.
770possible severity levels, in order of decreasing severity, and their 771Here are the supported severity levels, in order of decreasing
771meanings: 772severity, and their meanings:
772 773
773@table @code 774@table @code
774@item :emergency 775@item :emergency
775A problem that will seriously impair Emacs operation soon 776A problem that will seriously impair Emacs operation soon
776if you do not attend to it promptly. 777if the user does not attend to it promptly.
777@item :error 778@item :error
778A report of data or circumstances that are inherently wrong. 779A report about data or circumstances that are inherently wrong.
779@item :warning 780@item :warning
780A report of data or circumstances that are not inherently wrong, but 781A report about data or circumstances that are not inherently wrong,
781raise suspicion of a possible problem. 782but raise suspicion of a possible problem.
782@item :debug 783@item :debug
783A report of information that may be useful if you are debugging. 784A report of information that may be useful if the user is currently
785debugging 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
787signal a Lisp error by calling @code{error} or @code{signal} or report 789signal a Lisp error by calling @code{error} or @code{signal}
788a warning with severity @code{:error}. Signaling a Lisp error is the 790(@pxref{Signaling Errors}) or report a warning with severity
789easiest thing to do, but it means the program cannot continue 791@code{:error}. Signaling a Lisp error is the easiest thing to do, but
790processing. If you want to take the trouble to implement a way to 792it means the signaling program cannot continue execution. If you want
791continue processing despite the bad data, then reporting a warning of 793to take the trouble of implementing a way to continue processing
792severity @code{:error} is the right way to inform the user of the 794despite the invalid data, then reporting a warning of severity
793problem. For instance, the Emacs Lisp byte compiler can report an 795@code{:error} is the right way of informing the user of the problem.
794error that way and continue compiling other functions. (If the 796For instance, the Emacs Lisp byte compiler can report an error that
795program signals a Lisp error and then handles it with 797way and continue compiling other functions. (If the program signals a
796@code{condition-case}, the user won't see the error message; it could 798Lisp error and then handles it with @code{condition-case}, the user
797show the message to the user by reporting it as a warning.) 799won't see the error message; reporting that as a warning instead
798 800avoids 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}
804list of symbols. The first symbol should be the custom group that you 804to classify it. The warning type is either a symbol or a list of
805use for the program's user options. For example, byte compiler 805symbols. If it is a symbol, it should be the custom group that you
806warnings use the warning type @code{(bytecomp)}. You can also 806use for the program's user options; if it is a list, the first element
807subcategorize the warnings, if you wish, by using more symbols in the 807of the list should be that custom group. For example, byte compiler
808list. 808warnings use the warning type @code{(bytecomp)}. If the warning type
809is a list, the elements of the list after the first one, which should
810be arbitrary symbols, represent subcategories of the warning: they
811will be displayed to the user to better explain the nature of the
812warning.
809 813
810@defun display-warning type message &optional level buffer-name 814@defun display-warning type message &optional level buffer-name
811This function reports a warning, using @var{message} as the message 815This function reports a warning, using the string @var{message} as the
812and @var{type} as the warning type. @var{level} should be the 816warning text and @var{type} as the warning type. @var{level} should
813severity level, with @code{:warning} being the default. 817be 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
816for logging the warning. By default, it is @file{*Warnings*}. 821for 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
820This function reports a warning using the value of @code{(format-message 825This 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
822buffer. In other respects it is equivalent to @code{display-warning}. 827message text in the @file{*Warnings*} buffer. In other respects it is
828equivalent to @code{display-warning}.
823@end defun 829@end defun
824 830
825@defun warn message &rest args 831@defun warn message &rest args
826This function reports a warning using the value of @code{(format-message 832This 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
828type, and @code{:warning} as the severity level. It exists for 834message text, @code{emacs} as the warning type, and @code{:warning} as
829compatibility only; we recommend not using it, because you should 835the severity level. It exists for compatibility only; we recommend
830specify a specific warning type. 836not 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
842severity levels. Each element defines one severity level, 848severity levels. Each element defines one severity level,
843and they are arranged in order of decreasing severity. 849and they are arranged in order of decreasing severity.
844 850
845Each element has the form @code{(@var{level} @var{string} 851Each 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. 853defines. @var{string} specifies the textual description of this
848@var{string} should use @samp{%s} to specify where to put the warning 854level. @var{string} should use @samp{%s} to specify where to put the
849type information, or it can omit the @samp{%s} so as not to include 855warning type information, or it can omit the @samp{%s} so as not to
850that information. 856include that information.
851 857
852The optional @var{function}, if non-@code{nil}, is a function to call 858The optional @var{function}, if non-@code{nil}, is a function to call
853with no arguments, to get the user's attention. 859with no arguments, to get the user's attention. A notable example is
860@code{ding} (@pxref{Beeping}).
854 861
855Normally you should not change the value of this variable. 862Normally 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.
859If non-@code{nil}, the value is a function to generate prefix text for 866If non-@code{nil}, the value is a function to generate prefix text for
860warnings. Programs can bind the variable to a suitable function. 867warnings. 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
862current, and the function can insert text in it. That text becomes 869the current buffer, and the function can insert text into it. That
863the beginning of the warning message. 870text becomes the beginning of the warning message.
864 871
865The function is called with two arguments, the severity level and its 872The function is called with two arguments, the severity level and its
866entry in @code{warning-levels}. It should return a list to use as the 873entry in @code{warning-levels}. It should return a list to use
867entry (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 875of @code{warning-levels}, but it must have the same structure). By
869change the severity of the warning, or specify different handling for 876constructing this value, the function can change the severity of the
870a given severity level. 877warning, or specify different handling for a given severity level.
871 878
872If the variable's value is @code{nil} then there is no function 879If the variable's value is @code{nil}, there's no prefix text, before
873to call. 880the warning is displayed, starting with the @var{string} part of the
881entry 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
878warning should begin a series. When several warnings form a series, 886warning should begin a series. When several warnings form a series,
879that means to leave point on the first warning of the series, rather 887that means to leave point on the first warning of the series, rather
880than keep moving it for each warning so that it appears on the last one. 888than keep moving it for each warning so that it appears on the last one.
881The series ends when the local binding is unbound and 889The 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
884The value can also be a symbol with a function definition. That is 892The value can also be a symbol with a function definition. That is
885equivalent to @code{t}, except that the next warning will also call 893equivalent to @code{t}, except that the next warning will also call
886the function with no arguments with the warnings buffer current. The 894the function with no arguments with the warnings buffer the current
887function can insert text which will serve as a header for the series 895buffer. The function can, for example, insert text which will serve
888of warnings. 896as a header for the series of warnings.
889 897
890Once a series has begun, the value is a marker which points to the 898Once a series has begun, the value of this variable is a marker which
891buffer position in the warnings buffer of the start of the series. 899points to the buffer position in the warnings buffer of the start of
900the series.
892 901
893The variable's normal value is @code{nil}, which means to handle 902The variable's normal value is @code{nil}, which means to handle
894each warning separately. 903each warning separately.
@@ -896,7 +905,7 @@ each warning separately.
896 905
897@defvar warning-fill-prefix 906@defvar warning-fill-prefix
898When this variable is non-@code{nil}, it specifies a fill prefix to 907When this variable is non-@code{nil}, it specifies a fill prefix to
899use for filling each warning's text. 908use 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
907This variable specifies the format for displaying the warning type 916This variable specifies the format for displaying the warning type
908in the warning message. The result of formatting the type this way 917in the warning text. The result of formatting the type this way
909gets included in the message under the control of the string in the 918gets included in the message under the control of the string in the
910entry in @code{warning-levels}. The default value is @code{" (%s)"}. 919entry in @code{warning-levels}. The default value is @code{" (%s)"}.
911If you bind it to @code{""} then the warning type won't appear at 920If you bind it to the empty string @code{""} then the warning type
912all. 921won'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
923This user option specifies the minimum severity level that should be 932This user option specifies the minimum severity level that should be
924shown immediately to the user. The default is @code{:warning}, which 933shown immediately to the user, by popping the warnings buffer in some
925means to immediately display all warnings except @code{:debug} 934window. The default is @code{:warning}, which means to show the
926warnings. 935warning buffer for any warning severity except @code{:debug}. The
936warnings of lower severity levels will still be written into the
937warnings 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
930This user option specifies the minimum severity level that should be 941This user option specifies the minimum severity level that should be
931logged in the warnings buffer. The default is @code{:warning}, which 942logged in the warnings buffer. Warnings of lower severity will be
932means to log all warnings except @code{:debug} warnings. 943completely ignored: not written to the warnings buffer and not
944displayed. The default is @code{:warning}, which means to log
945warnings of any severity except @code{:debug}.
933@end defopt 946@end defopt
934 947
935@defopt warning-suppress-types 948@defopt warning-suppress-types
936This list specifies which warning types should not be displayed 949This list specifies which warning types should not be displayed
937immediately for the user. Each element of the list should be a list 950immediately when they occur. Each element of the list should be a
938of symbols. If its elements match the first elements in a warning 951list of symbols. If an element of this list has the same elements as
939type, then that warning is not displayed immediately. 952the first elements in a warning type, then the warning of that type
953will not be shown on display by popping the warnings buffer in some
954window (the warning will still be logged in the warnings buffer).
955
956For 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
963then warnings whose types are @code{foo} or @code{(foo)} or
964@w{@code{(foo something)}} or @w{@code{(bar subtype other)}} will not
965be shown to the user.
940@end defopt 966@end defopt
941 967
942@defopt warning-suppress-log-types 968@defopt warning-suppress-log-types
943This list specifies which warning types should not be logged in the 969This list specifies which warning types should be ignored: not logged
944warnings buffer. Each element of the list should be a list of 970in the warnings buffer and not shown to the user. The structure and
945symbols. If it matches the first few elements in a warning type, then 971the matching of warning types are the same as for
946that 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
978loads and processes the site-wide and user's init files
979(@pxref{Startup Summary}). Let-binding (@pxref{Local Variables}) the
980values of these options around some code in your init files which
981might emit a warning will therefore not work, because it will not be
982in effect by the time the warning is actually processed. Thus, if you
983want to suppress some warnings during startup, change the values of
984the above options in your init file early enough, or put those
985let-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
953Sometimes, you may wish to avoid showing a warning while a command is 993Sometimes, you may wish to avoid showing a warning while a command is
954running, and only show it only after the end of the command. You can 994running, and only show it only after the end of the command. You can
955use the function @code{delay-warning} for this. 995use the function @code{delay-warning} for this. Emacs automatically
996delays any warnings emitted during the early stages of startup, and
997shows 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
958This function is the delayed counterpart to @code{display-warning} 1000This 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
975command loop displays all the warnings specified by this variable, 1017command loop displays all the warnings specified by this variable,
976then resets it to @code{nil}. 1018then 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
983This is a normal hook which is run by the Emacs command loop, after 1025This 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
985warnings. 1027warnings. Emacs also runs this hook during startup, after loading the
1028site-start and user init files (@pxref{Startup Summary}), because
1029warnings emitted before that are automatically delayed.
986 1030
987Its default value is a list of two functions: 1031Its 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
182measurement of how long it took. 182measurement of how long it took.
183 183
184@item 184@item
185It runs the normal hook @code{after-init-hook}. 185It runs the normal hooks @code{after-init-hook} and
186@code{delayed-warnings-hook}. The latter shows any warnings emitted
187during previous stages of startup, which are automatically delayed.
186 188
187@item 189@item
188If the buffer @file{*scratch*} exists and is still in Fundamental mode 190If the buffer @file{*scratch*} exists and is still in Fundamental mode