emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/swift-mode 359efc0 379/496: Fix indentation of function pa


From: ELPA Syncer
Subject: [nongnu] elpa/swift-mode 359efc0 379/496: Fix indentation of function parameter clauses
Date: Sun, 29 Aug 2021 11:34:11 -0400 (EDT)

branch: elpa/swift-mode
commit 359efc05cceecac363f4b0d34d0c06de803cf3ee
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>

    Fix indentation of function parameter clauses
---
 swift-mode-lexer.el                        | 32 ++++++++++++++++++++++++++++--
 test/swift-files/indent/declarations.swift |  4 +++-
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/swift-mode-lexer.el b/swift-mode-lexer.el
index ed9e5fd..f17bdd5 100644
--- a/swift-mode-lexer.el
+++ b/swift-mode-lexer.el
@@ -68,6 +68,11 @@
                    stop-at-eol-token-types
                    stop-at-bol-token-types))
 
+(declare-function swift-mode:try-backward-generic-parameters
+                  "swift-mode-indent.el"
+                  ())
+
+
 (defun swift-mode:token (type text start end)
   "Construct and return a token.
 
@@ -571,7 +576,9 @@ Return nil otherwise."
     ;;   ]
     ((eq (swift-mode:token:type next-token) '\[) t)
 
-    ;; Inserts implicit semicolon before open parenthesis.
+    ;; Inserts implicit semicolon before open parenthesis, unless it is a
+    ;; function parameter clause. Suppress implicit semicolon before function
+    ;; parameter clause.
     ;;
     ;; Open parenthesis for function arguments cannot appear at the start of a
     ;; line.
@@ -584,7 +591,8 @@ Return nil otherwise."
     ;;   (
     ;;     1
     ;;   )
-    ((eq (swift-mode:token:type next-token) '\() t)
+    ((eq (swift-mode:token:type next-token) '\()
+     (not (swift-mode:function-parameter-clause-p)))
 
     ;; Suppress implicit semicolon after the beginning of an interpolated
     ;; expression.
@@ -595,6 +603,26 @@ Return nil otherwise."
     ;; Otherwise, inserts implicit semicolon.
     (t t))))
 
+(defun swift-mode:function-parameter-clause-p ()
+  "Return t if the cursor is before a function parameter clause.
+
+Return nil otherwise."
+  (save-excursion
+    (let* ((previous-token (swift-mode:backward-token-simple))
+           (previous-type (swift-mode:token:type previous-token)))
+      (cond
+       ((eq previous-type '>)
+        (and
+         (/= (point)
+             ;; FIXME: mutual dependency
+             (progn (swift-mode:try-backward-generic-parameters) (point)))
+         (swift-mode:function-parameter-clause-p)))
+       ((or (eq previous-type 'operator)
+            (eq previous-type 'identifier))
+        (equal (swift-mode:token:text (swift-mode:backward-token-simple))
+               "func"))
+       (t nil)))))
+
 (defun swift-mode:supertype-colon-p ()
   "Return t if a colon at the cursor is the colon for supertype.
 
diff --git a/test/swift-files/indent/declarations.swift 
b/test/swift-files/indent/declarations.swift
index c0a776c..dab5296 100644
--- a/test/swift-files/indent/declarations.swift
+++ b/test/swift-files/indent/declarations.swift
@@ -223,7 +223,9 @@ class Foo {
 private
   final
   func
-  foo<A, B>(
+  foo<A,
+      B>
+  (
     x:
       Int,
     y:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]