emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/sweeprolog 33323c7586 4/6: ENHANCED: use argument names fo


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 33323c7586 4/6: ENHANCED: use argument names for holes in predicate completion
Date: Sun, 27 Nov 2022 14:59:31 -0500 (EST)

branch: elpa/sweeprolog
commit 33323c75863b3b3ad8313161d29c59546e40191b
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    ENHANCED: use argument names for holes in predicate completion
    
    * sweep.pl (predicate_argument_names/2): new predicate.
    (sweep_format_predicate/2): use it, and revise into...
    (sweep_format_predicate/4): new predicate.
    (sweep_predicate_completion_candidates): use it.
---
 sweep.pl | 49 ++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/sweep.pl b/sweep.pl
index 2eeb37d162..1aaa7558e7 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -775,29 +775,37 @@ sweep_atom_collection(Sub, Col) :-
 
 sweep_predicate_completion_candidates(D, Ps) :-
     integer(D),
+    sweep_current_module(M),
     findall(H,
-            (   sweep_current_module(M),
-                (   @(predicate_property(H0, visible), M)
-                ;   xref_defined(_, H0, _)
+            (   (   @(predicate_property(H, visible), M)
+                ;   xref_defined(_, H, _)
                 ),
-                adjust_arity(D, H0, H)
+                pi_head(_/N, H),
+                N - D >= 0
             ),
             Hs),
-    maplist(sweep_format_predicate, Hs, Ps).
-
-adjust_arity(0, H, H) :- !.
-adjust_arity(D, H0, H) :- pi_head(F/N0, H0), !, N is N0 - D, N >= 0, 
pi_head(F/N, H).
-adjust_arity(D, H0, H) :- pi_head(M:F/N0, H0), N is N0 - D, N >= 0, 
pi_head(M:F/N, H).
-
-sweep_format_predicate(H, [S|SP]) :-
-    term_variables(H, Vs),
-    maplist(=('$VAR'('_')), Vs),
+    maplist(sweep_format_predicate(M, D), Hs, Ps).
+
+sweep_format_predicate(M0, D, H0, [S|SP]) :-
+    pi_head(F/N0, H0),
+    N is N0 - D,
+    length(NamedArgs, N),
+    append(NamedArgs, _, OpenNamedArgs),
+    (   @(predicate_property(H0, implementation_module(M)), M0),
+        predicate_argument_names(M:F/N0, As)
+    ->  maplist(name_variable, As, Vs), OpenNamedArgs = Vs
+    ;   maplist(=('$VAR'('_')), NamedArgs)
+    ),
+    !,
+    H =.. [F|NamedArgs],
     term_string(H, S, [quoted(true),
                        character_escapes(true),
                        spacing(next_argument),
                        numbervars(true)]),
     term_string(_, S, [subterm_positions(SP)]).
 
+name_variable(N, V) :- V = '$VAR'(N).
+
 sweep_context_callable([H|T], R) :-
     H = [F0|_],
     atom_string(F, F0),
@@ -882,3 +890,18 @@ sweep_file_path_in_library(Path, Spec) :-
     file_name_on_path(Path, Spec0),
     prolog_deps:segments(Spec0, Spec1),
     term_string(Spec1, Spec).
+
+predicate_argument_names(M:F/A, Args) :-
+    doc_comment(M:F/A, _, _, C),
+    comment_modes(C, ModeAndDets),
+    member(ModeAndDet, ModeAndDets),
+    strip_det(ModeAndDet, Head),
+    Head =.. [_|Args0],
+    length(Args0, A),
+    maplist(strip_mode_and_type, Args0, Args).
+
+strip_mode_and_type(S, N), compound(S) => arg(1, S, N0), strip_type(N0, N).
+strip_mode_and_type(S, N) => strip_type(S, N).
+
+strip_type(N:_, N) :- !.
+strip_type(N, N).



reply via email to

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