Browse Source

Auto format nix files

master
Nicolas Petton 6 months ago
parent
commit
64cdf6b1ef
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      init.el

+ 18
- 0
init.el View File

@@ -528,6 +528,24 @@ be global."
("C-M->" . mc/unmark-previous-like-this)
("C-c C-<" . mc/mark-all-like-this)))

(use-package nix-mode
:config (progn
(defun nixfmt-fix ()
(interactive)
(when (executable-find "nixfmt")
(let ((point (point)))
(unwind-protect
(call-process-region (point-min) (point-max) "nixfmt" t t)
(goto-char point)))))

(define-minor-mode nixfmt-fix-mode
"Use nixfmt to automatically format nix files."
:lighter " nixfmt"
(if nixfmt-fix-mode
(add-hook 'before-save-hook #'nixfmt-fix nil t)
(remove-hook 'before-save-hook #'nixfmt-fix t))))
:hook (nix-mode . nixfmt-fix-mode))

(use-package no-littering
:demand t
:config (progn


Loading…
Cancel
Save