From d5983b7fe429da553741cd87deb9530fe74ce86c Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 7 Nov 2022 19:02:32 +0200 Subject: [PATCH] FIXED: variable name completion on Emacs 27 * sweeprolog.el (sweeprolog-variable-completion-at-point): don't rely on char-uppercase-p * sweeprolog-tests.el (complete-variable): new test. --- sweeprolog-tests.el | 21 +++++++++++++++++++++ sweeprolog.el | 9 ++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index 834c7e6..da66d0a 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -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" diff --git a/sweeprolog.el b/sweeprolog.el index 9009fd3..74deb42 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -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)))) -- 2.39.2