branch: elpa/swift-mode commit 62276c39e5cf50286ded6736c8cc19e5fbaa7fff Author: Chris Barrett <chris.d.barr...@me.com> Commit: Chris Barrett <chris.d.barr...@me.com>
Indent cases in enums Fixes #15 --- swift-mode.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/swift-mode.el b/swift-mode.el index c879eb7..6b39a9d 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -91,6 +91,15 @@ (backward-word 1)) (current-column)))) +(defun swift-indent--at-enum-case? () + "Non-nil if point is at the case keyword at the top-level of an enum declaration." + (save-excursion + (back-to-indentation) + (when (looking-at (rx bow "case" eow)) + (backward-up-list) + (swift-indent--back-to-start-of-level) + (looking-at (rx bow "enum" eow))))) + (defun swift-indent--calculate-indentation () "Calculate the indentation column to use for `swift-indent-line'. Returns the column number as an integer." @@ -142,6 +151,8 @@ Returns the column number as an integer." (back-to-indentation) ;; Point is now at the beginning of the current line (cond + ((swift-indent--at-enum-case?) + baseline) ;; Cases are indented to the same level as the enclosing switch statement. ((looking-at (rx bow (or "case" "default") eow)) (- baseline swift-indent-offset))