[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode 6f66034 008/192: Improve indentation.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode 6f66034 008/192: Improve indentation. |
Date: |
Sun, 29 Aug 2021 11:01:40 -0400 (EDT) |
branch: elpa/dart-mode
commit 6f66034860f25968604b1f10d3353364da1aea01
Author: Nathan Weizenbaum <nweiz@google.com>
Commit: Nathan Weizenbaum <nweiz@google.com>
Improve indentation.
---
dart-mode.el | 90 ++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 60 insertions(+), 30 deletions(-)
diff --git a/dart-mode.el b/dart-mode.el
index fe19c1f..3a71439 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -154,38 +154,68 @@
;;; CC indentation support
+(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.
+
+SYNTAX-GUESS is the output of `c-guess-basic-syntax'."
+ (save-excursion
+ (c-safe
+ (backward-up-list)
+ (when (= (char-after) ?\{)
+ (c-backward-comments)
+ (or
+ ;; Both anonymous and named functions have a ")" immediately before
the
+ ;; code block.
+ (= (char-before) ?\))
+ ;; CC is good at figuring out if we're in a class.
+ (assq 'inclass syntax-guess))))))
+
(defadvice c-guess-basic-syntax (after dart-guess-basic-syntax activate)
(when (c-major-mode-is 'dart-mode)
- (setf (caar ad-return-value)
- (save-excursion
- (beginning-of-line)
-
- (or
- ;; Handle array literal indentation
- (when (memq (caar ad-return-value)
- '(arglist-intro
- arglist-cont
- arglist-cont-nonempty
- arglist-close))
- (save-excursion
- (c-safe
- (backward-up-list)
- (when (= (char-after) ?\[)
- (case (caar ad-return-value)
- (arglist-intro 'brace-list-intro)
- ((arglist-cont arglist-cont-nonempty) 'brace-list-entry)
- (arglist-close 'brace-list-close))))))
-
- ;; Handle indentifier keys in maps
- (when (eq (caar ad-return-value) 'label)
- (save-excursion
- (c-safe
- (c-backward-comments)
- (if (= (char-before) ?\{) 'brace-list-intro
- (backward-up-list)
- (when (= (char-after) ?\{) 'brace-list-entry)))))
-
- (caar ad-return-value))))))
+ (let* ((syntax (car (last ad-return-value)))
+ (type (car syntax)))
+ (save-excursion
+ (beginning-of-line)
+
+ (or
+ ;; Handle array literal indentation
+ (when (memq type
+ '(arglist-intro
+ arglist-cont
+ arglist-cont-nonempty
+ arglist-close))
+ (save-excursion
+ (c-safe
+ (backward-up-list)
+ (when (= (char-after) ?\[)
+ (setq ad-return-value
+ `((,(case type
+ (arglist-intro 'brace-list-intro)
+ ((arglist-cont arglist-cont-nonempty)
'brace-list-entry)
+ (arglist-close 'brace-list-close))
+ ,(cadr syntax))))
+ t))))
+
+ ;; Handle map literal indentation
+ (when (and (memq type '(label statement-block-intro statement-cont
statement block-close))
+ (not (dart-in-block-p ad-return-value)))
+ (save-excursion
+ (c-safe
+ (c-backward-comments)
+ ;; Completely reset ad-return-value here because otherwise it
+ ;; gets super-screwy.
+ (if (= (char-before) ?\{)
+ (progn
+ (back-to-indentation)
+ (setq ad-return-value `((brace-list-intro ,(point))))
+ t)
+ (backward-up-list)
+ (when (= (char-after) ?\{)
+ (c-forward-comments)
+ (back-to-indentation)
+ (setq ad-return-value `((brace-list-entry ,(point))))
+ t))))))))))
;;; Boilerplate font-lock piping
- [nongnu] branch elpa/dart-mode created (now 43975c9), ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode fc47325 012/192: Fix more keywords., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 50cbb65 015/192: Add a license (GPL3)., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 58c9bac 016/192: Add a copyright header., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 44c762d 022/192: More known bugs., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f50a1cc 037/192: Properly indent after constructors with member lists., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9be0c64 050/192: Add support for flymake., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 273f8da 053/192: Work around some dart_analzer/Emacs disagreements., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 010f557 055/192: changed (ad-do-it) to ad-do-it, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 6f66034 008/192: Improve indentation.,
ELPA Syncer <=
- [nongnu] elpa/dart-mode a081d12 011/192: Set version to 0.1., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 84580a5 021/192: Fix else block indentation., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c6478e8 026/192: Add a dart c style., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ff905a9 056/192: Merge pull request #3 from patefacio/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f35222d 057/192: Fix an error in the flymake hook., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode c6969ba 061/192: Add some support for the Dart formatter., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode be14d27 029/192: Dart doesn't use . as an identifier op., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d1d4d88 031/192: Add more known bugs., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d39043f 032/192: Fix an offset., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 5e9c9b9 034/192: Add a known bug., ELPA Syncer, 2021/08/29