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

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

[nongnu] elpa/jade-mode 63561e36f7 006/128: functional line indentation


From: ELPA Syncer
Subject: [nongnu] elpa/jade-mode 63561e36f7 006/128: functional line indentation logic
Date: Sat, 29 Jan 2022 08:24:41 -0500 (EST)

branch: elpa/jade-mode
commit 63561e36f7a9b5b0887932feed04d459afe3e6b9
Author: brianc <brian.m.carlson@gmail.com>
Commit: brianc <brian.m.carlson@gmail.com>

    functional line indentation logic
---
 jade-mode.el | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/jade-mode.el b/jade-mode.el
index 381a3d3a51..3230324ddd 100644
--- a/jade-mode.el
+++ b/jade-mode.el
@@ -7,6 +7,10 @@
   "Prints a debug message"
   (apply 'message (append (list string) args)))
 
+(defmacro jade-line-as-string ()
+  "Returns the current line as a string."
+  `(buffer-substring (point-at-bol) (point-at-eol)))
+
 
 (defun jade-indent-line ()
   "Indents current line")
@@ -22,15 +26,29 @@
   ;; should only indent if previous line is indented at most one less
   (> (jade-previous-indentation) (- (current-indentation) 1)))
 
+(defun jade-empty-line-p ()
+  "If line is empty or not."
+  (= (point-at-eol) (point-at-bol)))
+
 (defun jade-indent-line ()
   "Indents the line."
   (interactive)
-  (if (jade-should-indent-p)
-      (save-excursion
-        (let ((ci (current-indentation)))
-          (beginning-of-line)
-          (delete-horizontal-space)
-          (indent-to (+ jade-tab-width ci))))))
+
+  ;; indent straight to end on empty line
+  (if (jade-empty-line-p)
+      (indent-to (jade-previous-indentation))
+    (if (jade-should-indent-p)
+        (progn
+          (save-excursion
+            (let ((ci (current-indentation)))
+              (beginning-of-line)
+              (delete-horizontal-space)
+              (indent-to (+ jade-tab-width ci))))
+          )))
+  ;; move point to end of line on empty lines to make tabbing
+  ;; more obvious
+  (if (string-match-p "^[ ]*$" (jade-line-as-string))
+      (move-end-of-line 1)))
 
 (setq jade-font-lock-keywords
       `((,"!!!\\( \\(default\\|5\\|transitional\\)\\)?" 0 
font-lock-constant-face) ;; doctype



reply via email to

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