]> git.eshelyaron.com Git - sweep.git/commitdiff
FIXED: variable name completion on Emacs 27
authorEshel Yaron <me@eshelyaron.com>
Mon, 7 Nov 2022 17:02:32 +0000 (19:02 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 7 Nov 2022 17:02:32 +0000 (19:02 +0200)
* sweeprolog.el (sweeprolog-variable-completion-at-point): don't rely
on char-uppercase-p
* sweeprolog-tests.el (complete-variable): new test.

sweeprolog-tests.el
sweeprolog.el

index 834c7e644c0431868f6da7e141a8b06b8beb24d0..da66d0a5f3ff4882fac16d333411c80cbb15abcf 100644 (file)
@@ -106,6 +106,27 @@ foo(Foo) :- bar.
                      sweeprolog-clause-default-face)))))
 
 
+(ert-deftest complete-variable ()
+  "Test marking completing variable names."
+  (let ((temp (make-temp-file "sweeprolog-test"
+                              nil
+                              ".pl"
+                              "
+baz(Baz) :- bar(B).
+"
+                              )))
+    (find-file-literally temp)
+    (sweeprolog-mode)
+    (goto-char (point-max))
+    (backward-word)
+    (forward-word)
+    (call-interactively #'complete-symbol)
+    (should (string= (buffer-string)
+                     "
+baz(Baz) :- bar(Baz).
+"
+                     ))))
+
 (ert-deftest mark-predicate ()
   "Test marking predicate definition."
   (let ((temp (make-temp-file "sweeprolog-test"
index 9009fd3ac3b31535c749c5b7fa1441ad779af2b2..74deb42090c3acded7dd4cff0f2c447c0edbf911 100644 (file)
@@ -895,6 +895,13 @@ resulting list even when found in the current clause."
                 (push (match-string-no-properties 0) vars)))))))
     vars))
 
+(defun sweeprolog--char-uppercase-p (char)
+  (if (fboundp 'char-uppercase-p)
+      (char-uppercase-p char)
+    (cond ((unicode-property-table-internal 'lowercase)
+           (characterp (get-char-code-property char 'lowercase)))
+          ((and (>= char ?A) (<= char ?Z))))))
+
 (defun sweeprolog-variable-completion-at-point ()
   "Prolog variable name completion backend for `completion-at-point'."
   (when-let ((bounds (bounds-of-thing-at-point 'symbol))
@@ -902,7 +909,7 @@ resulting list even when found in the current clause."
              (end (cdr bounds)))
     (when (and (<= beg (point) end)
                (let ((first (char-after beg)))
-                 (or (char-uppercase-p first)
+                 (or (sweeprolog--char-uppercase-p first)
                      (= first ?_))))
       (when-let ((col (sweeprolog-local-variables-collection
                        (buffer-substring-no-properties beg end))))