branch: elpa/nix-mode
commit a5bf79a563f9ef2b77b91a2ecaa112d3153beacf
Merge: 7d09073976 7556c032dc
Author: Matthew Bauer <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #120 from znewman01/master
Use the located nixfmt binary for formatting.
---
nix-format.el | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/nix-format.el b/nix-format.el
index f43dc4d908..1f97e8a086 100644
--- a/nix-format.el
+++ b/nix-format.el
@@ -13,24 +13,29 @@
:group 'nix
:type 'string)
-(defun nix--format-call (buf)
+(defun nix--format-call (buf nixfmt-bin)
"Format BUF using nixfmt."
(with-current-buffer (get-buffer-create "*nixfmt*")
(erase-buffer)
(insert-buffer-substring buf)
- (if (zerop (call-process-region (point-min) (point-max) nix-nixfmt-bin t t
nil))
+ (if (zerop (call-process-region (point-min) (point-max) nixfmt-bin t t
nil))
(progn
(if (not (string= (buffer-string) (with-current-buffer buf
(buffer-string))))
(copy-to-buffer buf (point-min) (point-max)))
(kill-buffer))
(error "Nixfmt failed, see *nixfmt* buffer for details"))))
+(defun nix--find-nixfmt ()
+ "Find the nixfmt binary, or error if it's missing."
+ (let ((nixfmt-bin (executable-find nix-nixfmt-bin)))
+ (unless nixfmt-bin
+ (error "Could not locate executable \"%s\"" nix-nixfmt-bin))
+ nixfmt-bin))
+
(defun nix-format-buffer ()
"Format the current buffer using nixfmt."
(interactive)
- (unless (executable-find nix-nixfmt-bin)
- (error "Could not locate executable \"%s\"" nix-nixfmt-bin))
- (nix--format-call (current-buffer))
+ (nix--format-call (current-buffer) (nix--find-nixfmt))
(message "Formatted buffer with nixfmt."))
(provide 'nix-format)