nls: Update da translations.
[guix.git] / etc / indent-code.el.in
blob6102b5d1ab7baaaea2824fdf114c2831480d559c
1 #!@EMACS@ --script
2 ;;; indent-code.el --- Run Emacs to indent a package definition.
4 ;; Copyright © 2017 Alex Kost <alezost@gmail.com>
5 ;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
7 ;; This file is part of GNU Guix.
9 ;; GNU Guix is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Guix is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This scripts indents the given file or package definition in the specified
25 ;; file using Emacs.
27 ;;; Code:
29 ;; Load Scheme indentation rules from ".dir-locals.el".
30 (with-temp-buffer
31 (scheme-mode)
32 (let ((default-directory (file-name-as-directory load-file-name))
33 (enable-local-variables :all))
34 (hack-dir-local-variables)
35 (hack-local-variables-apply)))
37 ;; Add indentation info for Scheme constructs that are not Guix-specific.
38 ;; This is normally provided by Geiser but this file is for people who may not
39 ;; be running Geiser, so we just copy it here (from 'geiser-syntax.el').
40 (defmacro guix-syntax--scheme-indent (&rest pairs)
41 `(progn ,@(mapcar (lambda (p)
42 `(put ',(car p) 'scheme-indent-function ',(cadr p)))
43 pairs)))
45 (guix-syntax--scheme-indent
46 (and-let* 1)
47 (case-lambda 0)
48 (catch defun)
49 (class defun)
50 (dynamic-wind 0)
51 (guard 1)
52 (let*-values 1)
53 (let-values 1)
54 (let/ec 1)
55 (letrec* 1)
56 (match 1)
57 (match-lambda 0)
58 (match-lambda* 0)
59 (match-let scheme-let-indent)
60 (match-let* 1)
61 (match-letrec 1)
62 (opt-lambda 1)
63 (parameterize 1)
64 (parameterize* 1)
65 (receive 2)
66 (require-extension 0)
67 (syntax-case 2)
68 (test-approximate 1)
69 (test-assert 1)
70 (test-eq 1)
71 (test-equal 1)
72 (test-eqv 1)
73 (test-group-with-cleanup 1)
74 (test-runner-on-bad-count! 1)
75 (test-runner-on-bad-end-name! 1)
76 (test-runner-on-final! 1)
77 (test-runner-on-group-begin! 1)
78 (test-runner-on-group-end! 1)
79 (test-runner-on-test-begin! 1)
80 (test-runner-on-test-end! 1)
81 (test-with-runner 1)
82 (unless 1)
83 (when 1)
84 (while 1)
85 (with-exception-handler 1)
86 (with-syntax 1))
89 (pcase command-line-args-left
90 (`(,file-name ,package-name)
91 ;; Indent the definition of PACKAGE-NAME in FILE-NAME.
92 (find-file file-name)
93 (goto-char (point-min))
94 (if (re-search-forward (concat "^(define\\(-public\\) +"
95 package-name)
96 nil t)
97 (let ((indent-tabs-mode nil))
98 (beginning-of-defun)
99 (indent-sexp)
100 (save-buffer)
101 (message "Done!"))
102 (error "Package '%s' not found in '%s'"
103 package-name file-name)))
104 (`(,file-name)
105 ;; Indent all of FILE-NAME.
106 (find-file file-name)
107 (let ((indent-tabs-mode nil))
108 (indent-region (point-min) (point-max))
109 (save-buffer)
110 (message "Done!")))
112 (error "Usage: indent-code.el FILE [PACKAGE]")))
114 ;;; indent-code.el ends here