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

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

[nongnu] elpa/dart-mode 61f334c 149/192: Improves indentation


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode 61f334c 149/192: Improves indentation
Date: Sun, 29 Aug 2021 11:02:07 -0400 (EDT)

branch: elpa/dart-mode
commit 61f334c3eb5f9038566994decbf5a1457b570541
Author: Brady Trainor <mail@bradyt.com>
Commit: Brady Trainor <mail@bradyt.com>

    Improves indentation
    
     - Depth is now calculated relative to previous non-empty line, rather
       than absolute depth.
    
     - If first character after indentation is a closing paren, move
       forward counting closing parens until an opening paren or newline.
       This handles cases like `),};` or `} else {`.
---
 dart-mode.el | 46 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git a/dart-mode.el b/dart-mode.el
index 4297cdd..b8b0829 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -312,17 +312,45 @@ Returns nil if `dart-sdk-path' is nil."
 
 ;;; Indentation support
 
+(defun dart-depth-of-line ()
+  (save-excursion
+    (back-to-indentation)
+    (let ((depth (car (syntax-ppss))))
+      (when (and (char-after)
+                 (= (char-syntax (char-after)) ?\)))
+        (while (and (char-after)
+                    (/= (char-syntax (char-after)) ?\()
+                    (/= (char-after) ?\C-j))
+          (when (= (char-syntax (char-after)) ?\))
+            (setq depth (1- depth)))
+          (forward-char)))
+      depth)))
+
 (defun dart-indent-line-function ()
-  (let (pt)
+  (let ((curr-depth (dart-depth-of-line))
+        prev-line
+        prev-depth
+        prev-indent)
     (save-excursion
-      (back-to-indentation)
-      (let ((depth (car (syntax-ppss))))
-        (if (= (char-syntax (char-after)) ?\))
-            (setq depth (1- depth)))
-        (indent-line-to (* depth tab-width)))
-      (setq pt (point)))
-    (when (< (point) pt)
-        (back-to-indentation))))
+      (beginning-of-line)
+      (catch 'done
+        (while t
+          (when (= (point) 1)
+            (throw 'done t))
+          (previous-line)
+          (unless (looking-at (rx (and bol (zero-or-more space) eol)))
+            (setq prev-line t)
+            (setq prev-indent (current-indentation))
+            (setq prev-depth (dart-depth-of-line))
+            (throw 'done t)))))
+    (save-excursion
+      (if prev-line
+          (indent-line-to (max 0 (+ prev-indent
+                                    (* (- curr-depth prev-depth)
+                                       tab-width))))
+        (indent-line-to 0)))
+    (when (< (current-column) (current-indentation))
+      (back-to-indentation))))
 
 
 ;;; Additional fontification support



reply via email to

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