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

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

[nongnu] elpa/nix-mode 1e53bed4d4 299/500: Move the logic for indentatio


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 1e53bed4d4 299/500: Move the logic for indentation of first line of file
Date: Sat, 29 Jan 2022 08:27:15 -0500 (EST)

branch: elpa/nix-mode
commit 1e53bed4d47c526c71113569f592c82845a17784
Author: Elis Hirwing <elis@hirwing.se>
Commit: Elis Hirwing <elis@hirwing.se>

    Move the logic for indentation of first line of file
    
    This moves the logic of indentation of the first line of the file from
    the logic of indenting the first line of a block of any kind. This
    greatly simplify the code in the block function and it doesn't make
    sense to do that check that late either since it's a simple check that
    hardly can go wrong.
---
 nix-mode.el | 49 ++++++++++++++++++++++---------------------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 707723f3ca..1f36ba105e 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -365,33 +365,25 @@ STRING-TYPE type of string based off of Emacs syntax 
table types"
   "Indent the first line in a block."
 
   (let ((matching-indentation (save-excursion
-                                ;; If we're on the first line of the buffer
-                                (if (= (line-number-at-pos) 1)
-                                    ;; Return that we want to ident to 
position 0 if we're on th
-                                    ;; first line. This fixes bad indent of 
things and avoid endless
-                                    ;; indent loop of tokens that would match 
below if we press tab
-                                    ;; on the first line and it happens to 
match any of the ones below.
-                                    0
-
-                                  ;; Go back to previous line that contain 
anything useful to check the
-                                  ;; contents of that line.
-                                  (beginning-of-line)
-                                  (skip-chars-backward "\n[:space:]")
-
-                                  ;; Grab the full string of the line before 
the one we're indenting
-                                  (let ((line (buffer-substring-no-properties 
(line-beginning-position) (line-end-position))))
-                                    ;; Then regex-match strings at the end of 
the line to detect if we need to indent the line after.
-                                    ;; We could probably add more things to 
look for here in the future.
-                                    (if (or (string-match "let$" line)
-                                            (string-match "import$" line)
-                                            (string-match "\\[$" line)
-                                            (string-match "=$" line)
-                                            (string-match "\($" line)
-                                            (string-match "\{$" line))
-
-                                        ;; If it matches any of the regexes 
above, grab the indent level
-                                        ;; of the line and add 2 to ident the 
line below this one.
-                                        (+ 2 (current-indentation))))))))
+                                ;; Go back to previous line that contain 
anything useful to check the
+                                ;; contents of that line.
+                                (beginning-of-line)
+                                (skip-chars-backward "\n[:space:]")
+
+                                ;; Grab the full string of the line before the 
one we're indenting
+                                (let ((line (buffer-substring-no-properties 
(line-beginning-position) (line-end-position))))
+                                  ;; Then regex-match strings at the end of 
the line to detect if we need to indent the line after.
+                                  ;; We could probably add more things to look 
for here in the future.
+                                  (if (or (string-match "let$" line)
+                                          (string-match "import$" line)
+                                          (string-match "\\[$" line)
+                                          (string-match "=$" line)
+                                          (string-match "\($" line)
+                                          (string-match "\{$" line))
+
+                                      ;; If it matches any of the regexes 
above, grab the indent level
+                                      ;; of the line and add 2 to ident the 
line below this one.
+                                      (+ 2 (current-indentation)))))))
     (when matching-indentation (indent-line-to matching-indentation) t)))
 
 (defun nix-mode-search-backward ()
@@ -476,6 +468,9 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
   (let ((end-of-indentation
          (save-excursion
            (cond
+            ;; Indent first line of file to 0
+            ((= (line-number-at-pos) 1)
+             (indent-line-to 0))
 
             ;; comment
             ((save-excursion



reply via email to

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