1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

; Improve documentation of :predicate in globalized minor modes

* doc/lispref/modes.texi (Defining Minor Modes):
* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Improve documentation of the :predicate keyword in defining
globalized minor modes.
This commit is contained in:
Eli Zaretskii 2023-03-23 11:30:19 +02:00
parent 930b9fdd3a
commit bcd02cf512
2 changed files with 39 additions and 23 deletions

View file

@ -1775,6 +1775,8 @@ it's used to say which major modes this minor mode is useful in.
Any other keyword arguments are passed directly to the Any other keyword arguments are passed directly to the
@code{defcustom} generated for the variable @var{mode}. @code{defcustom} generated for the variable @var{mode}.
@xref{Variable Definitions}, for the description of those keywords and
their values.
The command named @var{mode} first performs the standard actions such as The command named @var{mode} first performs the standard actions such as
setting the variable named @var{mode} and then executes the @var{body} setting the variable named @var{mode} and then executes the @var{body}
@ -1860,9 +1862,10 @@ by visiting files, and buffers that use a major mode other than
Fundamental mode; but it does not detect the creation of a new buffer Fundamental mode; but it does not detect the creation of a new buffer
in Fundamental mode. in Fundamental mode.
This defines the customization option @var{global-mode} (@pxref{Customization}), This macro defines the customization option @var{global-mode}
which can be toggled in the Customize interface to turn the minor mode on (@pxref{Customization}), which can be toggled via the Customize
and off. As with @code{define-minor-mode}, you should ensure that the interface to turn the minor mode on and off. As with
@code{define-minor-mode}, you should ensure that the
@code{define-globalized-minor-mode} form is evaluated each time Emacs @code{define-globalized-minor-mode} form is evaluated each time Emacs
starts, for example by providing a @code{:require} keyword. starts, for example by providing a @code{:require} keyword.
@ -1875,24 +1878,27 @@ Use @code{:variable @var{variable}} if that's not the case--some minor
modes use a different variable to store this state information. modes use a different variable to store this state information.
Generally speaking, when you define a globalized minor mode, you should Generally speaking, when you define a globalized minor mode, you should
also define a non-globalized version, so that people can use (or also define a non-globalized version, so that people could use it (or
disable) it in individual buffers. This also allows them to disable a disable it) in individual buffers. This also allows them to disable a
globally enabled minor mode in a specific major mode, by using that globally enabled minor mode in a specific major mode, by using that
mode's hook. mode's hook.
If given a @code{:predicate} keyword, a user option called the same as If the macro is given a @code{:predicate} keyword, it will create a
the global mode variable, but with @code{-modes} instead of user option called the same as the global mode variable, but with
@code{-mode} at the end will be created. The variable is used as a @code{-modes} instead of @code{-mode} at the end, i.e.@:
predicate that specifies which major modes the minor mode should be @code{@var{global-mode}s}. This variable will be used in a predicate
activated in. Valid values include @code{t} (use in all major modes, function that determines whether the minor mode should be activated in
@code{nil} (use in no major modes), or a list of mode names (or a particular major mode. Valid values of @code{:predicate} include
@code{(not mode-name ...)}) elements (as well as @code{t} and @code{t} (use in all major modes), @code{nil} (don't use in any major
@code{nil}). modes), or a list of mode names, optionally preceded with @code{not}
(as in @w{@code{(not @var{mode-name} @dots{})}}). These elements can
be mixed, as shown in the following examples.
@example @example
(c-mode (not mail-mode message-mode) text-mode) (c-mode (not mail-mode message-mode) text-mode)
@end example @end example
@noindent
This means ``use in modes derived from @code{c-mode}, and not in This means ``use in modes derived from @code{c-mode}, and not in
modes derived from @code{message-mode} or @code{mail-mode}, but do use modes derived from @code{message-mode} or @code{mail-mode}, but do use
in modes derived from @code{text-mode}, and otherwise no other in modes derived from @code{text-mode}, and otherwise no other
@ -1902,13 +1908,15 @@ modes''.
((not c-mode) t) ((not c-mode) t)
@end example @end example
This means ``don't use modes derived from @code{c-mode}, but use @noindent
This means ``don't use in modes derived from @code{c-mode}, but do use
everywhere else''. everywhere else''.
@example @example
(text-mode) (text-mode)
@end example @end example
@noindent
This means ``use in modes derived from @code{text-mode}, but nowhere This means ``use in modes derived from @code{text-mode}, but nowhere
else''. (There's an implicit @code{nil} element at the end.) else''. (There's an implicit @code{nil} element at the end.)
@end defmac @end defmac

View file

@ -449,15 +449,23 @@ No problems result if this variable is not bound.
TURN-ON is a function that will be called with no args in every buffer TURN-ON is a function that will be called with no args in every buffer
and that should try to turn MODE on if applicable for that buffer. and that should try to turn MODE on if applicable for that buffer.
Each of KEY VALUE is a pair of CL-style keyword arguments. :predicate Each of KEY VALUE is a pair of CL-style keyword arguments.
specifies which major modes the globalized minor mode should be switched on The :predicate argument specifies in which major modes should the
in. As the minor mode defined by this function is always global, any globalized minor mode be switched on. The value should be t (meaning
:global keyword is ignored. Other keywords have the same meaning as in switch on the minor mode in all major modes), nil (meaning don't
`define-minor-mode', which see. In particular, :group specifies the custom switch on in any major mode), a list of modes (meaning switch on only
group. The most useful keywords are those that are passed on to the in those modes and their descendants), or a list (not MODES...),
`defcustom'. It normally makes no sense to pass the :lighter or :keymap meaning switch on in any major mode except MODES. The value can also
keywords to `define-globalized-minor-mode', since these are usually passed mix all of these forms, see the info node `Defining Minor Modes' for
to the buffer-local version of the minor mode. details.
As the minor mode defined by this function is always global, any
:global keyword is ignored.
Other keywords have the same meaning as in `define-minor-mode',
which see. In particular, :group specifies the custom group.
The most useful keywords are those that are passed on to the `defcustom'.
It normally makes no sense to pass the :lighter or :keymap keywords
to `define-globalized-minor-mode', since these are usually passed to
the buffer-local version of the minor mode.
BODY contains code to execute each time the mode is enabled or disabled. BODY contains code to execute each time the mode is enabled or disabled.
It is executed after toggling the mode, and before running It is executed after toggling the mode, and before running