From 1e09cf648d8bc151015e9cefe6341044b385352b Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 10 Dec 2022 08:28:44 +0200 Subject: [PATCH] * (sweeprolog-beginning-of-predicate-at-point): fix hang near bob --- sweeprolog-tests.el | 11 ++++++++++- sweeprolog.el | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index eb08bcc..cf0d331 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -587,7 +587,7 @@ foo. foo :- Body. ")))) -(ert-deftest dwim-next-clause-module-qualified-cdg () +(ert-deftest dwim-next-clause-module-qualified-dcg () "Tests inserting new module-qualified DCG non-terminal." (let ((temp (make-temp-file "sweeprolog-test" nil @@ -1020,6 +1020,15 @@ scasp_and_show(Q, Model, Tree) :- (sweeprolog-end-of-top-term) (should (= (point) 252)))) +(ert-deftest beginning-of-predicate-definition-near-bob () + "Test finding the beginning of the first predicate definition." + (with-temp-buffer + (sweeprolog-mode) + (insert "foo :- bar.") + (goto-char (point-min)) + (sweeprolog-beginning-of-predicate-at-point) + (should (= (point) (point-min))))) + (ert-deftest align-spacs-in-line-comment () "Test using `sweeprolog-align-spaces' in a line comment." (with-temp-buffer diff --git a/sweeprolog.el b/sweeprolog.el index 2161dc5..9fabeb0 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -2962,7 +2962,8 @@ predicate definition at or directly above POINT." (while (and point (not (bobp))) (sweeprolog-beginning-of-top-term) (backward-char 1) - (if-let* ((ndef (sweeprolog-definition-at-point (point))) + (if-let* ((moved (< (point) point)) + (ndef (sweeprolog-definition-at-point (point))) (nfun (cadr ndef)) (nari (caddr ndef)) (same (and (string= fun nfun) -- 2.39.2