[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 "<")
- [nongnu] elpa/swift-mode 92f8eba 349/496: Update README.md, (continued)
- [nongnu] elpa/swift-mode 92f8eba 349/496: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 2cd111f 351/496: Fix indentation of multiline strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3bcdf32 353/496: Add more keywords with number sign, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 030b1b8 356/496: Update documentations and wordings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d68af3c 365/496: Update copyright, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 359efc0 379/496: Fix indentation of function parameter clauses, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 25944c2 378/496: Add test for beginning/end-of-defun, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ea029a0 370/496: Suppress implicit semicolons inside interpolated expressions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode b5602c1 375/496: Add beginning/end-of-sentence to README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 18c3dc4 376/496: Bump version to 4.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 27e959e 385/496: Handle unmatched parens correctly,
ELPA Syncer <=
- [nongnu] elpa/swift-mode abf3426 392/496: Add support for highlighting function calls / properties / enum cases, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 560242d 393/496: Add support for choosing scheme when building/running iOS projects, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c56f43c 395/496: Make faces customizable, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6d4fab5 396/496: Move customizations for REPL to their own group, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 604610d 399/496: Fix LLDB breakpoint option, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 6fdb3cd 403/496: Fix `swift-mode:debug-swift-module`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode d2f2f1d 410/496: Bump version to 6.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode f847923 419/496: Highlight more compiler directives, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 0b1e5e8 420/496: Support raw texts, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 348e153 422/496: Change buffer name of REPL, ELPA Syncer, 2021/08/29