branch: elpa/nix-mode
commit e61ecb95ef1e5d44d9e50f8e5f8fa135da623da6
Merge: 3cca5b6527 207e5c0a92
Author: Matthew Bauer <mjbaue...@gmail.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #137 from bcc32/nix-format-before-save
    
    nix-format.el: Add nix-format-before-save
---
 nix-format.el | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/nix-format.el b/nix-format.el
index 1f97e8a086..151c16bdd2 100644
--- a/nix-format.el
+++ b/nix-format.el
@@ -38,5 +38,11 @@
   (nix--format-call (current-buffer) (nix--find-nixfmt))
   (message "Formatted buffer with nixfmt."))
 
+;;;###autoload
+(defun nix-format-before-save ()
+  "Add this to `before-save-hook' to run nixfmt when saving."
+  (when (derived-mode-p 'nix-mode)
+    (nix-format-buffer)))
+
 (provide 'nix-format)
 ;;; nix-format.el ends here

Reply via email to