From 0406742c335c91cfad4d185d2d68fc981bc5e40f Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 20 May 2023 17:52:17 +0300 Subject: [PATCH] ENHANCED: faster completion-at-point for predicates Filter predicate completion candidates according to the text near point before formatting and computing argument names. This makes completion-at-point for predicates much faster when there are lots of known predicates. * sweeprolog.el (sweeprolog-predicate-completion-at-point): Pass (partial) functor at point to... * sweep.pl (sweep_predicate_completion_candidates/2): Filter predicates based on new Sub argument. --- sweep.pl | 7 ++++--- sweeprolog.el | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sweep.pl b/sweep.pl index 71c63fe..154b50a 100644 --- a/sweep.pl +++ b/sweep.pl @@ -865,18 +865,19 @@ sweep_atom_collection(Sub, Col) :- findall(S, ( current_atom(A), atom_string(A, S), - sub_string(S, _, _, _, Sub) + once(sub_string(S, _, _, _, Sub)) ), Col). -sweep_predicate_completion_candidates(D, Ps) :- +sweep_predicate_completion_candidates([D|Sub], Ps) :- integer(D), sweep_current_module(M), findall(H, ( ( @(predicate_property(H, visible), M) ; xref_defined(_, H, _) ), - pi_head(_/N, H), + pi_head(F/N, H), + once(sub_atom(F, _, _, _, Sub)), N - D >= 0 ), Hs), diff --git a/sweeprolog.el b/sweeprolog.el index 1900241..e0faa14 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -1240,8 +1240,10 @@ resulting list even when found in the current clause." (not (or (sweeprolog--char-uppercase-p first) (= first ?_))))) (when-let - ((col (sweeprolog--query-once "sweep" "sweep_predicate_completion_candidates" - (sweeprolog-context-callable-p)))) + ((col (sweeprolog--query-once + "sweep" "sweep_predicate_completion_candidates" + (cons (sweeprolog-context-callable-p) + (buffer-substring-no-properties beg end))))) (list beg end col :exclusive 'no :annotation-function -- 2.39.2