]> git.eshelyaron.com Git - sweep.git/commitdiff
; Fix filtering of the just created body when extracting goal
authorEshel Yaron <me@eshelyaron.com>
Sun, 24 Sep 2023 19:53:13 +0000 (21:53 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 24 Sep 2023 19:53:13 +0000 (21:53 +0200)
* sweeprolog (sweeprolog-extract-region-to-predicate): When searching
and replacing other goals subsumed by the extracted goal, use a more
robust check to filter out the newly created body term from the search
matches.

sweeprolog.el

index 39f612ffa4f3367919a78e518310b21fc0773795..4a9b15737a5118ab08f17131ed48cb0eb8f6256d 100644 (file)
@@ -7139,7 +7139,8 @@ where in the buffer to insert the newly created predicate."
                    (sweeprolog--query-once "sweep" "sweep_term_variable_names"
                                            body)
                  (prolog-exception
-                  (user-error "Region does not contain a valid Prolog term")))))
+                  (user-error "Region does not contain a valid Prolog term"))))
+         (def-end nil))
     (if (and (sweeprolog--query-once "sweep" "sweep_goal_may_cut" body)
              (not (y-or-n-p (concat
                              "The selected goal contains a cut whose "
@@ -7182,18 +7183,15 @@ where in the buffer to insert the newly created predicate."
                                 ".\n")))
             (insert clause)
             (indent-region-line-by-line def-beg (point))
+            (setq def-end (point))
             (goto-char def-beg))))
       (when all
-        (let ((body-beg
-               (+ 2 (point)
-                  (length head)
-                  (length neck)
-                  sweeprolog-indent-offset)))
+        (let ((def-beg (point)))
           (save-excursion
             (goto-char (point-min))
             (let ((sweeprolog-query-replace-term-include-match-function
-                   (pcase-lambda (`(,beg . ,_))
-                     (not (= beg body-beg)))))
+                   (pcase-lambda (`(,beg ,end . ,_))
+                     (not (<= def-beg beg end def-end)))))
               (deactivate-mark)
               (sweeprolog-query-replace-term
                body head "true" '(goal))))))