diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2017-01-12 14:56:52 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2017-01-12 14:56:52 +0100 |
| commit | 7bb2b10cd01a076d7d5e964ed433e62846042859 (patch) | |
| tree | d1d6958d31e2814f1969d23417e8fec8da8bf575 | |
| parent | a91740655c8d18cd1b266d4d5719146cfeaf400d (diff) | |
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>
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | configure.ac | 5 | ||||
| -rw-r--r-- | doc/contributing.texi | 23 | ||||
| -rwxr-xr-x | etc/indent-package.el.in | 53 |
4 files changed, 80 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index b64f5ef4b04..5bcc734ac52 100644 --- a/.gitignore +++ b/.gitignore | |||
| @@ -128,3 +128,4 @@ stamp-h[0-9] | |||
| 128 | tmp | 128 | tmp |
| 129 | /doc/os-config-lightweight-desktop.texi | 129 | /doc/os-config-lightweight-desktop.texi |
| 130 | /nix/scripts/download | 130 | /nix/scripts/download |
| 131 | /etc/indent-package.el | ||
diff --git a/configure.ac b/configure.ac index 676f600111e..f628fa9d0d2 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -232,6 +232,10 @@ AM_MISSING_PROG([DOT], [dot]) | |||
| 232 | dnl Manual pages. | 232 | dnl Manual pages. |
| 233 | AM_MISSING_PROG([HELP2MAN], [help2man]) | 233 | AM_MISSING_PROG([HELP2MAN], [help2man]) |
| 234 | 234 | ||
| 235 | dnl Emacs (optional), for 'etc/indent-package.el'. | ||
| 236 | AC_PATH_PROG([EMACS], [emacs], [/usr/bin/emacs]) | ||
| 237 | AC_SUBST([EMACS]) | ||
| 238 | |||
| 235 | AC_CONFIG_FILES([Makefile | 239 | AC_CONFIG_FILES([Makefile |
| 236 | po/guix/Makefile.in | 240 | po/guix/Makefile.in |
| 237 | po/packages/Makefile.in | 241 | po/packages/Makefile.in |
| @@ -241,5 +245,6 @@ AC_CONFIG_FILES([scripts/guix], [chmod +x scripts/guix]) | |||
| 241 | AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env]) | 245 | AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env]) |
| 242 | AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in], | 246 | AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in], |
| 243 | [chmod +x pre-inst-env]) | 247 | [chmod +x pre-inst-env]) |
| 248 | AC_CONFIG_FILES([etc/indent-package.el], [chmod +x etc/indent-package.el]) | ||
| 244 | 249 | ||
| 245 | AC_OUTPUT | 250 | AC_OUTPUT |
diff --git a/doc/contributing.texi b/doc/contributing.texi index 24db9a89e6f..9fc1eb54d85 100644 --- a/doc/contributing.texi +++ b/doc/contributing.texi | |||
| @@ -237,6 +237,8 @@ especially when matching lists. | |||
| 237 | @node Formatting Code | 237 | @node Formatting Code |
| 238 | @subsection Formatting Code | 238 | @subsection Formatting Code |
| 239 | 239 | ||
| 240 | @cindex formatting code | ||
| 241 | @cindex coding style | ||
| 240 | When writing Scheme code, we follow common wisdom among Scheme | 242 | When writing Scheme code, we follow common wisdom among Scheme |
| 241 | programmers. In general, we follow the | 243 | programmers. In general, we follow the |
| 242 | @url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp | 244 | @url{http://mumble.net/~campbell/scheme/style.txt, Riastradh's Lisp |
| @@ -246,8 +248,20 @@ please do read it. | |||
| 246 | 248 | ||
| 247 | Some special forms introduced in Guix, such as the @code{substitute*} | 249 | Some special forms introduced in Guix, such as the @code{substitute*} |
| 248 | macro, have special indentation rules. These are defined in the | 250 | macro, have special indentation rules. These are defined in the |
| 249 | @file{.dir-locals.el} file, which Emacs automatically uses. If you do | 251 | @file{.dir-locals.el} file, which Emacs automatically uses. |
| 250 | not use Emacs, please make sure to let your editor know the rules. | 252 | |
| 253 | @cindex indentation, of code | ||
| 254 | @cindex formatting, of code | ||
| 255 | If you do not use Emacs, please make sure to let your editor knows these | ||
| 256 | rules. To automatically indent a package definition, you can also run: | ||
| 257 | |||
| 258 | @example | ||
| 259 | ./etc/indent-package.el gnu/packages/@var{file}.scm @var{package} | ||
| 260 | @end example | ||
| 261 | |||
| 262 | @noindent | ||
| 263 | This automatically indents the definition of @var{package} in | ||
| 264 | @file{gnu/packages/@var{file}.scm} by running Emacs in batch mode. | ||
| 251 | 265 | ||
| 252 | We require all top-level procedures to carry a docstring. This | 266 | We require all top-level procedures to carry a docstring. This |
| 253 | requirement can be relaxed for simple private procedures in the | 267 | requirement can be relaxed for simple private procedures in the |
| @@ -358,6 +372,11 @@ Bundling unrelated changes together makes reviewing harder and slower. | |||
| 358 | Examples of unrelated changes include the addition of several packages, | 372 | Examples of unrelated changes include the addition of several packages, |
| 359 | or a package update along with fixes to that package. | 373 | or a package update along with fixes to that package. |
| 360 | 374 | ||
| 375 | @item | ||
| 376 | Please follow our code formatting rules, possibly running the | ||
| 377 | @command{etc/indent-package.el} script to do that automatically for you | ||
| 378 | (@pxref{Formatting Code}). | ||
| 379 | |||
| 361 | @end enumerate | 380 | @end enumerate |
| 362 | 381 | ||
| 363 | When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as | 382 | When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as |
diff --git a/etc/indent-package.el.in b/etc/indent-package.el.in new file mode 100755 index 00000000000..3188809f0b4 --- /dev/null +++ b/etc/indent-package.el.in | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #!@EMACS@ --script | ||
| 2 | ;;; indent-package.el --- Run Emacs to indent a package definition. | ||
| 3 | |||
| 4 | ;; Copyright © 2017 Alex Kost <alezost@gmail.com> | ||
| 5 | |||
| 6 | ;; This file is part of GNU Guix. | ||
| 7 | |||
| 8 | ;; GNU Guix is free software; you can redistribute it and/or modify | ||
| 9 | ;; it under the terms of the GNU General Public License as published by | ||
| 10 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 11 | ;; (at your option) any later version. | ||
| 12 | |||
| 13 | ;; GNU Guix is distributed in the hope that it will be useful, | ||
| 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | ;; GNU General Public License for more details. | ||
| 17 | |||
| 18 | ;; You should have received a copy of the GNU General Public License | ||
| 19 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | |||
| 21 | ;;; Commentary: | ||
| 22 | |||
| 23 | ;; This scripts indents the given package definition in the specified file | ||
| 24 | ;; using Emacs. | ||
| 25 | |||
| 26 | ;;; Code: | ||
| 27 | |||
| 28 | ;; Load Scheme indentation rules from the current directory. | ||
| 29 | (with-temp-buffer | ||
| 30 | (scheme-mode) | ||
| 31 | (let ((default-directory (file-name-as-directory ".")) | ||
| 32 | (enable-local-variables :all)) | ||
| 33 | (hack-dir-local-variables) | ||
| 34 | (hack-local-variables-apply))) | ||
| 35 | |||
| 36 | (pcase command-line-args-left | ||
| 37 | (`(,file-name ,package-name) | ||
| 38 | (find-file file-name) | ||
| 39 | (goto-char (point-min)) | ||
| 40 | (if (re-search-forward (concat "^(define\\(-public\\) +" | ||
| 41 | package-name) | ||
| 42 | nil t) | ||
| 43 | (let ((indent-tabs-mode nil)) | ||
| 44 | (beginning-of-defun) | ||
| 45 | (indent-sexp) | ||
| 46 | (save-buffer) | ||
| 47 | (message "Done!")) | ||
| 48 | (error "Package '%s' not found in '%s'" | ||
| 49 | package-name file-name))) | ||
| 50 | (x | ||
| 51 | (error "Usage: indent-package.el FILE PACKAGE"))) | ||
| 52 | |||
| 53 | ;;; indent-package.el ends here | ||
