branch: elpa/nix-mode
commit 207e5c0a92536a271b18354745e58abd3553336a
Author: Aaron L. Zeng <[email protected]>
Commit: Aaron L. Zeng <[email protected]>
nix-format.el: Add nix-format-before-save
This is an autoloaded function suitable for adding to
the global `before-save-hook`.
---
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