[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dart-mode 57767bb 157/192: Makes current indentation logic
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dart-mode 57767bb 157/192: Makes current indentation logic more usable |
Date: |
Sun, 29 Aug 2021 11:02:09 -0400 (EDT) |
branch: elpa/dart-mode
commit 57767bb50a70632dd32a23029feb30a313cab79c
Author: Brady Trainor <mail@bradyt.com>
Commit: Brady Trainor <mail@bradyt.com>
Makes current indentation logic more usable
The two symbols dart-indent-trigger-commands and
dart-indent-line-function are copied from python.el, as of commit:
<https://github.com/emacs-mirror/emacs/commit/05345babc988060cca540770599282102c34f2a7>
As we work to improve the smart indentation, this makes the current
state more usable, as the first TAB press uses the smart indentation,
and subsequent presses indent to tab stops, that is 2 spaces.
Additionally we bind S-TAB to dedent.
The function dart-indent-simple is inspired by other editors and IDEs.
---
dart-mode.el | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/dart-mode.el b/dart-mode.el
index fb66412..1bbdb61 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -308,10 +308,40 @@ Returns nil if `dart-sdk-path' is nil."
(define-key dart-mode-map (kbd "C-c C-o") 'dart-format)
(define-key dart-mode-map (kbd "M-/") 'dart-expand)
(define-key dart-mode-map (kbd "M-?") 'dart-expand-parameters)
+(define-key dart-mode-map (kbd "<backtab>") 'dart-dedent-simple)
+(define-key dart-mode-map (kbd "C-c C-i") 'indent-according-to-mode)
;;; Indentation support
+(defcustom dart-indent-trigger-commands
+ '(indent-for-tab-command yas-expand yas/expand dart-dedent-simple)
+ "Commands that might trigger a `dart-indent-line' call."
+ :type '(repeat symbol)
+ :group 'dart)
+
+(defun dart-indent-line-function ()
+ "`indent-line-function' for Dart mode.
+When the variable `last-command' is equal to one of the symbols
+inside `dart-indent-trigger-commands' it cycles possible
+indentation levels from right to left."
+ (if (and (memq this-command dart-indent-trigger-commands)
+ (eq last-command this-command))
+ (dart-indent-simple)
+ (dart-indent-line-relative)))
+
+(defun dart-indent-simple (&optional backwards)
+ (interactive)
+ (save-excursion
+ (indent-line-to
+ (max 0 (indent-next-tab-stop (current-indentation) backwards))))
+ (when (< (current-column) (current-indentation))
+ (back-to-indentation)))
+
+(defun dart-dedent-simple ()
+ (interactive)
+ (dart-indent-simple 'backwards))
+
(defun dart-depth-of-line ()
(save-excursion
(back-to-indentation)
@@ -326,7 +356,7 @@ Returns nil if `dart-sdk-path' is nil."
(forward-char)))
depth)))
-(defun dart-indent-line-function ()
+(defun dart-indent-line-relative ()
(let ((curr-depth (dart-depth-of-line))
prev-line
prev-depth
- [nongnu] elpa/dart-mode d9a12e1 151/192: Fontifies function declarations, (continued)
- [nongnu] elpa/dart-mode d9a12e1 151/192: Fontifies function declarations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode aa628c9 138/192: Remove deprecated analysis server option, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 5d0a7cd 139/192: Use dart-sdk-path to find dartfmt., ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1879cb8 145/192: Update README for providing diff to dart-format on Windows, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 21abd77 152/192: Fontifies declared identifiers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode ac14859 147/192: Normalize paths for dartanalyzer on Windows, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 9d72469 169/192: Don't set variables globally, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 591b6fe 170/192: Improve handling of strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode f20f895 164/192: Move docs from README to Wiki, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 36fe2ce 166/192: Fontify identifiers after multi-nested types, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 57767bb 157/192: Makes current indentation logic more usable,
ELPA Syncer <=
- [nongnu] elpa/dart-mode 90f1120 162/192: Require subr-x for string-empty-p, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 8983e17 186/192: Code in font-lock tests were copied from dart.dev site, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 07a9e76 189/192: Add failing font-lock test, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 3c089f3 183/192: Fix font lock for abstract method, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 40f6741 150/192: Fontifies more keywords, builtins, constants and types, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode d5776f1 172/192: Fixes fontification of small strings containing only backslashes, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 5989dca 180/192: Fontify operator declaration, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 1c2cbe5 179/192: Add faceup tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode 04fcd64 190/192: Treat angle brackets as puncutation syntax instead of symbol syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/dart-mode e41f41e 174/192: Fontify untyped parameters in anonymous functions, ELPA Syncer, 2021/08/29