]> git.eshelyaron.com Git - sweep.git/commitdiff
ENHANCED: show more relevant candidates in top-level completion
authorEshel Yaron <me@eshelyaron.com>
Sat, 3 Sep 2022 06:04:45 +0000 (09:04 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 3 Sep 2022 06:04:45 +0000 (09:04 +0300)
sweep.el
sweep.pl

index b984b42194098c8af0e8e90baf81b67e9a8b3989..e5af56058badfd0188c9aaa2b4e7914ea1792f4f 100644 (file)
--- 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 ()
 
 (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))
 
 (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)
index 5de752344c5157fdbf9e063800c50c92206aefa6..68343bed66fb1aab1011bf697af26e39cefdbab6 100644 (file)
--- 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)).