Skip to content

Commit

Permalink
Add function to indent things in blocks for nix-indint-line
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etu committed Jan 2, 2019
1 parent 1512d02 commit a0266ae
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nix-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,23 @@ 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
(forward-line -1)

;; 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))))
(if (or (string-match "let$" line)
(string-match "import$" line)
(string-match "\\[$" line)
(string-match "=$" line)
(string-match "\($" line)
(string-match "\{$" line))
(current-indentation))))))
(when matching-indentation (indent-line-to (+ 2 matching-indentation)) t)))

(defun nix-mode-make-regexp (parts)
"Combine the regexps into a single or-delimited regexp.
PARTS a list of regexps"
Expand Down Expand Up @@ -514,6 +531,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))

Expand Down

0 comments on commit a0266ae

Please sign in to comment.