Subject: bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer

From: Eric Abrahamsen <[email-masked]>
Date: Mon, 11 Dec 2017 21:42:43 -0800

Noam Postavsky <[email-masked]> writes:

> [forwarding to list]

Whoops, sorry.

[...]

>> A year later, older and wiser, I agree that maybe all that's needed is
>> more documentation. I just noticed that, at some point in the interim,
>> the documentation for generic functions has been greatly expanded, which
>> is nice!
>>
>> I'd like to add the following to the docs:
>>
>> 1. The &context thing has to come after the required arguments, but
>>    before any &optional or &rest things.
>> 2. You can have an arbitrary number of forms following &context.
>> 3. The &context arguments don't have to match the declared arguments in
>>    `cl-defgeneric'.
>> 4. Ergo they can be left off altogether without needing to be
>>    specifically declared as nil or what have you, ie, my original bug
>>    report isn't really a bug.
>>
>> If this looks okay, I'll have at the docs.

> Sounds good to me.

Here's my diff.

diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 466a12f7a4..6b98a3d639 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -1252,15 +1252,21 @@ Generic Functions
 Extensions for GNU Emacs Lisp}), or of one of its parent classes.
 @end table
 
-Alternatively, the argument specializer can be of the form
-@code{&context (@var{expr} @var{spec})}, in which case the value of
-@var{expr} must be compatible with the specializer provided by
-@var{spec}; @var{spec} can be any of the forms described above.  In
-other words, this form of specializer uses the value of @var{expr}
-instead of arguments for the decision whether the method is
-applicable.  For example, @code{&context (overwrite-mode (eql t))}
-will make the method compatible only when @code{overwrite-mode} is
-turned on.
+Generic functions provide a new argument-list keyword,
+@code{&context}, which can be used to introduce extra specializers
+that test the general environment in which the method is run.  This
+keyword should appear after the list of required arguments, but before
+any @code{&rest} or @code{&optional} keywords.  The @code{&context}
+specializers look much like regular argument
+specializers---(@var{expr} @var{spec})---except that @var{expr} is an
+expression to be evaluated in the current context, and the @var{spec}
+is a value to compare against.  For example, @code{&context
+(overwrite-mode (eql t))} will make the method applicable only when
+@code{overwrite-mode} is turned on.  The @code{&context} keyword can
+be followed by any number of context specializers.  Because the
+context specializers are not part of the generic function's required
+argument signature, they may be omitted in methods that don't require
+them.
 
 The type specializer, @code{(@var{arg} @var{type})}, can specify one
 of the @dfn{system types} in the following list.  When a parent type