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

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

[nongnu] elpa/sweeprolog 3a72df5958 2/2: Simplify completion at point, b


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 3a72df5958 2/2: Simplify completion at point, bump patch version
Date: Sun, 13 Nov 2022 04:59:17 -0500 (EST)

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

    Simplify completion at point, bump patch version
---
 NEWS.org            |  8 +++++++
 README.org          | 16 ++++++--------
 sweeprolog-tests.el | 23 ++++++++++++++++++--
 sweeprolog.el       | 61 ++++++++++++-----------------------------------------
 4 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 23602eb6f9..ad5ef97818 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -11,6 +11,14 @@ SWI-Prolog in Emacs.
 For further details, please consult the manual:
 <https://eshelyaron.com/sweep.html>.
 
+* Version 0.8.7 on 2022-11-12
+
+** Revised predicate completion-at-point and added atom completion
+
+~sweep~'s completion at point now detects when predicate completion is
+appropriate based on the context of point.  If point is at a
+non-callable position, atom completion is provided instead.
+
 * Version 0.8.6 on 2022-11-11
 
 ** New user option ~sweeprolog-new-predicate-location-function~
diff --git a/README.org b/README.org
index 1d09df0b24..7e3399032c 100644
--- a/README.org
+++ b/README.org
@@ -951,9 +951,12 @@ In ~sweeprolog-mode~ buffers, the following enhancements 
are provided:
   completed to one or more variable names that appear elsewhere in the
   current clause, ~completion-at-point~ suggests matching variable names
   as completion candidates.
-- Predicate completion :: If the text before point can be completed to
-  a predicate call, ~completion-at-point~ suggests matching predicates
-  as completion candidates.
+- Predicate completion :: If point is at a callable position,
+  ~completion-at-point~ suggests matching predicates as completion
+  candidates.
+- Atom completion :: If point is at a non-callable,
+  ~completion-at-point~ suggests matching atoms as completion
+  candidates.
 
 ** Context-Based Term Insertion
 :PROPERTIES:
@@ -1509,13 +1512,6 @@ there some further improvements that we want to pursue:
   the names and modes of its arguments, when available.  E.g. say
   ~foo(+Bar, -Baz)~ instead of ~foo/2~.
 
-- Improve the behavior of predicate completion in the middle of a functor :: 
When
-  invoking predicate completion in the middle of a functor,
-  e.g. ~foo<|>bar(~ (where ~<|>~ designates the location of the cursor),
-  we should take into account the part that comes after the cursor and
-  either restrict completion to candidates that match it as a suffix,
-  or delete it after completion.
-
 - Make predicate completion aware of module-qualification :: predicate
   completion should detect when the prefix it's trying to complete
   starts with a module-qualification ~foo:ba<|>~ and restrict completion
diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el
index 78d767bfab..f5b295ea77 100644
--- a/sweeprolog-tests.el
+++ b/sweeprolog-tests.el
@@ -105,6 +105,25 @@ foo(Foo) :- bar.
                    '(sweeprolog-undefined-default-face
                      sweeprolog-body-default-face)))))
 
