[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 7556c032dc 421/500: Use the located nixfmt binary
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 7556c032dc 421/500: Use the located nixfmt binary for formatting. |
Date: |
Sat, 29 Jan 2022 08:27:51 -0500 (EST) |
branch: elpa/nix-mode
commit 7556c032dc0c84a7d3b982169205102dcbf0dc42
Author: Zachary Newman <z@znewman.net>
Commit: Zachary Newman <z@znewman.net>
Use the located nixfmt binary for formatting.
Allows use with `nixfmt` installed using direnv ([envrc-mode]).
Before:
1. `nix-format-buffer` checks for `nixfmt`: `(executable-find
nix-nixfmt-bin)`
2. If it's missing, error. Otherwise, disregard the path to `nixfmt`
that we just found.
3. Open a new buffer (if using `envrc-mode`, with a totally different
`$PATH`) and try to run `nix-nixfmt-bin`.
If you had `nixfmt` installed in your direnv but not globally, this
gives an error: "Searching for program: No such file or directory, nixfmt".
Now, we use the path that we just found and `call-process-region` on that.
[envrc-mode]: https://github.com/purcell/envrc
---
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)
- [nongnu] elpa/nix-mode 9f24153d67 367/500: Remove redundant case in tokenizer., (continued)
- [nongnu] elpa/nix-mode 9f24153d67 367/500: Remove redundant case in tokenizer., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode b4518ae3ee 374/500: fixed a typo, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d13d70b37d 377/500: Merge pull request #102 from yilinwei/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode a00b3f776d 384/500: Merge pull request #103 from yilinwei/patch-1, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode bb0b49e3ac 408/500: Merge pull request #112 from leungbk/makefile-load-path, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7d09073976 424/500: Merge pull request #121 from znewman01/fixbuild, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 4941961c75 059/500: Get rid of extra hanging indent matches., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode c577957d66 347/500: Merge pull request #85 from NixOS/fix-84, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode cccd68768b 319/500: Install info page to the right location, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e820157994 338/500: Merge pull request #82 from jabranham/comp-warns, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7556c032dc 421/500: Use the located nixfmt binary for formatting.,
ELPA Syncer <=
- [nongnu] elpa/nix-mode df4ba688a7 435/500: Merge branch 'nix-search-updates', ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 4528033194 018/500: Add "nix-mode-reload" function., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode f3b4215166 004/500: Update metadata, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 69c7c87caa 017/500: Sert comment-multi-line., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 83229f0d4c 041/500: Fix flycheck errors., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 76ad5882f0 046/500: format, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3ef4647aa2 052/500: Fixup lets/ins counting., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0ad464e25a 058/500: Add ']' to match closing parens., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 376cbff828 054/500: More let fixes., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 1a1ce340af 070/500: Fix indentation case when '{' at beginning., ELPA Syncer, 2022/01/29