emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/clojure-mode 47ce793466: Fix infinite loop when opening fi


From: ELPA Syncer
Subject: [nongnu] elpa/clojure-mode 47ce793466: Fix infinite loop when opening file containing "comment" (#651)
Date: Fri, 23 Jun 2023 19:00:33 -0400 (EDT)

branch: elpa/clojure-mode
commit 47ce793466768e97065cf7afc4cf95804d648415
Author: Vadim Rodionov <47952597+OknoLombarda@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Fix infinite loop when opening file containing "comment" (#651)
    
    Closes #586
---
 CHANGELOG.md                   |  4 ++++
 clojure-mode.el                |  7 +++++--
 test/clojure-mode-sexp-test.el | 18 ++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f783d11ddb..3098888928 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@
 
 * Font-lock Lein's `defproject` as a keyword.
 
+### Bugs fixed
+
+* [#586](https://github.com/clojure-emacs/clojure-mode/issues/586): Fix 
infinite loop when opening file containing `comment` with 
`clojure-toplevel-inside-comment-form` set to `t`.
+
 ## 5.16.0 (2022-12-14)
 
 ### Changes
diff --git a/clojure-mode.el b/clojure-mode.el
index a5f75316af..320eca1c8a 100644
--- a/clojure-mode.el
+++ b/clojure-mode.el
@@ -2264,8 +2264,11 @@ position before the current position."
           (while (< (point) position)
             (clojure-forward-logical-sexp 1)
             (clojure-backward-logical-sexp 1)
-            (push (point) sexp-positions)
-            (clojure-forward-logical-sexp 1))
+            ;; Needed to prevent infinite recursion when there's only 1 form 
in buffer.
+            (if (eq (point) (car sexp-positions))
+                (goto-char position)
+              (push (point) sexp-positions)
+              (clojure-forward-logical-sexp 1)))
         (scan-error nil))
       sexp-positions)))
 
diff --git a/test/clojure-mode-sexp-test.el b/test/clojure-mode-sexp-test.el
index de4bea7c4c..f82552a0b6 100644
--- a/test/clojure-mode-sexp-test.el
+++ b/test/clojure-mode-sexp-test.el
@@ -169,6 +169,24 @@
             (goto-char (point-max))
             (expect (clojure-find-ns) :to-equal expected)))))))
 
+(describe "clojure-sexp-starts-until-position"
+  (it "should return starting points for forms after POINT until POSITION"
+    (with-clojure-buffer "(run 1) (def b 2) (slurp \"file\")\n"
+        (goto-char (point-min))
+        (expect (not (cl-set-difference '(19 9 1)
+                                        (clojure-sexp-starts-until-position 
(point-max)))))))
+
+  (it "should return starting point for a single form in buffer after POINT"
+    (with-clojure-buffer "comment\n"
+        (goto-char (point-min))
+        (expect (not (cl-set-difference '(1)
+                                        (clojure-sexp-starts-until-position 
(point-max)))))))
+
+  (it "should return nil if POSITION is behind POINT"
+    (with-clojure-buffer "(run 1) (def b 2)\n"
+        (goto-char (point-max))
+        (expect (not (clojure-sexp-starts-until-position (- (point-max) 
1)))))))
+
 (provide 'clojure-mode-sexp-test)
 
 ;;; clojure-mode-sexp-test.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]