[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
pkg 8561667124 33/76: Handle packages in completion
From: |
Gerd Moellmann |
Subject: |
pkg 8561667124 33/76: Handle packages in completion |
Date: |
Fri, 21 Oct 2022 00:16:11 -0400 (EDT) |
branch: pkg
commit 856166712438166741933e76b948c825a7661b21
Author: Gerd Möllmann <gerd@gnu.org>
Commit: Gerd Möllmann <gerd@gnu.org>
Handle packages in completion
* lisp/minibuffer.el (completion-table-with-context): Add packagep
case.
* src/minibuf.c (Ftry_completion, Fall_completions),
Ftest_completion): Take into account that predicate functions used
with packages are the same that were used for obarrays.
---
lisp/minibuffer.el | 2 ++
src/minibuf.c | 65 ++++++++++++++++++++++++++++++++++++------------------
2 files changed, 46 insertions(+), 21 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 9f26e4f7f9..bf9321c5fa 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -313,6 +313,8 @@ the form (concat S2 S)."
;; Predicates are called differently depending on the nature of
;; the completion table :-(
(cond
+ ((packagep table)
+ (lambda (sym) (funcall pred (concat prefix (symbol-name sym)))))
((vectorp table) ;Obarray.
(lambda (sym) (funcall pred (concat prefix (symbol-name sym)))))
((hash-table-p table)
diff --git a/src/minibuf.c b/src/minibuf.c
index 02bbb0df35..886d2dec93 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1622,7 +1622,13 @@ or from one of the possible completions. */)
if (FUNCTIONP (collection))
return call3 (collection, string, predicate, Qnil);
- if (PACKAGEP (collection))
+ /* Use a package's symbol table for completion, but remember that we
+ are working on a package, because we are called with a predicate
+ that takes only one argument, which is a remnant ob obarrays.
+ Sad that we are receiving predicates of different arity depending
+ on the type of collection. */
+ const bool symbol_table_p = PACKAGEP (collection);
+ if (symbol_table_p)
collection = PACKAGE_SYMBOLS (collection);
ptrdiff_t idx = 0;
@@ -1689,15 +1695,18 @@ or from one of the possible completions. */)
{
if (EQ (predicate, Qcommandp))
tem = Fcommandp (elt, Qnil);
- else
+ else if (HASH_TABLE_P (collection))
{
- tem = (HASH_TABLE_P (collection)
- ? call2 (predicate, elt,
- HASH_VALUE (XHASH_TABLE (collection),
- idx - 1))
- : call1 (predicate, elt));
+ const Lisp_Object value = HASH_VALUE (XHASH_TABLE
(collection), idx - 1);
+ if (symbol_table_p)
+ tem = call1 (predicate, value);
+ else
+ tem = call2 (predicate, elt, value);
}
- if (NILP (tem)) continue;
+ else
+ tem = call1 (predicate, elt);
+ if (NILP (tem))
+ continue;
}
/* Update computation of how much all possible completions match */
@@ -1843,7 +1852,13 @@ with a space are ignored unless STRING itself starts
with a space. */)
if (type == 0)
return call3 (collection, string, predicate, Qt);
- if (type == 2)
+ /* Use a package's symbol table for completion, but remember that we
+ are working on a package, because we are called with a predicate
+ that takes only one argument, which is a remnant ob obarrays.
+ Sad that we are receiving predicates of different arity depending
+ on the type of collection. */
+ const bool symbol_table_p = PACKAGEP (collection);
+ if (symbol_table_p)
{
collection = PACKAGE_SYMBOLS (collection);
type = 3;
@@ -1914,13 +1929,16 @@ with a space are ignored unless STRING itself starts
with a space. */)
{
if (EQ (predicate, Qcommandp))
tem = Fcommandp (elt, Qnil);
- else
+ else if (HASH_TABLE_P (collection))
{
- tem = type == 3
- ? call2 (predicate, elt,
- HASH_VALUE (XHASH_TABLE (collection), idx - 1))
- : call1 (predicate, elt);
+ const Lisp_Object value = HASH_VALUE (XHASH_TABLE
(collection), idx - 1);
+ if (symbol_table_p)
+ tem = call1 (predicate, value);
+ else
+ tem = call2 (predicate, elt, value);
}
+ else
+ tem = call1 (predicate, elt);
if (NILP (tem)) continue;
}
/* Ok => put it on the list. */
@@ -2019,7 +2037,8 @@ the values STRING, PREDICATE and `lambda'. */)
CHECK_STRING (string);
- if (PACKAGEP (collection))
+ const bool symbol_table_p = PACKAGEP (collection);
+ if (symbol_table_p)
collection = PACKAGE_SYMBOLS (collection);
if (NILP (collection) || (CONSP (collection) && !FUNCTIONP (collection)))
@@ -2062,14 +2081,18 @@ the values STRING, PREDICATE and `lambda'. */)
return Qnil;
/* Finally, check the predicate. */
- if (!NILP (predicate))
+ if (NILP (predicate))
+ return Qt;
+
+ if (HASH_TABLE_P (collection))
{
- return HASH_TABLE_P (collection)
- ? call2 (predicate, tem, HASH_VALUE (XHASH_TABLE (collection), i))
- : call1 (predicate, tem);
+ const Lisp_Object value = HASH_VALUE (XHASH_TABLE (collection), i);
+ if (symbol_table_p)
+ return call1 (predicate, value);
+ return call2 (predicate, tem, value);
}
- else
- return Qt;
+
+ return call1 (predicate, tem);
}
DEFUN ("internal-complete-buffer", Finternal_complete_buffer,
Sinternal_complete_buffer, 3, 3, 0,
- branch pkg created (now a93ec52542), Gerd Moellmann, 2022/10/21
- pkg 02e1214f23 06/76: More stuff in pkg.c, Gerd Moellmann, 2022/10/21
- pkg 2821ca31ae 20/76: Use packages instead of obarrays in obarray.el, Gerd Moellmann, 2022/10/21
- pkg 7ecfc3ca69 13/76: Can now pdump, Gerd Moellmann, 2022/10/21
- pkg b3cdb8a3d3 11/76: Intern keywords differently, Gerd Moellmann, 2022/10/21
- pkg 47a2e75c1c 07/76: Read symbols differently, Gerd Moellmann, 2022/10/21
- pkg b5c199b118 08/76: Check for keywords differently, Gerd Moellmann, 2022/10/21
- pkg bb6b5db2b7 24/76: Dpn't assume symbol-name of keywords starts with colon, Gerd Moellmann, 2022/10/21
- pkg c025885c33 41/76: symbol-name returning ':' for keywords, Gerd Moellmann, 2022/10/21
- pkg 8561667124 33/76: Handle packages in completion,
Gerd Moellmann <=
- pkg df9417ac57 66/76: Remove Lisp_Symbol::external, Gerd Moellmann, 2022/10/21
- pkg 85bd8cfcdb 18/76: Mapping over symbols in a package, mapatoms, Gerd Moellmann, 2022/10/21
- pkg 62c7059adc 19/76: Initialize package system earlier, Gerd Moellmann, 2022/10/21
- pkg a19917468c 04/76: Don't fix symbols here, Gerd Moellmann, 2022/10/21
- pkg 072e89afa1 23/76: Use make-package instead of make-vector, Gerd Moellmann, 2022/10/21
- pkg f6b80ef5a5 25/76: Blabla, Gerd Moellmann, 2022/10/21
- pkg 2ed1ac6639 09/76: Fixing stuff, Gerd Moellmann, 2022/10/21
- pkg 1d02e7a48b 02/76: Add xprint command, Gerd Moellmann, 2022/10/21
- pkg a3f99fde48 22/76: Remove Lisp_Symbol::next pointer, Gerd Moellmann, 2022/10/21
- pkg 2518bc249c 39/76: Fix printing symbols, Gerd Moellmann, 2022/10/21