You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
2.0 KiB

  1. #!@EMACS@ --script
  2. ;;; indent-code.el --- Run Emacs to indent a package definition.
  3. ;; Copyright © 2017 Alex Kost <alezost@gmail.com>
  4. ;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
  5. ;; This file is part of GNU Guix.
  6. ;; GNU Guix is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Guix is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This scripts indents the given file or package definition in the specified
  18. ;; file using Emacs.
  19. ;;; Code:
  20. ;; Load Scheme indentation rules from the current directory.
  21. (with-temp-buffer
  22. (scheme-mode)
  23. (let ((default-directory (file-name-as-directory "."))
  24. (enable-local-variables :all))
  25. (hack-dir-local-variables)
  26. (hack-local-variables-apply)))
  27. (pcase command-line-args-left
  28. (`(,file-name ,package-name)
  29. ;; Indent the definition of PACKAGE-NAME in FILE-NAME.
  30. (find-file file-name)
  31. (goto-char (point-min))
  32. (if (re-search-forward (concat "^(define\\(-public\\) +"
  33. package-name)
  34. nil t)
  35. (let ((indent-tabs-mode nil))
  36. (beginning-of-defun)
  37. (indent-sexp)
  38. (save-buffer)
  39. (message "Done!"))
  40. (error "Package '%s' not found in '%s'"
  41. package-name file-name)))
  42. (`(,file-name)
  43. ;; Indent all of FILE-NAME.
  44. (find-file file-name)
  45. (let ((indent-tabs-mode nil))
  46. (indent-region (point-min) (point-max))
  47. (save-buffer)
  48. (message "Done!")))
  49. (x
  50. (error "Usage: indent-code.el FILE [PACKAGE]")))
  51. ;;; indent-code.el ends here