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

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

[nongnu] elpa/swift-mode 27e959e 385/496: Handle unmatched parens correc


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode 27e959e 385/496: Handle unmatched parens correctly
Date: Sun, 29 Aug 2021 11:34:12 -0400 (EDT)

branch: elpa/swift-mode
commit 27e959e97235b2427ad80b61d58d7cb49b5173a7
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>

    Handle unmatched parens correctly
---
 swift-mode-beginning-of-defun.el | 34 +++++++++++++++++++++++---------
 swift-mode-indent.el             | 42 +++++++++++++++++++++++++---------------
 2 files changed, 51 insertions(+), 25 deletions(-)

diff --git a/swift-mode-beginning-of-defun.el b/swift-mode-beginning-of-defun.el
index cd8eedc..19120ff 100644
--- a/swift-mode-beginning-of-defun.el
+++ b/swift-mode-beginning-of-defun.el
@@ -172,7 +172,7 @@ The cursor must be at the beginning of a statement."
             "prefix" "postfix" "infix" "precedencegroup"
             "var" "let"
             "case"))
-        (stop-tokens '(\; implicit-\; {} } \) \]
+        (stop-tokens '(\; implicit-\; {} { } \( \) \[ \]
                        anonymous-function-parameter-in outside-of-buffer))
         (class-token nil))
     (while (not (or
@@ -641,14 +641,30 @@ Both functions return t if succeeded, return nil 
otherwise."
       region)
 
      (t
-      (catch 'swift-mode:found-block
-        (while (funcall move-forward)
-          (let ((end (point)))
-            (save-excursion
-              (funcall move-backward)
-              (when (<= (point) pos end)
-                (throw 'swift-mode:found-block (cons (point) end))))))
-        (cons (point-min) (point-max)))))))
+      (save-excursion
+        (catch 'swift-mode:found-block
+          (let ((start pos)
+                (end pos))
+            (while (and (funcall move-forward) (/= end (point)))
+              (setq end (point))
+              (save-excursion
+                (funcall move-backward)
+                (when (<= (point) pos end)
+                  (throw 'swift-mode:found-block (cons (point) end)))))
+            (when (= end (point))
+              ;; Got unmatched parens.
+              ;; Scans backward.
+              (goto-char pos)
+              (while (and (funcall move-backward) (/= start (point)))
+                (setq start (point))
+                (save-excursion
+                  (funcall move-forward)
+                  (when (<= start pos (point))
+                    (throw 'swift-mode:found-block (cons start (point))))
+                  (funcall move-backward)
+                  (when (/= start (point))
+                    (throw 'swift-mode:found-block (cons start end)))))))
+          (cons (point-min) (point-max))))))))
 
 (defun swift-mode:extend-region-with-spaces (region)
   "Return REGION extended with surrounding spaces."
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index 9e3c5a8..818c87e 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -1320,14 +1320,19 @@ Return the token skipped."
      ;; List
      ((memq previous-type '(} \) \]))
       (goto-char previous-end)
-      (backward-list)
-      (swift-mode:token
-       (cdr (assoc previous-type '((} . {})
-                                   (\) . \(\))
-                                   (\] . \[\]))))
-       (buffer-substring-no-properties (point) previous-end)
-       (point)
-       previous-end))
+      (condition-case nil
+          (progn
+            (backward-list)
+            (swift-mode:token
+             (cdr (assoc previous-type '((} . {})
+                                         (\) . \(\))
+                                         (\] . \[\]))))
+             (buffer-substring-no-properties (point) previous-end)
+             (point)
+             previous-end))
+        (scan-error
+         (goto-char previous-start)
+         previous-token)))
 
      ;; Generic parameter list
      ((equal previous-text ">")
@@ -1355,14 +1360,19 @@ Return the token skipped."
      ;; List
      ((memq next-type '({ \( \[))
       (goto-char next-start)
-      (forward-list)
-      (swift-mode:token
-       (cdr (assoc next-type '(({ . {})
-                               (\( . \(\))
-                               (\[ . \[\]))))
-       (buffer-substring-no-properties next-start (point))
-       next-start
-       (point)))
+      (condition-case nil
+          (progn
+            (forward-list)
+            (swift-mode:token
+             (cdr (assoc next-type '(({ . {})
+                                     (\( . \(\))
+                                     (\[ . \[\]))))
+             (buffer-substring-no-properties next-start (point))
+             next-start
+             (point)))
+        (scan-error
+         (goto-char next-end)
+         next-token)))
 
      ;; Generic parameter list
      ((equal next-text "<")



reply via email to

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