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

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

[nongnu] elpa/dart-mode 2d00ec4 043/192: Properly indent multiline optio


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode 2d00ec4 043/192: Properly indent multiline optional parameter lists.
Date: Sun, 29 Aug 2021 11:01:47 -0400 (EDT)

branch: elpa/dart-mode
commit 2d00ec46053b90fe1df8992f8a70c43ae5350813
Author: Nathan Weizenbaum <nweiz@google.com>
Commit: Nathan Weizenbaum <nweiz@google.com>

    Properly indent multiline optional parameter lists.
---
 dart-mode.el | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/dart-mode.el b/dart-mode.el
index a7c7404..88f4136 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -194,6 +194,9 @@
 (c-lang-defconst c-opt-postfix-decl-spec-kwds
   dart '("native"))
 
+(push '(dart-brace-list-cont-nonempty . 0)
+      (get 'c-offsets-alist 'c-stylevar-fallback))
+
 (defconst dart-c-style
   '("java"
     (c-basic-offset . 2)
@@ -202,7 +205,9 @@
     (c-offsets-alist . ((arglist-intro . +)
                         (arglist-cont-nonempty . ++)
                         (statement-block-intro . dart-block-offset)
-                        (block-close . dart-block-offset))))
+                        (block-close . dart-block-offset)
+                        (dart-brace-list-cont-nonempty .
+                         dart-brace-list-cont-nonempty-offset))))
   "The default Dart styles.")
 
 (c-add-style "dart" dart-c-style)
@@ -227,6 +232,20 @@ functions taking them as parameters essentially don't 
exist."
              (if (eq syntax 'block-close) c-basic-offset 0))
         (if (eq syntax 'block-close) 0 '+)))))
 
+(defun dart-brace-list-cont-nonempty-offset (info)
+  "Indent a brace-list line in the same style as arglist-cont-nonempty.
+This could be either an actual brace-list or an optional parameter."
+  (destructuring-bind (syntax . anchor) info
+    ;; If we're in a function definition with optional arguments, indent as if
+    ;; the brace wasn't there. Currently this misses the in-function function
+    ;; definition, but that's probably acceptable.
+    (if (assq 'topmost-intro
+              (save-excursion (goto-char anchor) (c-guess-basic-syntax)))
+        '++
+      ;; Otherwise, we're in an actual brace list, in which case only indent
+      ;; once.
+      '+)))
+
 (defun dart-in-block-p (syntax-guess)
   "Return whether or not the immediately enclosing {} block is a code block.
 The other option, of course, is a map literal.
@@ -286,10 +305,11 @@ SYNTAX-GUESS is the output of `c-guess-basic-syntax'."
                  (setq ad-return-value
                        `((,(case type
                              (arglist-intro 'brace-list-intro)
-                             ((arglist-cont arglist-cont-nonempty) 
'brace-list-entry)
+                             (arglist-cont 'brace-list-entry)
+                             (arglist-cont-nonempty 
'dart-brace-list-cont-nonempty)
                              (arglist-close 'brace-list-close))
-                          ,(cadr syntax))))
-                 t))))
+                          ,(cadr syntax)))))
+               t)))
 
          ;; Handle map literal indentation
          (when (and (memq type '(label statement-block-intro statement-cont 
statement



reply via email to

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