From bddbc6267c284c5831515ef505918f6c1c93056c Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 10 Oct 2022 15:31:29 +0300 Subject: [PATCH] FIXED: sweeprolog-end-of-top-term would get confused by "=.." * sweeprolog.el: sweeprolog-end-of-top-term: don't stop after "=..". * sweeprolog-tests.el: add unit test. --- NEWS.org | 7 +++++++ README.org | 4 ---- sweeprolog-tests.el | 25 +++++++++++++++++++++++++ sweeprolog.el | 5 ++++- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/NEWS.org b/NEWS.org index 5417c11..139ae2d 100644 --- a/NEWS.org +++ b/NEWS.org @@ -29,6 +29,13 @@ Wrapper around ~flymake-show-buffer-diagnostics~ for ~sweeprolog-mode~, bound to ~C-c C-`~. With a prefix argument, calls ~flymake-show-project-diagnostics~ instead. +** Fixed bug in end of a clause detection in presence of ~=..~ + +This version includes a fix in ~sweeprolog-end-of-top-term~, which is +used to locate the end of the current clause. Previously this +function would get "confused" by occurrences of the ~=../2~ ("univ") +operator in the clause's body. + * Version 0.5.4 on 2022-10-09 ** The manual now has a short description attached to each section diff --git a/README.org b/README.org index 92959a3..408d339 100644 --- a/README.org +++ b/README.org @@ -1264,10 +1264,6 @@ there some further improvements that we want to pursue: moving to the next predicate definition and ~C-c C-p~ for moving to the previous. -- Integrate with ~flymake~ to provide on-the-fly diagnostics :: ~sweeprolog-mode~ - should integrate with ~flymake~ to provide diagnostics and feedback - for errors in Prolog code in an Emacs-standard manner. - - Improve the information provided for predicate completion candidates :: predicate completion with ~C-M-i~ should annotate each completion candidate with the names and modes of its arguments, when available. E.g. say diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index c02f7e8..f3a7d5e 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -52,6 +52,31 @@ (should (equal (sweeprolog-next-solution) nil)) (should (equal (sweeprolog-cut-query) t))) +(ert-deftest end-of-top-term-with-univ () + "Tests detecting the fullstop in presence of `=..'." + (with-temp-buffer + (sweeprolog-mode) + (insert " +html_program_section(Section, Dict) --> + { _{module:M, options:Options} :< Dict, + Content = Dict.get(Section), + Content \= [], + scasp_code_section_title(Section, Default, Title), + Opt =.. [Section,true], + option(Opt, Options, Default) + }, + !, + html(h2(Title)), + ( {Section == query} + -> {ovar_set_bindings(Dict.bindings)}, + html_query(M:Content, Options) + ; sequence(predicate_r(M:Options), Content) + ). +") + (goto-char (point-min)) + (sweeprolog-end-of-top-term) + (should (= (point) 466)))) + (ert-deftest fullstop-detection () "Tests detecting the fullstop in presence of confusing comments." diff --git a/sweeprolog.el b/sweeprolog.el index fccf3e6..28c07f8 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -1817,7 +1817,10 @@ Interactively, a prefix arg means to prompt for BUFFER." (while (and (or (nth 8 (syntax-ppss)) (save-excursion (nth 8 (syntax-ppss (max (point-min) - (1- (point))))))) + (1- (point)))))) + (save-match-data + (looking-back (rx "=.." (or white "\n")) + (line-beginning-position)))) (not (eobp))) (while (and (nth 8 (syntax-ppss)) (not (eobp))) (forward-char)) -- 2.39.2