[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 98426b94e5 280/500: Add function to indent things
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 98426b94e5 280/500: Add function to indent things in blocks for nix-indent-line |
Date: |
Sat, 29 Jan 2022 08:27:14 -0500 (EST) |
branch: elpa/nix-mode
commit 98426b94e53ddea5e835d6cad58474affca59572
Author: Elis Hirwing <elis@hirwing.se>
Commit: Elis Hirwing <elis@hirwing.se>
Add function to indent things in blocks for nix-indent-line
Add a function `nix-indent-first-line-in-block` that checks if the
last word on the previous line is one of "let, import, [, =, (, {".
Then it adds two spaces of indent to the one of the previous line.
And if you stand on the first line of a file, it defaults to indenting
the line to zero spaces.
---
nix-mode.el | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/nix-mode.el b/nix-mode.el
index d4bf6fc486..05ba967388 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -380,6 +380,39 @@ STRING-TYPE type of string based off of Emacs syntax table
types"
(current-indentation)))))
(when matching-indentation (indent-line-to matching-indentation) t)))
+(defun nix-indent-first-line-in-block ()
+ "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))))))))
+ (when matching-indentation (indent-line-to matching-indentation) t)))
+
(defun nix-mode-make-regexp (parts)
"Combine the regexps into a single or-delimited regexp.
PARTS a list of regexps"
@@ -514,6 +547,9 @@ PARTS a list of regexps"
) -1 0)
)))))
+ ;; indent line after 'let', 'import', '[', '=', '(', '{'
+ ((nix-indent-first-line-in-block))
+
;; dedent '}', ']', ')' 'in'
((nix-indent-to-backward-match))
- [nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization options, (continued)
- [nongnu] elpa/nix-mode acf4fd09db 470/500: nix-flake: Add customization options, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7346057087 471/500: nix-flake: Show aliases in the registry as well, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode de85646434 486/500: Add dependabot.yml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 186698599c 480/500: nix-flake: Set a prompt string, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6712a66321 381/500: Fix yaml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1c42c634bf 379/500: Allow missing git repo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 38958e5203 413/500: Update install-nix-action in GitHub Action, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cc60a0d027 417/500: Make nix-drv-mode a derived-mode of javascript-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0de9c70c89 429/500: Split up `nix-search` into two separate functions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e8e5211f6e 426/500: Merge pull request #122 from leungbk/def-obsol, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 98426b94e5 280/500: Add function to indent things in blocks for nix-indent-line,
ELPA Syncer <=
- [nongnu] elpa/nix-mode 71fda1db41 373/500: add README section for nix-prettify-mode (#100), ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode fc68739bec 011/500: Fix syntax error, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cb392d45b6 030/500: tweak indentation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ade1d49841 128/500: Fixup indentation logic., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 414a40fe54 131/500: Add hydra mode (#25), ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f7fa332705 155/500: Add nix-shell custom group, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6573b1d70e 145/500: Add nix-shell.el, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0af6073003 171/500: Add nix-mode to nix-mode group., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode af686b570c 159/500: Fix package-lint complaints., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3fa526ee57 165/500: Add MELPA badges to READM.md, ELPA Syncer, 2022/01/29