From 54e0a5e9262f8c9b70c6e4adddfc3453a6fcae4d Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 1 Dec 2023 19:15:06 +0100 Subject: [PATCH] Fix fullstop detection in presence of dot character literal This fixes an issue where the character "0'." in a clause body would confuse clause boundaries calculation. * sweeprolog.el (sweeprolog-end-of-top-term): Make sure fullstop have punctuation syntax class (otherwise it's part of a character literal). * sweeprolog-tests.el (end-of-top-term-with-dot-char-literal): Test it --- sweeprolog-tests.el | 17 +++++++++++++++++ sweeprolog.el | 2 ++ 2 files changed, 19 insertions(+) diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index c20a6e0..096a8e1 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -1379,6 +1379,23 @@ html_program_section(Section, Dict) --> (sweeprolog-end-of-top-term) (should (= (point) 466))) +(sweeprolog-deftest end-of-top-term-with-dot-char-literal () + "Tests detecting the fullstop in presence of `0\'.'." + " +full_stop_after(Index, String, [H|T]) :- + string_code(Index, String, H), + Index2 is Index+1, + ( code_type(H, space) + -> !, full_stop_after(Index2, String, T) + ; H == 0'. + -> !, layout_after(Index2, String, T) + ). +full_stop_after(_, _, []). +" + (goto-char (point-min)) + (sweeprolog-end-of-top-term) + (should (= (point) 242))) + (sweeprolog-deftest fullstop-detection () "Tests detecting the fullstop in presence of confusing comments." " diff --git a/sweeprolog.el b/sweeprolog.el index 8ddfac8..136e10b 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -1384,6 +1384,7 @@ Prolog buffers." (ppre (sweeprolog-op-prefix-precedence op))) (cond ((and (string= "." op) + (equal 1 (sweeprolog-syntax-class-at obeg)) (let ((sa (sweeprolog-syntax-class-at (1+ obeg)))) (or (null sa) (member sa '(0 12))))) nil) @@ -3873,6 +3874,7 @@ The command `beginning-of-defun' calls this function in (or (re-search-forward (rx "." (or white "\n")) nil t) (goto-char (point-max))) (while (and (or (nth 8 (syntax-ppss)) + (equal 0 (sweeprolog-syntax-class-at (point))) (save-excursion (nth 8 (syntax-ppss (max (point-min) (1- (point)))))) -- 2.39.2