[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/nix-mode 233bf03b96 040/500: Add nixfmt command.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/nix-mode 233bf03b96 040/500: Add nixfmt command. |
Date: |
Sat, 29 Jan 2022 08:26:34 -0500 (EST) |
branch: elpa/nix-mode
commit 233bf03b960112554b15e5aa7d03008dc2d53c97
Author: Matthew Bauer <mjbauer95@gmail.com>
Commit: Matthew Bauer <mjbauer95@gmail.com>
Add nixfmt command.
This should be compatible with the nixfmt available here:
https://github.com/Gabriel439/nixfmt
---
nix-mode.el | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/nix-mode.el b/nix-mode.el
index 4c06319404..d7da9ee0c7 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -238,6 +238,31 @@ If a close brace `}' ends an antiquote, the next character
begins a string."
(if (looking-at nix-re-file-path)
(find-file (match-string-no-properties 0)))))
+(defcustom nix-nixfmt-bin "nixfmt"
+ "Path to nixfmt executable."
+ :group 'nix
+ :type 'string)
+
+(defun nix--format-call (buf)
+ "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))
+ (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-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))
+ (message "Formatted buffer with rustfmt."))
+
(defvar nix-mode-menu (make-sparse-keymap "Nix")
"Menu for Nix mode.")
@@ -247,12 +272,14 @@ If a close brace `}' ends an antiquote, the next
character begins a string."
(defun nix-create-keymap ()
"Create the keymap associated with the Nix mode."
- (define-key nix-mode-map "\C-c\C-f" 'nix-visit-file))
+ (define-key nix-mode-map "\C-c\C-g" 'nix-visit-file)
+ (define-key nix-mode-map "\C-c\C-f" 'nix-format-buffer))
(defun nix-create-menu ()
"Create the Nix menu as shown in the menu bar."
(let ((m '("Nix"
- ["Goto file" nix-visit-file t])
+ ["Goto file" nix-visit-file t]
+ ["Format buffer" nix-format-buffer t])
))
(easy-menu-define ada-mode-menu nix-mode-map "Menu keymap for Nix mode"
m)))
- [nongnu] elpa/nix-mode 36070654c8 243/500: Don’t autoload nix-instantiate., (continued)
- [nongnu] elpa/nix-mode 36070654c8 243/500: Don’t autoload nix-instantiate., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d2f4a629a8 258/500: Only show derivations in nix store, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode d0eb92e97a 263/500: Package linting, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 38061187ca 265/500: Add nix-read-file & nix-read-attr, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7d65288c72 266/500: Fix erroneous use of function as variable, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 8b3a9927e7 270/500: Add dependency on json-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 7a7f600133 288/500: travis: Add travis badge, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode da16900326 293/500: tests: Add a testcase with broken identation to have as a check if it indents at all, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode aa43b72a45 014/500: Revert "Use warning font lock for upper case vars", ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 5a2674592f 033/500: Don't save-excursion for nix-indent-line., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 233bf03b96 040/500: Add nixfmt command.,
ELPA Syncer <=
- [nongnu] elpa/nix-mode ff550f9bbd 036/500: Add comments., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ea95e3c9c6 068/500: Add nix-prettify-mode.el., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 6eaf2a97d2 069/500: Fixup hanging indent., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode e53d99d840 064/500: Ignore '* chars in syntax propertize., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 9b705381c4 063/500: Fix antiquote highlighting., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0624820fd3 067/500: Fix org-mode fontification error., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 3338f5997e 056/500: Fix beginning of buffer issue, ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 0f01eecdaa 050/500: Make sure everything starts at beginning of line., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode 03f462ef34 062/500: Add "+" to hanging indent list., ELPA Syncer, 2022/01/29
- [nongnu] elpa/nix-mode ad09b3be7f 066/500: Fix flycheck errors., ELPA Syncer, 2022/01/29