From: Eshel Yaron Date: Sat, 28 Jan 2023 16:38:00 +0000 (+0200) Subject: ENHANCED: use docs from the SWI-Prolog manual to guess hole names X-Git-Tag: V9.1.4-sweep-0.14.1~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=447c530c26b52d7678fed4a7b123249fda40e3c2;p=dict.git ENHANCED: use docs from the SWI-Prolog manual to guess hole names * sweep.pl (predicate_argument_names/2): also consult the SWI-Prolog manual via pldoc_man:load_man_object/4 to find argument names for built-in predicates. --- diff --git a/README.org b/README.org index 67d436c..784c417 100644 --- a/README.org +++ b/README.org @@ -1455,9 +1455,9 @@ prefix argument (~C-u C-c C-e~). ~sweeprolog-mode~ empowers Emacs's standard ~completion-at-point~ command, bound by default to ~C-M-i~ and ~M-TAB~, with context-aware completion for Prolog terms. For background about completion-at-point in Emacs, see [[info:emacs#Symbol -Completion][Symbol Completion in the Emacs manual]]. +Completion][Symbol Completion]] in the Emacs manual. -In ~sweeprolog-mode~ buffers, the following enhancements are provided: +Sweep provides the following Prolog-specific completion facilities: - Variable name completion :: If the text before point can be completed to one or more variable names that appear elsewhere in the @@ -1468,7 +1468,7 @@ In ~sweeprolog-mode~ buffers, the following enhancements are provided: candidates. Predicate calls are inserted as complete term. If the chosen predicate takes arguments, holes are inserted in their places (see [[#holes][Holes]]). -- Atom completion :: If point is at a non-callable, +- Atom completion :: If point is at a non-callable position, ~completion-at-point~ suggests matching atoms as completion candidates. diff --git a/sweep.pl b/sweep.pl index 302f9fe..0a02caf 100644 --- a/sweep.pl +++ b/sweep.pl @@ -959,13 +959,39 @@ sweep_file_path_in_library(Path, Spec) :- ; term_string(Spec1, Spec) ). +predicate_argument_names(M:F/A, Args) :- + ( M == system + -> true + ; sub_atom(M, 0, 1, _, '$') + ), + pldoc_man:load_man_object(F/A, _, _, DOM0), + memberchk(element(dt, _, DOM1), DOM0), + memberchk(element(a, _, DOM2), DOM1), + catch(findall(Arg, + ( member(element(var, _, Vars), DOM2), + member(ArgsSpec, Vars), + term_string(CommaSeparatedArgs, + ArgsSpec, + [module(pldoc_modes), + variable_names(VN)]), + maplist(call, VN), + comma_list(CommaSeparatedArgs, ArgsList), + member(Arg, ArgsList) + ), + Args0), + error(syntax_error(_),_), + fail), + predicate_argument_names_(A, Args0, Args). 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), + predicate_argument_names_(A, Args0, Args). + +predicate_argument_names_(Arity, Args0, Args) :- + length(Args0, Arity), maplist(strip_mode_and_type, Args0, Args). strip_mode_and_type(S, N), compound(S) => arg(1, S, N0), strip_type(N0, N). diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index c4e3b1f..c1551c3 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -443,7 +443,7 @@ baz(Baz) :- findall(X, b_g (call-interactively #'completion-at-point) (should (string= (buffer-string) " -baz(Baz) :- findall(X, b_getval(_, _) +baz(Baz) :- findall(X, b_getval(Name, Value) " ))))