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

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

[nongnu] elpa/jade-mode 36fbf629a8 049/128: Improved sws-mode indentatio


From: ELPA Syncer
Subject: [nongnu] elpa/jade-mode 36fbf629a8 049/128: Improved sws-mode indentation
Date: Sat, 29 Jan 2022 08:24:46 -0500 (EST)

branch: elpa/jade-mode
commit 36fbf629a846dfeae47cd80cd15c9ab8b9f87320
Author: Jaakko Pallari <jkpl@lepovirta.org>
Commit: Jaakko Pallari <jkpl@lepovirta.org>

    Improved sws-mode indentation
    
    If the the last command wasn't an indentation command and the current
    line indentation is 0, the 'sws-indent-line indents to whatever was the
    previous line indent. This way it works better with 'newline-and-indent
    but the function still works as it previously did.
    
    Also, the 'sws-previous-indentation now searches for a previous line
    that has atleast one non-whitespace character.
---
 sws-mode.el | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/sws-mode.el b/sws-mode.el
index 51dbcd137e..84f9a74a85 100644
--- a/sws-mode.el
+++ b/sws-mode.el
@@ -14,8 +14,11 @@
 (defun sws-previous-indentation ()
   "Gets indentation of previous line"
   (save-excursion
-    (previous-line)
-    (current-indentation)))
+    (forward-line -1)
+    (if (bobp) 0
+      (progn
+        (while (and (looking-at "^[ \t]*$") (not (bobp))) (forward-line -1))
+        (current-indentation)))))
 
 (defun sws-max-indent ()
   "Calculates max indentation"
@@ -44,12 +47,14 @@
 (defun sws-indent-line ()
   "Indents current line"
   (interactive)
-  (if mark-active
-      (sws-indent-region)
-    (if (sws-at-bot-p)
-        (sws-do-indent-line)
-      ;; instead of adjusting indent, move point to text
-      (sws-point-to-bot))))
+  (if (and (eq (current-indentation) 0)
+           (not (eq last-command 'sws-indent-line)))
+      (indent-to (sws-previous-indentation))
+    (if mark-active
+        (sws-indent-region (region-beginning) (region-end))
+      (if (sws-at-bot-p)
+          (sws-do-indent-line)
+        (sws-point-to-bot)))))
 
 (defun sws-at-bol-p ()
   "If point is at beginning of line"



reply via email to

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