branch: elpa/swift-mode commit f42752b9fd2ce335d282fd480f69967075088423 Author: ap4y <l...@pisem.net> Commit: ap4y <l...@pisem.net>
Respect comments when calculating position of the implicit semicolon --- swift-mode.el | 6 ++++-- test/indentation-tests.el | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/swift-mode.el b/swift-mode.el index 786763c..91e0f0d 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -224,15 +224,17 @@ ;; Characters placed on the second line in multi-line expression (looking-at "[ \n\t]+[.?:]") ;; Operators placed on the second line in multi-line expression - (looking-at (concat "[ \n\t]+" swift-smie--operators-regexp)) + ;; Should respect here possible comments strict before the linebreak + (looking-at (concat "\\(\/\/.*\\)?\n[[:space:]]*" swift-smie--operators-regexp)) (and (looking-back swift-smie--operators-regexp (- (point) 3) t) ;; Not a generic type (not (looking-back "[[:upper:]]>" (- (point) 2) t))) )))) (defun swift-smie--forward-token () + (skip-chars-forward " \t") (cond - ((and (looking-at "\n") (swift-smie--implicit-semi-p)) + ((and (looking-at "\n\\|\/\/") (swift-smie--implicit-semi-p)) (if (eolp) (forward-char 1) (forward-comment 1)) ";") diff --git a/test/indentation-tests.el b/test/indentation-tests.el index b5fa50e..f3cbff4 100644 --- a/test/indentation-tests.el +++ b/test/indentation-tests.el @@ -1955,6 +1955,32 @@ var object: JsonObject<Foo>! |var object: JsonObject ") +(check-indentation indents-expression-with-comment/1 + " +func foo() { + foo() // foo + |foo() +} +" " +func foo() { + foo() // foo + |foo() +} +") + +(check-indentation indents-expression-with-comment/2 + " +func foo() { + let x = 1 // foo + |/ 1 +} +" " +func foo() { + let x = 1 // foo + |/ 1 +} +") + (provide 'indentation-tests) ;;; indentation-tests.el ends here