From 7bb2b10cd01a076d7d5e964ed433e62846042859 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 12 Jan 2017 14:56:52 +0100 Subject: 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 --- .gitignore | 1 + 1 file changed, 1 insertion(+) (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index b64f5ef4b0..5bcc734ac5 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,4 @@ stamp-h[0-9] tmp /doc/os-config-lightweight-desktop.texi /nix/scripts/download +/etc/indent-package.el -- cgit v1.2.3 From 557d9c8d7a843bf06e75b4e1a742654ccf951fa3 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 13 Jan 2017 18:47:15 +0100 Subject: 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. --- .gitignore | 2 +- configure.ac | 2 +- doc/contributing.texi | 11 ++++++--- etc/indent-code.el.in | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ etc/indent-package.el.in | 53 ----------------------------------------- 5 files changed, 72 insertions(+), 58 deletions(-) create mode 100755 etc/indent-code.el.in delete mode 100755 etc/indent-package.el.in (limited to '.gitignore') diff --git a/.gitignore b/.gitignore index 5bcc734ac5..c64326e60e 100644 --- a/.gitignore +++ b/.gitignore @@ -128,4 +128,4 @@ stamp-h[0-9] tmp /doc/os-config-lightweight-desktop.texi /nix/scripts/download -/etc/indent-package.el +/etc/indent-code.el diff --git a/configure.ac b/configure.ac index f628fa9d0d..9079a142dc 100644 --- a/configure.ac +++ b/configure.ac @@ -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([pre-inst-env:build-aux/pre-inst-env.in], [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 diff --git a/doc/contributing.texi b/doc/contributing.texi index 9fc1eb54d8..4454df1f98 100644 --- a/doc/contributing.texi +++ b/doc/contributing.texi @@ -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: @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 @noindent 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 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 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}). @end enumerate diff --git a/etc/indent-code.el.in b/etc/indent-code.el.in new file mode 100755 index 0000000000..7556b30cc8 --- /dev/null +++ b/etc/indent-code.el.in @@ -0,0 +1,62 @@ +#!@EMACS@ --script +;;; indent-code.el --- Run Emacs to indent a package definition. + +;; Copyright © 2017 Alex Kost +;; Copyright © 2017 Ludovic Courtès + +;; 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 . + +;;; Commentary: + +;; This scripts indents the given file or 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) + ;; Indent the definition of PACKAGE-NAME in FILE-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))) + (`(,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 + (error "Usage: indent-code.el FILE [PACKAGE]"))) + +;;; indent-code.el ends here diff --git a/etc/indent-package.el.in b/etc/indent-package.el.in deleted file mode 100755 index 3188809f0b..0000000000 --- a/etc/indent-package.el.in +++ /dev/null @@ -1,53 +0,0 @@ -#!@EMACS@ --script -;;; indent-package.el --- Run Emacs to indent a package definition. - -;; Copyright © 2017 Alex Kost - -;; 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 . - -;;; 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 -- cgit v1.2.3