summary refs log tree commit diff
path: root/etc
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2017-01-14 05:24:09 -0500
committerMark H Weaver <mhw@netris.org>2017-01-14 05:24:09 -0500
commit5827ea30ee64f2981929f865cf4c07e6c4712773 (patch)
tree31b6505f4ad9b53860028d2e47db62c34c15e484 /etc
parent57203ebba0fa3eaa7c2df9bfd3e7c59f8ee98f6a (diff)
parentdd42a330d1301fd34f36dada9d142006165abaef (diff)
downloadguix-5827ea30ee64f2981929f865cf4c07e6c4712773.tar.gz
Merge branch 'master' into gnome-updates
Diffstat (limited to 'etc')
-rwxr-xr-xetc/indent-code.el.in62
1 files changed, 62 insertions, 0 deletions
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 <alezost@gmail.com>
+;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
+
+;; 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 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