summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-01-12 14:56:52 +0100
committerLudovic Courtès <ludo@gnu.org>2017-01-12 14:56:52 +0100
commit7bb2b10cd01a076d7d5e964ed433e62846042859 (patch)
treed1d6958d31e2814f1969d23417e8fec8da8bf575
parenta91740655c8d18cd1b266d4d5719146cfeaf400d (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--.gitignore1
-rw-r--r--configure.ac5
-rw-r--r--doc/contributing.texi23
-rwxr-xr-xetc/indent-package.el.in53
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]
128tmp 128tmp
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])
232dnl Manual pages. 232dnl Manual pages.
233AM_MISSING_PROG([HELP2MAN], [help2man]) 233AM_MISSING_PROG([HELP2MAN], [help2man])
234 234
235dnl Emacs (optional), for 'etc/indent-package.el'.
236AC_PATH_PROG([EMACS], [emacs], [/usr/bin/emacs])
237AC_SUBST([EMACS])
238
235AC_CONFIG_FILES([Makefile 239AC_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])
241AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env]) 245AC_CONFIG_FILES([test-env:build-aux/test-env.in], [chmod +x test-env])
242AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in], 246AC_CONFIG_FILES([pre-inst-env:build-aux/pre-inst-env.in],
243 [chmod +x pre-inst-env]) 247 [chmod +x pre-inst-env])
248AC_CONFIG_FILES([etc/indent-package.el], [chmod +x etc/indent-package.el])
244 249
245AC_OUTPUT 250AC_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
240When writing Scheme code, we follow common wisdom among Scheme 242When writing Scheme code, we follow common wisdom among Scheme
241programmers. In general, we follow the 243programmers. 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
247Some special forms introduced in Guix, such as the @code{substitute*} 249Some special forms introduced in Guix, such as the @code{substitute*}
248macro, have special indentation rules. These are defined in the 250macro, 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.
250not use Emacs, please make sure to let your editor know the rules. 252
253@cindex indentation, of code
254@cindex formatting, of code
255If you do not use Emacs, please make sure to let your editor knows these
256rules. 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
263This automatically indents the definition of @var{package} in
264@file{gnu/packages/@var{file}.scm} by running Emacs in batch mode.
251 265
252We require all top-level procedures to carry a docstring. This 266We require all top-level procedures to carry a docstring. This
253requirement can be relaxed for simple private procedures in the 267requirement can be relaxed for simple private procedures in the
@@ -358,6 +372,11 @@ Bundling unrelated changes together makes reviewing harder and slower.
358Examples of unrelated changes include the addition of several packages, 372Examples of unrelated changes include the addition of several packages,
359or a package update along with fixes to that package. 373or a package update along with fixes to that package.
360 374
375@item
376Please 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
363When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as 382When 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