/emacs-nixfmt

Emacs package for reformatting Nix code using nixfmt

Primary LanguageEmacs Lisp

Melpa Status Melpa Stable Status Build Status Support me

nixfmt.el

This Emacs library provides commands and a minor mode for easily reformatting Nix source code using the nixfmt command.

Installation

If you choose not to use one of the convenient packages in MELPA, you'll need to add the directory containing nixfmt.el to your load-path, and then (require 'nixfmt).

Usage

Customise the nixfmt-command variable as desired, then call nixfmt-buffer or nixfmt-region as convenient.

Enable nixfmt-on-save-mode in Nix buffers like this:

(add-hook 'nix-mode-hook 'nixfmt-on-save-mode)

or locally to your project with a form in your .dir-locals.el like this:

((nix-mode
   (mode . nixfmt-on-save)))

You might like to bind nixfmt or nixfmt-buffer to a key, e.g. with:

(define-key 'nix-mode-map (kbd "C-c C-f") 'nixfmt)

💝 Support this project and my other Open Source work

💼 LinkedIn profile

✍ sanityinc.com

🐦 @sanityinc