bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#52202: [PATCH] try-completion, all-completions support for a list of


From: Matt Armstrong
Subject: bug#52202: [PATCH] try-completion, all-completions support for a list of strings COLLECTION is not documented in their docstrings
Date: Tue, 30 Nov 2021 11:18:05 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Attached is a docstring patch against the emacs-28 branch for this
issue.

Note/question: I wonder if the `all-completions' docstring should refer
to `try-completion' rather than copy much of the text.  The same
approach works well in the lisp ref manual, I think.

>From 8bc1bee134f0626513efd00f4a283cf5a2d2a359 Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Tue, 30 Nov 2021 10:54:17 -0800
Subject: [PATCH] Improve the `try-completion' and `all-completions' docstrings

* src/minibuf.c (Ftry_completion):
(Fall_completions): Use language from the Emacs lisp manual when
talking about the COLLECTION and PREDICATE arguments.  Most notably,
the way completion tables may be passed is now more clear.  The prior
docstring did not mention lists of strings/symbols at all.  Bug#52202
---
 src/minibuf.c | 124 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 77 insertions(+), 47 deletions(-)

diff --git a/src/minibuf.c b/src/minibuf.c
index 6c0cd358c5..f1ee7b2453 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1569,34 +1569,49 @@ match_regexps (Lisp_Object string, Lisp_Object regexps,
 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
        doc: /* Return common substring of all completions of STRING in 
COLLECTION.
 Test each possible completion specified by COLLECTION
-to see if it begins with STRING.  The possible completions may be
-strings or symbols.  Symbols are converted to strings before testing,
-see `symbol-name'.
-All that match STRING are compared together; the longest initial sequence
-common to all these matches is the return value.
-If there is no match at all, the return value is nil.
-For a unique match which is exact, the return value is t.
-
-If COLLECTION is an alist, the keys (cars of elements) are the
-possible completions.  If an element is not a cons cell, then the
-element itself is the possible completion.
-If COLLECTION is a hash-table, all the keys that are strings or symbols
-are the possible completions.
-If COLLECTION is an obarray, the names of all symbols in the obarray
-are the possible completions.
+to see if it begins with STRING.
 
-COLLECTION can also be a function to do the completion itself.
-It receives three arguments: the values STRING, PREDICATE and nil.
+All completions that match STRING are compared together; the longest
+initial sequence common to all these matches is the return value.  If
+there is no match at all, the return value is nil.  For a unique match
+which is exact, the return value is t.
+
+COLLECTION is called the "completion table."  Its value must be a
+list, a hash table, an obarray, or a completion function.
+
+If COLLECTION is a list, the possible completions are specified by the
+elements of the list, each of which should be either a string, a
+symbol, or a cons cell whose CAR is either a string or a symbol.  If
+the list contains elements of any other type, those are ignored.
+
+If COLLECTION is a hash-table, all the keys that are strings or
+symbols are the possible completions.
+
+If COLLECTION is an obarray, all the symbols in the obarray are the
+possible completions.
+
+The possible completions from COLLECTION that are symbols are
+converted to strings before testing, see `symbol-name'.
+
+COLLECTION can also be a function to do the completion itself.  It
+receives three arguments: the values STRING, PREDICATE and nil (the
+third argument is so that the same function can be used in
+‘all-completions’ and do the appropriate thing in either case).
 Whatever it returns becomes the value of `try-completion'.
 
-If optional third argument PREDICATE is non-nil,
-it is used to test each possible match.
-The match is a candidate only if PREDICATE returns non-nil.
-The argument given to PREDICATE is the alist element
-or the symbol from the obarray.  If COLLECTION is a hash-table,
-predicate is called with two arguments: the key and the value.
-Additionally to this predicate, `completion-regexp-list'
-is used to further constrain the set of candidates.  */)
+If optional third argument PREDICATE is non-nil, it is used to test
+each possible match.  The match is a candidate only if PREDICATE
+returns non-nil.  The argument given to PREDICATE is an element from
+COLLECTION.  If COLLECTION is a list it is a list element (either a
+symbol, string, or cons cell whose CAR is a symbol or string).  If
+COLLECTION is an obarray, a symbol from it.  If COLLECTION is a
+hash-table, predicate is called with two arguments: a key and the
+value.
+
+In addition, to be acceptable, a completion must also match all the
+regular expressions in ‘completion-regexp-list’.  (Unless COLLECTION
+is a function, in which case that function has to handle
+‘completion-regexp-list’ itself.)  */)
   (Lisp_Object string, Lisp_Object collection, Lisp_Object predicate)
 {
 
@@ -1808,31 +1823,46 @@ DEFUN ("try-completion", Ftry_completion, 
Stry_completion, 2, 3, 0,
 DEFUN ("all-completions", Fall_completions, Sall_completions, 2, 4, 0,
        doc: /* Search for partial matches to STRING in COLLECTION.
 Test each of the possible completions specified by COLLECTION
-to see if it begins with STRING.  The possible completions may be
-strings or symbols.  Symbols are converted to strings before testing,
-see `symbol-name'.
-The value is a list of all the possible completions that match STRING.
-
-If COLLECTION is an alist, the keys (cars of elements) are the
-possible completions.  If an element is not a cons cell, then the
-element itself is the possible completion.
-If COLLECTION is a hash-table, all the keys that are strings or symbols
-are the possible completions.
-If COLLECTION is an obarray, the names of all symbols in the obarray
-are the possible completions.
+to see if it begins with STRING.
+The value is a list of strings for all the possible completions that
+match STRING.
 
-COLLECTION can also be a function to do the completion itself.
-It receives three arguments: the values STRING, PREDICATE and t.
+COLLECTION is called the "completion table."  Its value must be a
+list, a hash table, an obarray, or a completion function.
+
+If COLLECTION is a list, the permissible completions are specified by
+the elements of the list, each of which should be either a string, a
+symbol, or a cons cell whose CAR is either a string or a symbol.  If
+the list contains elements of any other type, those are ignored.
+
+If COLLECTION is a hash-table, all the keys that are strings or
+symbols are the possible completions.
+
+If COLLECTION is an obarray, all the symbols in the obarray are the
+possible completions.
+
+The possible completions from COLLECTION that are symbols are
+converted to strings before testing, see `symbol-name'.
+
+COLLECTION can also be a function to do the completion itself.  It
+receives three arguments: the values STRING, PREDICATE and t (the
+third argument is so that the same function can be used in
+‘try-completion’ and do the appropriate thing in either case).
 Whatever it returns becomes the value of `all-completions'.
 
-If optional third argument PREDICATE is non-nil,
-it is used to test each possible match.
-The match is a candidate only if PREDICATE returns non-nil.
-The argument given to PREDICATE is the alist element
-or the symbol from the obarray.  If COLLECTION is a hash-table,
-predicate is called with two arguments: the key and the value.
-Additionally to this predicate, `completion-regexp-list'
-is used to further constrain the set of candidates.
+If optional third argument PREDICATE is non-nil, it is used to test
+each possible match.  The match is a candidate only if PREDICATE
+returns non-nil.  The argument given to PREDICATE is an element from
+COLLECTION.  If COLLECTION is a list it is a list element (either a
+symbol, string, or cons cell whose CAR is a symbol or string).  If
+COLLECTION is an obarray, a symbol from it.  If COLLECTION is a
+hash-table, predicate is called with two arguments: a key and the
+value.
+
+In addition, to be acceptable, a completion must also match all the
+regular expressions in ‘completion-regexp-list’.  (Unless COLLECTION
+is a function, in which case that function has to handle
+‘completion-regexp-list’ itself.)
 
 An obsolete optional fourth argument HIDE-SPACES is still accepted for
 backward compatibility.  If non-nil, strings in COLLECTION that start
-- 
2.33.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]