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

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

[nongnu] elpa/go-mode 3bc7479 450/495: Fix infinite loop in fill-region


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 3bc7479 450/495: Fix infinite loop in fill-region
Date: Sat, 7 Aug 2021 09:06:07 -0400 (EDT)

branch: elpa/go-mode
commit 3bc74790c41e071cc3a9da97b95bb01c78cc8784
Author: Muir Manders <muir@mnd.rs>
Commit: Peter Sanford <psanford@sanford.io>

    Fix infinite loop in fill-region
    
    Calling fill-region on code (as opposed to comments) was looping
    forever. This is because fill-region keeps going until it reaches the
    end of the region, but our go--fill-forward-paragraph was giving up if
    it didn't see a comment. Now we just fall back to forward-paragraph so
    we can be sure we will make it out of the region.
    
    Closes: #297 [via git-merge-pr]
---
 go-mode.el                     | 13 ++++++++++---
 test/go-fill-paragraph-test.el | 17 ++++++++++++++++-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 85d1bf5..5691959 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -723,8 +723,8 @@ thing for comments."
     (while (and (not done) (not (zerop arg)))
       ;; If we are moving backwards and aren't currently looking at a
       ;; comment, move back one line. This is to make sure
-      ;; (go--file-forward-paragraph -1) always works properly as the
-      ;; inverse of (go--file-forward-paragraph 1).
+      ;; (go--fill-forward-paragraph -1) always works properly as the
+      ;; inverse of (go--fill-forward-paragraph 1).
       (when (and
              (= single -1)
              (not (go-in-comment-p))
@@ -744,7 +744,14 @@ thing for comments."
           (setq saw-comment t))
 
         (if (not saw-comment)
-            (setq done t)
+            (progn
+              ;; In fill-region case user may have selected a region
+              ;; with non-comments. fill-region will loop forever
+              ;; until it makes it to the end of the region, so just
+              ;; fall back to `forward-paragraph' so we make progress.
+              (when mark-active
+                (setq arg (forward-paragraph arg)))
+              (setq done t))
           ;; If we are going backwards, back up one more line so
           ;; we are on the line before the comment.
           (when (= single -1)
diff --git a/test/go-fill-paragraph-test.el b/test/go-fill-paragraph-test.el
index 5775018..8c5deda 100644
--- a/test/go-fill-paragraph-test.el
+++ b/test/go-fill-paragraph-test.el
@@ -148,7 +148,6 @@ func main() {
 }"
    ))
 
-
 (ert-deftest go--fill-paragraph-block-region ()
   (go--should-fill
    "
@@ -198,3 +197,19 @@ func main() {
   /////////////////////
 }"
    ))
+
+(ert-deftest go--fill-paragraph-code-region ()
+  (go--should-fill
+   "
+func main() {
+<      if something() {
+               somethingElse()
+       }
+>}"
+
+   ;; important thing is we don't get stuck in an infinite loop
+   "
+func main() {
+       if something() { somethingElse() }
+}"
+   ))



reply via email to

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