From: Eshel Yaron Date: Sat, 3 Sep 2022 06:04:45 +0000 (+0300) Subject: ENHANCED: show more relevant candidates in top-level completion X-Git-Tag: v0.2.0~50 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a26ca14c81f6c2361ed3837a575cd5c2f86eaa3c;p=sweep.git ENHANCED: show more relevant candidates in top-level completion --- diff --git a/sweep.el b/sweep.el index b984b42..e5af560 100644 --- a/sweep.el +++ b/sweep.el @@ -66,8 +66,7 @@ :type '(list string) :group 'sweep) - -(defvar sweep-prolog-server-port 12345) +(defvar sweep-prolog-server-port nil) ;;;###autoload (defun sweep-module-compile () @@ -104,16 +103,15 @@ (defun sweep-start-prolog-server () (sweep-open-query "user" - "sweep" - "sweep_start_prolog_server" - sweep-prolog-server-port) + "prolog_server" + "prolog_server" + nil t) (let ((sol (sweep-next-solution))) (sweep-close-query) - sol)) + (when (sweep-true-p sol) + (setq sweep-prolog-server-port (cdr sol))))) (defun sweep-init () - (setq sweep-prolog-server-port (+ (random 10000) - sweep-prolog-server-port)) (apply #'sweep-initialize (cons (expand-file-name "bin/swipl" (file-name-directory load-file-name)) @@ -123,8 +121,12 @@ (defvar sweep-predicate-completion-collection nil) +(defvar-local sweep-buffer-module nil) + (defun sweep-local-predicates-collection (&optional prefix) - (sweep-open-query "user" "sweep" "sweep_local_predicate_completion" prefix) + (sweep-open-query "user" "sweep" "sweep_local_predicate_completion" + (cons sweep-buffer-module + prefix)) (let ((sol (sweep-next-solution))) (sweep-close-query) (when (sweep-true-p sol) @@ -549,8 +551,8 @@ module name, F is a functor name and N is its arity." (put-text-property beg end 'font-lock-face (pcase g (`("recursion" . ,_) sweep-recursion-face) - (`("meta" . ,_) sweep-meta-face) - (`("built_in" . ,_) sweep-built-in-face) + (`("meta" . ,_) sweep-meta-face) + (`("built_in" . ,_) sweep-built-in-face) (`("undefined" . ,_) sweep-undefined-face) (_ sweep-goal-face)))) ("unused_import" (put-text-property beg end 'font-lock-face sweep-unused-import-face)) @@ -633,6 +635,7 @@ module name, F is a functor name and N is its arity." (add-hook 'post-self-insert-hook #'sweep-top-level--post-self-insert-function nil t) (setq sweep-top-level-timer (run-with-idle-timer 0.2 t #'sweep-colourise-query (current-buffer))) (add-hook 'completion-at-point-functions #'sweep-completion-at-point-function nil t) + (setq sweep-buffer-module "user") (add-hook 'kill-buffer-hook (lambda () (when (timerp sweep-top-level-timer) diff --git a/sweep.pl b/sweep.pl index 5de7523..68343be 100644 --- a/sweep.pl +++ b/sweep.pl @@ -37,7 +37,6 @@ sweep_predicates_collection/2, sweep_modules_collection/2, sweep_packs_collection/2, - sweep_start_prolog_server/2, sweep_pack_install/2, sweep_module_path/2 ]). @@ -227,18 +226,19 @@ sweep_predicate_location(MFN, [Path|Line]) :- predicate_property(M:H, line_count(Line)), predicate_property(M:H, file(Path0)), atom_string(Path0, Path). -sweep_local_predicate_completion(Sub, Preds) :- +sweep_local_predicate_completion([Mod|Sub], Preds) :- + atom_string(M, Mod), findall(F/N, - current_predicate(F/N), + @(current_predicate(F/N), M), Preds0), - list_to_set(Preds0, Preds1), - convlist(sweep_predicate_completion_annotated(Sub), Preds1, Preds). + convlist(sweep_predicate_completion_annotated(Sub, M), Preds0, Preds). -sweep_predicate_completion_annotated(Sub, F/N, [S|A]) :- +sweep_predicate_completion_annotated(Sub, M, F/N, [S|A]) :- format(string(S), '~W/~w', [F, [quoted(true), character_escapes(true)], N]), sub_string(S, _, _, _, Sub), + \+ sub_string(S, _, _, _, "$"), pi_head(F/N, Head), - findall(P, predicate_property(Head, P), Ps0), + findall(P, @(predicate_property(Head, P), M), Ps0), sweep_predicate_completion_op_annotation(F, Ps0, Ps), phrase(sweep_head_annotation(Ps), A). @@ -282,14 +282,17 @@ sweep_predicates_collection(Sub, Preds) :- Tail), list_to_set(Preds0, Preds1), maplist(sweep_predicate_description, Preds1, Preds2), + include(sweep_predicate_non_hidden, Preds2, Preds3), ( Sub == [] - -> Preds = Preds2 - ; include(sweep_predicate_matches(Sub), Preds2, Preds) + -> Preds = Preds3 + ; include(sweep_predicate_matches(Sub), Preds3, Preds) ). sweep_predicate_matches(Sub, [String|_]) :- sub_string(String, _, _, _, Sub). +sweep_predicate_non_hidden([String|_]) :- + \+ sub_string(String, 0, _, _, "$"). sweep_predicate_description(M:F/N, [S|T]) :- sweep_predicate_description_(M, F, N, T), format(string(S), '~w:~w/~w', [M, F, N]). @@ -314,9 +317,6 @@ sweep_pack_install(PackName, []) :- atom_string(Pack, PackName), pack_install(Pack, [silent(true), upgrade(true), interactive(false)]). -sweep_start_prolog_server(Port, []) :- - prolog_server(Port, []). - sweep_colourise_query([String|Offset], _) :- prolog_colourise_query(String, module(sweep), sweep_handle_query_color(Offset)).