[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
- [nongnu] elpa/nix-mode 0ac0271f6c 201/500: Update Homepage in .el files, (continued)
- [nongnu] elpa/nix-mode 0ac0271f6c 201/500: Update Homepage in .el files, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 39f29d8be4 207/500: Replace indentation code with simpler heuristics, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 57ac40d53b 214/500: Merge pull request #45 from eqyiel/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ba202b6657 220/500: Add nix-shell.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 082a25ba7d 227/500: Add more default packages in nix.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b98c1083a0 234/500: nix-shell-file not risky, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9fb4e16c9f 233/500: Setup global-nix-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 161e7ae4d2 237/500: Cleanup nix-instantiate, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c1b1982ea7 239/500: Fix nix-instantiate.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1b15a6e583 252/500: Merge pull request #46 from matthewbauer/develop, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1e53bed4d4 299/500: Move the logic for indentation of first line of file,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 79a3715c3d 303/500: Improve handling of 'in' after a hanging 'let'., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6e4f66de1d 317/500: Add all-packages.nix test case, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f938aeaeb6 324/500: Fix buggy implementation of nix-smie--anchor., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 63fbbf27bf 326/500: Improve indentation of closing parentheses., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b12aeada41 334/500: Don’t use smie-indent-line when nix-mode-use-smie is nil, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e5abdd41e4 352/500: add json-mode dependency, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ab49f46754 027/500: Redo keymap, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 81e8c3dea6 032/500: cleanup formatting, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 09d40e95e2 037/500: Skip braces with hanging indents, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f29d9865e4 055/500: Fixup hanging indents., ELPA Syncer, 2022/01/29