[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: etc: Add 'indent-package.el' script.

From: Ludovic Courtès
Subject: 01/02: etc: Add 'indent-package.el' script.
Date: Thu, 12 Jan 2017 14:00:48 +0000 (UTC)

civodul pushed a commit to branch master
in repository guix.

commit 7bb2b10cd01a076d7d5e964ed433e62846042859
Author: Ludovic Courtès <address@hidden>
Date:   Thu Jan 12 14:56:52 2017 +0100

    etc: Add 'indent-package.el' script.
    * Check for 'emacs', substitute 'EMACS', and emit
    * etc/ New file.
    * doc/contributing.texi (Formatting Code): Mention
    (Submitting Patches): Likewise, and link to the above node.
    Co-authored-by: Alex Kost <address@hidden>
 .gitignore               |    1 +             |    5 +++++
 doc/contributing.texi    |   23 ++++++++++++++++++--
 etc/ |   53 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index b64f5ef..5bcc734 100644
--- a/.gitignore
+++ b/.gitignore
@@ -128,3 +128,4 @@ stamp-h[0-9]
diff --git a/ b/
index 676f600..f628fa9 100644
--- a/
+++ b/
@@ -232,6 +232,10 @@ AM_MISSING_PROG([DOT], [dot])
 dnl Manual pages.
 AM_MISSING_PROG([HELP2MAN], [help2man])
+dnl Emacs (optional), for 'etc/indent-package.el'.
+AC_PATH_PROG([EMACS], [emacs], [/usr/bin/emacs])
@@ -241,5 +245,6 @@ AC_CONFIG_FILES([scripts/guix], [chmod +x scripts/guix])
 AC_CONFIG_FILES([test-env:build-aux/], [chmod +x test-env])
   [chmod +x pre-inst-env])
+AC_CONFIG_FILES([etc/indent-package.el], [chmod +x etc/indent-package.el])
diff --git a/doc/contributing.texi b/doc/contributing.texi
index 24db9a8..9fc1eb5 100644
--- a/doc/contributing.texi
+++ b/doc/contributing.texi
@@ -237,6 +237,8 @@ especially when matching lists.
 @node Formatting Code
 @subsection Formatting Code
address@hidden formatting code
address@hidden coding style
 When writing Scheme code, we follow common wisdom among Scheme
 programmers.  In general, we follow the
 @url{, Riastradh's Lisp
@@ -246,8 +248,20 @@ please do read it.
 Some special forms introduced in Guix, such as the @code{substitute*}
 macro, have special indentation rules.  These are defined in the
address@hidden file, which Emacs automatically uses.  If you do
-not use Emacs, please make sure to let your editor know the rules.
address@hidden file, which Emacs automatically uses.
address@hidden indentation, of code
address@hidden 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:
+./etc/indent-package.el gnu/packages/@var{file}.scm @var{package}
address@hidden example
+This automatically indents the definition of @var{package} in
address@hidden/packages/@var{file}.scm} by running Emacs in batch mode.
 We require all top-level procedures to carry a docstring.  This
 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,
 or a package update along with fixes to that package.
+Please follow our code formatting rules, possibly running the
address@hidden/indent-package.el} script to do that automatically for you
+(@pxref{Formatting Code}).
 @end enumerate
 When posting a patch to the mailing list, use @samp{[PATCH] @dots{}} as
diff --git a/etc/ b/etc/
new file mode 100755
index 0000000..3188809
--- /dev/null
+++ b/etc/
@@ -0,0 +1,53 @@
address@hidden@ --script
+;;; indent-package.el --- Run Emacs to indent a package definition.
+;; Copyright © 2017 Alex Kost <address@hidden>
+;; 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
+;; 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 <>.
+;;; Commentary:
+;; This scripts indents the given package definition in the specified file
+;; using Emacs.
+;;; Code:
+;; Load Scheme indentation rules from the current directory.
+  (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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]