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

[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



reply via email to

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