etc: Add 'indent-package.el' script.

* configure.ac: Check for 'emacs', substitute 'EMACS', and emit
'etc/indent-package.el'.
* etc/indent-package.el.in: New file.
* doc/contributing.texi (Formatting Code): Mention
'etc/indent-package.el'.
(Submitting Patches): Likewise, and link to the above node.

Co-authored-by: Alex Kost <alezost@gmail.com>
This commit is contained in:
Ludovic Courtès 2017-01-12 14:56:52 +01:00
parent a91740655c
commit 7bb2b10cd0
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
4 changed files with 80 additions and 2 deletions

1
.gitignore vendored
View file

@ -128,3 +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

View file

@ -232,6 +232,10 @@ AM_MISSING_PROG([DOT], [dot])
dnl Manual pages. dnl Manual pages.
AM_MISSING_PROG([HELP2MAN], [help2man]) AM_MISSING_PROG([HELP2MAN], [help2man])
dnl Emacs (optional), for 'etc/indent-package.el'.
AC_PATH_PROG([EMACS], [emacs], [/usr/bin/emacs])
AC_SUBST([EMACS])
AC_CONFIG_FILES([Makefile AC_CONFIG_FILES([Makefile
po/guix/Makefile.in po/guix/Makefile.in
po/packages/Makefile.in po/packages/Makefile.in
@ -241,5 +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_OUTPUT AC_OUTPUT

View file

@ -237,6 +237,8 @@ especially when matching lists.
@node Formatting Code @node Formatting Code
@subsection Formatting Code @subsection Formatting Code
@cindex formatting code
@cindex coding style
When writing Scheme code, we follow common wisdom among Scheme When writing Scheme code, we follow common wisdom among Scheme
programmers. In general, we follow the programmers. In general, we follow the
@url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp @url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp
@ -246,8 +248,20 @@ please do read it.
Some special forms introduced in Guix, such as the @code{substitute*} Some special forms introduced in Guix, such as the @code{substitute*}
macro, have special indentation rules. These are defined in the macro, have special indentation rules. These are defined in the
@file{.dir-locals.el} file, which Emacs automatically uses. If you do @file{.dir-locals.el} file, which Emacs automatically uses.
not use Emacs, please make sure to let your editor know the rules.
@cindex indentation, of code
@cindex formatting, of code
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:
@example
./etc/indent-package.el gnu/packages/@var{file}.scm @var{package}
@end example
@noindent
This automatically indents the definition of @var{package} in
@file{gnu/packages/@var{file}.scm} by running Emacs in batch mode.
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
@ -358,6 +372,11 @@ Bundling unrelated changes together makes reviewing harder and slower.
Examples of unrelated changes include the addition of several packages, Examples of unrelated changes include the addition of several packages,
or a package update along with fixes to that package. or a package update along with fixes to that package.
@item
Please follow our code formatting rules, possibly running the
@command{etc/indent-package.el} script to do that automatically for you
(@pxref{Formatting Code}).
@end enumerate @end enumerate
When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as

53
etc/indent-package.el.in Executable file
View file

@ -0,0 +1,53 @@
#!@EMACS@ --script
;;; indent-package.el --- Run Emacs to indent a package definition.
;; Copyright © 2017 Alex Kost <alezost@gmail.com>
;; This file is part of GNU Guix.
;; GNU Guix is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Guix is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This scripts indents the given package definition in the specified file
;; using Emacs.
;;; Code:
;; Load Scheme indentation rules from the current directory.
(with-temp-buffer
(scheme-mode)
(let ((default-directory (file-name-as-directory "."))
(enable-local-variables :all))
(hack-dir-local-variables)
(hack-local-variables-apply)))
(pcase command-line-args-left
(`(,file-name ,package-name)
(find-file file-name)
(goto-char (point-min))
(if (re-search-forward (concat "^(define\\(-public\\) +"
package-name)
nil t)
(let ((indent-tabs-mode nil))
(beginning-of-defun)
(indent-sexp)
(save-buffer)
(message "Done!"))
(error "Package '%s' not found in '%s'"
package-name file-name)))
(x
(error "Usage: indent-package.el FILE PACKAGE")))
;;; indent-package.el ends here