branch: elpa/swift-mode
commit 2c67d9246fbe57629c8d5685d0abfde3deb96989
Author: ap4y <[email protected]>
Commit: ap4y <[email protected]>
Fix indentation of the closure arguments inside parentheses
---
swift-mode.el | 16 ++++++++++++++--
test/indentation-tests.el | 46 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/swift-mode.el b/swift-mode.el
index 9e4408f..420bb09 100644
--- a/swift-mode.el
+++ b/swift-mode.el
@@ -676,11 +676,23 @@ You can send text to the REPL process from other buffers
containing source.
;; Parenthesis, braces and brackets
(modify-syntax-entry ?\( "()" table)
(modify-syntax-entry ?\) ")(" table)
- (modify-syntax-entry ?\{ "(}" table)
- (modify-syntax-entry ?\} "){" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
+ ;; HACK: This is not a correct syntax table definition
+ ;; for the braces, but it allows us disable smie indentation
+ ;; based on syntax-table. Default behaviour doesn't work with
+ ;; closures in method arguments. For example:
+ ;;
+ ;; foo.bar(10,
+ ;; closure: {
+ ;; })
+ ;;
+ ;; With enabled syntax table, smie doesn't respect closing brace, so
+ ;; it's impossible to provide custom indentation rules
+ (modify-syntax-entry ?\{ "w" table)
+ (modify-syntax-entry ?\} "w" table)
+
table))
(defvar swift-mode-map
diff --git a/test/indentation-tests.el b/test/indentation-tests.el
index d3ec032..d9816cc 100644
--- a/test/indentation-tests.el
+++ b/test/indentation-tests.el
@@ -1568,7 +1568,7 @@ UIView.animateWithDuration(1.0,
" "
UIView.animateWithDuration(1.0,
animations: {
-|})
+ |})
")
(check-indentation anonymous-function-as-a-argument/2
@@ -1581,7 +1581,49 @@ UIView.animateWithDuration(
UIView.animateWithDuration(
1.0,
animations: {
-|})
+ |})
+")
+
+(check-indentation anonymous-function-as-a-argument/3
+ "
+func foo() {
+ UIView.animateWithDuration(1.0,
+ animations: {
+ |}
+ ) {
+ completed in
+ }
+}
+" "
+func foo() {
+ UIView.animateWithDuration(1.0,
+ animations: {
+ |}
+ ) {
+ completed in
+ }
+}
+")
+
+(check-indentation anonymous-function-as-a-argument/4
+ "
+func foo() {
+ UIView.animateWithDuration(1.0,
+ animations: {
+ }
+|) {
+ completed in
+ }
+}
+" "
+func foo() {
+ UIView.animateWithDuration(1.0,
+ animations: {
+ }
+ |) {
+ completed in
+ }
+}
")
(check-indentation indents-expression-with-optional-type/1