From fbde60f59cc7bc27cb3088c028619692a279765b Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 22 Nov 2022 12:59:41 +0200 Subject: [PATCH] FIXED: sweeprolog-beginning-of-next-top-term: other possible loop * sweeprolog.el (sweeprolog-beginning-of-next-top-term): don't loop when called in the last term of the buffer * sweeprolog-tests.el (beginning-of-next-top-term-at-last-clause): new test case --- sweeprolog-tests.el | 18 ++++++++++++++++++ sweeprolog.el | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index ed79c42..f096bf7 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -657,6 +657,24 @@ loop_term(I, Arity, Goal1, Goal2) :- (sweeprolog-end-of-top-term) (should (= (point) 232)))) +(ert-deftest beginning-of-next-top-term-at-last-clause () + "Test finding the beginning of next top term when there isn't one." + (with-temp-buffer + (sweeprolog-mode) + (insert " +test_bindings(Name-Value) --> + [' '~w = ~p'-[Name-Value] ].. +") + (goto-char 43) + (backward-delete-char 1) + (end-of-line) + (backward-delete-char 1) + (should (string= (buffer-string) " +test_bindings(Name-Value) --> + [' ~w = ~p'-[Name-Value] ]. +" + )))) + (defun sweeprolog-test-indentation (given expected) (with-temp-buffer diff --git a/sweeprolog.el b/sweeprolog.el index 2fcabbf..d1c585b 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -2485,9 +2485,9 @@ Interactively, POINT is set to the current point." (re-search-forward (rx bol graph) nil t) (while (and (or (nth 8 (syntax-ppss)) (looking-at-p (rx bol (or "%" "/*")))) - (not (eobp))) - (re-search-forward (rx bol graph) nil t))) - (beginning-of-line) + (not (eobp)) + (re-search-forward (rx bol graph) nil t)))) + (unless (= p (point)) (beginning-of-line)) (not (= p (point))))) (defun sweeprolog-end-of-top-term () -- 2.39.2