me
/
guix
Archived
1
0
Fork 0

etc: Support indentation of whole files.

* etc/indent-package.el.in: Rename to...
* etc/indent-code.el.in: ... this.  Add case for a single argument.
* doc/contributing.texi (Formatting Code): Adjust accordingly.
* configure.ac: Likewise.
master
Ludovic Courtès 2017-01-13 18:47:15 +01:00
parent 608a50b66c
commit 557d9c8d7a
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
4 changed files with 24 additions and 10 deletions

2
.gitignore vendored
View File

@ -128,4 +128,4 @@ stamp-h[0-9]
tmp tmp
/doc/os-config-lightweight-desktop.texi /doc/os-config-lightweight-desktop.texi
/nix/scripts/download /nix/scripts/download
/etc/indent-package.el /etc/indent-code.el

View File

@ -245,6 +245,6 @@ AC_CONFIG_FILES([scripts/guix], [chmod +x scripts/guix])
AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env]) AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env])
AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in], AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in],
[chmod +x pre-inst-env]) [chmod +x pre-inst-env])
AC_CONFIG_FILES([etc/indent-package.el], [chmod +x etc/indent-package.el]) AC_CONFIG_FILES([etc/indent-code.el], [chmod +x etc/indent-code.el])
AC_OUTPUT AC_OUTPUT

View File

@ -256,12 +256,17 @@ If you do not use Emacs, please make sure to let your editor knows these
rules. To automatically indent a package definition, you can also run: rules. To automatically indent a package definition, you can also run:
@example @example
./etc/indent-package.el gnu/packages/@var{file}.scm @var{package} ./etc/indent-code.el gnu/packages/@var{file}.scm @var{package}
@end example @end example
@noindent @noindent
This automatically indents the definition of @var{package} in This automatically indents the definition of @var{package} in
@file{gnu/packages/@var{file}.scm} by running Emacs in batch mode. @file{gnu/packages/@var{file}.scm} by running Emacs in batch mode. To
indent a whole file, omit the second argument:
@example
./etc/indent-code.el gnu/services/@var{file}.scm
@end example
We require all top-level procedures to carry a docstring. This We require all top-level procedures to carry a docstring. This
requirement can be relaxed for simple private procedures in the requirement can be relaxed for simple private procedures in the
@ -374,7 +379,7 @@ or a package update along with fixes to that package.
@item @item
Please follow our code formatting rules, possibly running the Please follow our code formatting rules, possibly running the
@command{etc/indent-package.el} script to do that automatically for you @command{etc/indent-code.el} script to do that automatically for you
(@pxref{Formatting Code}). (@pxref{Formatting Code}).
@end enumerate @end enumerate

View File

@ -1,7 +1,8 @@
#!@EMACS@ --script #!@EMACS@ --script
;;; indent-package.el --- Run Emacs to indent a package definition. ;;; indent-code.el --- Run Emacs to indent a package definition.
;; Copyright © 2017 Alex Kost <alezost@gmail.com> ;; Copyright © 2017 Alex Kost <alezost@gmail.com>
;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
;; This file is part of GNU Guix. ;; This file is part of GNU Guix.
@ -20,8 +21,8 @@
;;; Commentary: ;;; Commentary:
;; This scripts indents the given package definition in the specified file ;; This scripts indents the given file or package definition in the specified
;; using Emacs. ;; file using Emacs.
;;; Code: ;;; Code:
@ -35,6 +36,7 @@
(pcase command-line-args-left (pcase command-line-args-left
(`(,file-name ,package-name) (`(,file-name ,package-name)
;; Indent the definition of PACKAGE-NAME in FILE-NAME.
(find-file file-name) (find-file file-name)
(goto-char (point-min)) (goto-char (point-min))
(if (re-search-forward (concat "^(define\\(-public\\) +" (if (re-search-forward (concat "^(define\\(-public\\) +"
@ -47,7 +49,14 @@
(message "Done!")) (message "Done!"))
(error "Package '%s' not found in '%s'" (error "Package '%s' not found in '%s'"
package-name file-name))) package-name file-name)))
(`(,file-name)
;; Indent all of FILE-NAME.
(find-file file-name)
(let ((indent-tabs-mode nil))
(indent-region (point-min) (point-max))
(save-buffer)
(message "Done!")))
(x (x
(error "Usage: indent-package.el FILE PACKAGE"))) (error "Usage: indent-code.el FILE [PACKAGE]")))
;;; indent-package.el ends here ;;; indent-code.el ends here