branch: elpa/swift-mode commit 58f31cc50ee8fac236f5aa3936152e6e70ee3ce5 Author: taku0 <mxxouy6x3m_git...@tatapa.org> Commit: taku0 <mxxouy6x3m_git...@tatapa.org>
Speed-up indentation for colon --- swift-mode-lexer.el | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/swift-mode-lexer.el b/swift-mode-lexer.el index 4bdec5e..b00bbcc 100644 --- a/swift-mode-lexer.el +++ b/swift-mode-lexer.el @@ -437,27 +437,38 @@ That is supertype declaration or type declaration of let or var." '("class" "extension" "enum" "struct" "protocol" "typealias" "associatedtype")))))) -(defun swift-mode:case-colon-p () - "Return t if a colon at the cursor is the colon for case or default label." - (save-excursion - (member - ;; This function can be confused by conditional operator. - ;; - ;; - ;; switch foo { - ;; case let x where x is Foo ? - ;; a : // This function should return nil but it - ;; // actually retuns t. - ;; b: // This function should return t but it - ;; // actually return nil. - ;; let y = a ? b : c // This function returns nil correctly for this. - ;; } +(defvar swift-mode:in-recursive-call-of-case-colon-p nil + "Non-nil if `case-colon-p' is being evaluated.") - ;; FIXME: mutual dependency - (swift-mode:token:text - (swift-mode:backward-sexps-until - '(implicit-\; \; { \( \[ "case" "default" ":"))) - '("case" "default")))) +(defun swift-mode:case-colon-p () + "Return non-nil if the colon at the cursor follows case or default label. + +Return nil otherwise." + (if swift-mode:in-recursive-call-of-case-colon-p + nil + (save-excursion + (setq swift-mode:in-recursive-call-of-case-colon-p t) + + (unwind-protect + (member + ;; FIXME: + ;; This function can be confused by conditional operator. + ;; + ;; switch foo { + ;; case let x where x is Foo ? + ;; a : // This function should return nil but it + ;; // actually retuns t. + ;; b: // This function should return t but it + ;; // actually return nil. + ;; let y = a ? b : c // This function returns nil correctly for this. + ;; } + + ;; FIXME: mutual dependency + (swift-mode:token:text + (swift-mode:backward-sexps-until + '(implicit-\; \; { \( \[ "case" "default" ":"))) + '("case" "default")) + (setq swift-mode:in-recursive-call-of-case-colon-p nil))))) (defun swift-mode:anonyous-parameter-in-p () "Return t if a 'in' token at the cursor is for anonymous function parameters."