Klimi's new dotfiles with stow.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

37 líneas
1.1 KiB

hace 5 años
  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