Klimi's new dotfiles with stow.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

37 linhas
1.1 KiB

há 4 anos
  1. ;;; nix-format.el --- Nix formatter -*- lexical-binding: t -*-
  2. ;; This file is NOT part of GNU Emacs.
  3. ;; Version: 1.4.0
  4. ;;; Commentary:
  5. ;;; Code:
  6. (defcustom nix-nixfmt-bin "nixfmt"
  7. "Path to nixfmt executable."
  8. :group 'nix
  9. :type 'string)
  10. (defun nix--format-call (buf)
  11. "Format BUF using nixfmt."
  12. (with-current-buffer (get-buffer-create "*nixfmt*")
  13. (erase-buffer)
  14. (insert-buffer-substring buf)
  15. (if (zerop (call-process-region (point-min) (point-max) nix-nixfmt-bin t t nil))
  16. (progn
  17. (if (not (string= (buffer-string) (with-current-buffer buf (buffer-string))))
  18. (copy-to-buffer buf (point-min) (point-max)))
  19. (kill-buffer))
  20. (error "Nixfmt failed, see *nixfmt* buffer for details"))))
  21. (defun nix-format-buffer ()
  22. "Format the current buffer using nixfmt."
  23. (interactive)
  24. (unless (executable-find nix-nixfmt-bin)
  25. (error "Could not locate executable \"%s\"" nix-nixfmt-bin))
  26. (nix--format-call (current-buffer))
  27. (message "Formatted buffer with nixfmt."))
  28. (provide 'nix-format)
  29. ;;; nix-format.el ends here