+(ert-deftest complete-atom ()
+  "Tests completing atoms."
+  (let ((temp (make-temp-file "sweeprolog-test"
+                              nil
+                              ".pl"
+                              "
+baz(Baz) :- Baz = emacsc
+"
+                              )))
+    (find-file-literally temp)
+    (sweeprolog-mode)
+    (goto-char (point-max))
+    (backward-char)
+    (call-interactively #'completion-at-point)
+    (should (string= (buffer-string)
+                     "
+baz(Baz) :- Baz = emacsclient
+"
+                     ))))
 
 (ert-deftest complete-predicate ()
   "Tests completing predicate calls."
@@ -119,7 +138,7 @@ baz(Baz) :- findall(X, b_g
     (sweeprolog-mode)
     (goto-char (point-max))
     (backward-char)
-    (call-interactively #'sweeprolog-completion-at-point)
+    (call-interactively #'completion-at-point)
     (should (string= (buffer-string)
                      "
 baz(Baz) :- findall(X, b_getval(_, _)
@@ -140,7 +159,7 @@ baz(Baz) :- bar(B).
     (goto-char (point-max))
     (backward-word)
     (forward-word)
-    (call-interactively #'sweeprolog-completion-at-point)
+    (call-interactively #'completion-at-point)
     (should (string= (buffer-string)
                      "
 baz(Baz) :- bar(Baz).
diff --git a/sweeprolog.el b/sweeprolog.el
index 35808a92f9..09c680c130 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -6,7 +6,7 @@
 ;; Maintainer: Eshel Yaron <~eshel/dev@lists.sr.ht>
 ;; Keywords: prolog languages extensions
 ;; URL: https://git.sr.ht/~eshel/sweep
-;; Package-Version: 0.8.6
+;; Package-Version: 0.8.7
 ;; Package-Requires: ((emacs "28.1"))
 
 ;; This file is NOT part of GNU Emacs.
@@ -342,7 +342,6 @@ buffer where the new predicate defintion should be 
inserted."
                   #'flymake-show-diagnostics-buffer))
     (define-key map (kbd "C-M-^")   #'kill-backward-up-list)
     (define-key map (kbd "C-M-m")   #'sweeprolog-insert-term-dwim)
-    (define-key map (kbd "C-M-i")   #'sweeprolog-completion-at-point)
     (define-key map (kbd "M-p")     #'sweeprolog-backward-predicate)
     (define-key map (kbd "M-n")     #'sweeprolog-forward-predicate)
     (define-key map (kbd "M-h")     #'sweeprolog-mark-predicate)
@@ -351,7 +350,6 @@ buffer where the new predicate defintion should be 
inserted."
 
 (defvar sweeprolog-top-level-mode-map
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "C-M-i")   #'sweeprolog-completion-at-point)
     (define-key map (kbd "C-c C-c") #'sweeprolog-top-level-signal-current)
     map)
   "Keymap for `sweeprolog-top-level-mode'.")
@@ -914,14 +912,9 @@ module name, F is a functor name and N is its arity."
 ;;;; Completion at point
 
 (defvar sweeprolog-completion-at-point-functions
-  '((sweeprolog-predicate-completion-at-point
-     ?p "predicate" "Predicate name")
-    (sweeprolog-atom-completion-at-point
-     ?a "atom"      "Atom")
-    (sweeprolog-module-completion-at-point
-     ?m "module"    "Module name")
-    (sweeprolog-variable-completion-at-point
-     ?v "variable"  "Variable name")))
+  '(sweeprolog-atom-completion-at-point
+    sweeprolog-predicate-completion-at-point
+    sweeprolog-variable-completion-at-point))
 
 (defun sweeprolog-atoms-collection (&optional sub)
   "Return a list of atom completion candidates matchitng SUB."
@@ -976,21 +969,6 @@ resulting list even when found in the current clause."
               :annotation-function
               (lambda (_) " Var"))))))
 
-(defun sweeprolog-module-completion-at-point ()
-  "Prolog module name completion backend for `completion-at-point'."
-  (when-let ((bounds (bounds-of-thing-at-point 'symbol))
-             (beg (car bounds))
-             (end (cdr bounds)))
-    (when (and (<= beg (point) end)
-               (let ((first (char-after beg)))
-                 (not (or (sweeprolog--char-uppercase-p first)
-                          (= first ?_)))))
-      (when-let ((col (sweeprolog-modules-collection)))
-        (list beg end (mapcar #'car col)
-              :exclusive 'no
-              :annotation-function
-              (lambda (_) " module"))))))
-
 (defun sweeprolog-atom-completion-at-point ()
   "Prolog atom name completion backend for `completion-at-point'."
   (when-let ((bounds (bounds-of-thing-at-point 'symbol))
@@ -1000,8 +978,10 @@ resulting list even when found in the current clause."
                (let ((first (char-after beg)))
                  (not (or (sweeprolog--char-uppercase-p first)
                           (= first ?_)))))
-      (when-let ((col (sweeprolog-atoms-collection
-                       (buffer-substring-no-properties beg end))))
+      (when-let ((sub (buffer-substring-no-properties beg end))
+                 (col (seq-filter (lambda (atom)
+                                    (not (string= atom sub)))
+                                  (sweeprolog-atoms-collection sub))))
         (list beg end col
               :exclusive 'no
               :annotation-function
@@ -1059,6 +1039,7 @@ resulting list even when found in the current clause."
       context)))
 
 (defun sweeprolog-predicate-completion-at-point ()
+  "Prolog predicate completion backend for `completion-at-point'."
   (when-let ((bounds (bounds-of-thing-at-point 'symbol))
              (beg (car bounds))
              (end (cdr bounds)))
@@ -1077,26 +1058,6 @@ resulting list even when found in the current clause."
               :annotation-function
               (lambda (_) " Predicate"))))))
 
-(defun sweeprolog-completion-at-point (&optional funs)
-  (interactive
-   (list
-    (and current-prefix-arg
-         (list
-          (let ((choice (read-multiple-choice
-                         "Completion kind: "
-                         (mapcar
-                          #'cdr
-                          sweeprolog-completion-at-point-functions))))
-            (caar (seq-filter
-                   (lambda (capf)
-                     (equal (cdr capf) choice))
-                   sweeprolog-completion-at-point-functions)))))))
-  (let ((completion-at-point-functions
-         (or funs
-             (append (mapcar #'car
-                             sweeprolog-completion-at-point-functions)
-                     completion-at-point-functions))))
-    (completion-at-point)))
 
 ;;;; Packages
 
@@ -2309,6 +2270,8 @@ Interactively, a prefix arg means to prompt for BUFFER."
               comint-delimiter-argument-list '(?,)
               comment-start "%")
   (add-hook 'post-self-insert-hook 
#'sweeprolog-top-level--post-self-insert-function nil t)
+  (dolist (capf sweeprolog-completion-at-point-functions)
+    (add-hook 'completion-at-point-functions capf nil t))
   (setq sweeprolog-top-level-timer (run-with-idle-timer 0.2 t 
#'sweeprolog-colourise-query (current-buffer)))
   (add-hook 'kill-buffer-hook
             (lambda ()
@@ -3213,6 +3176,8 @@ if-then-else constructs in SWI-Prolog."
     (setq sweeprolog--analyze-buffer-duration (float-time (time-since time))))
   (add-hook 'xref-backend-functions #'sweeprolog--xref-backend nil t)
   (add-hook 'file-name-at-point-functions #'sweeprolog-file-at-point nil t)
+  (dolist (capf sweeprolog-completion-at-point-functions)
+    (add-hook 'completion-at-point-functions capf nil t))
   (when sweeprolog-analyze-buffer-on-idle
     (setq sweeprolog--timer
           (run-with-idle-timer



reply via email to

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