2020-03-31 06:12:01 +02:00
|
|
|
|
:;exec emacs --batch --quick --load="$0" --funcall=main "$@"
|
2017-01-13 18:47:15 +01:00
|
|
|
|
;;; indent-code.el --- Run Emacs to indent a package definition.
|
2017-01-12 14:56:52 +01:00
|
|
|
|
|
|
|
|
|
;; Copyright © 2017 Alex Kost <alezost@gmail.com>
|
2017-01-13 18:47:15 +01:00
|
|
|
|
;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
|
2020-03-31 06:12:01 +02:00
|
|
|
|
;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
2020-08-18 15:13:12 +02:00
|
|
|
|
;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
|
2017-01-12 14:56:52 +01:00
|
|
|
|
|
|
|
|
|
;; 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:
|
|
|
|
|
|
2017-01-13 18:47:15 +01:00
|
|
|
|
;; This scripts indents the given file or package definition in the specified
|
|
|
|
|
;; file using Emacs.
|
2017-01-12 14:56:52 +01:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2017-04-28 15:07:33 +02:00
|
|
|
|
;; Load Scheme indentation rules from ".dir-locals.el".
|
2017-01-12 14:56:52 +01:00
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(scheme-mode)
|
2017-04-28 15:07:33 +02:00
|
|
|
|
(let ((default-directory (file-name-as-directory load-file-name))
|
2017-01-12 14:56:52 +01:00
|
|
|
|
(enable-local-variables :all))
|
|
|
|
|
(hack-dir-local-variables)
|
|
|
|
|
(hack-local-variables-apply)))
|
|
|
|
|
|
2017-01-20 14:43:43 +01:00
|
|
|
|
;; Add indentation info for Scheme constructs that are not Guix-specific.
|
|
|
|
|
;; This is normally provided by Geiser but this file is for people who may not
|
|
|
|
|
;; be running Geiser, so we just copy it here (from 'geiser-syntax.el').
|
|
|
|
|
(defmacro guix-syntax--scheme-indent (&rest pairs)
|
|
|
|
|
`(progn ,@(mapcar (lambda (p)
|
|
|
|
|
`(put ',(car p) 'scheme-indent-function ',(cadr p)))
|
|
|
|
|
pairs)))
|
|
|
|
|
|
|
|
|
|
(guix-syntax--scheme-indent
|
|
|
|
|
(and-let* 1)
|
|
|
|
|
(case-lambda 0)
|
|
|
|
|
(catch defun)
|
|
|
|
|
(class defun)
|
|
|
|
|
(dynamic-wind 0)
|
|
|
|
|
(guard 1)
|
|
|
|
|
(let*-values 1)
|
|
|
|
|
(let-values 1)
|
|
|
|
|
(let/ec 1)
|
|
|
|
|
(letrec* 1)
|
|
|
|
|
(match 1)
|
|
|
|
|
(match-lambda 0)
|
|
|
|
|
(match-lambda* 0)
|
|
|
|
|
(match-let scheme-let-indent)
|
|
|
|
|
(match-let* 1)
|
|
|
|
|
(match-letrec 1)
|
|
|
|
|
(opt-lambda 1)
|
|
|
|
|
(parameterize 1)
|
|
|
|
|
(parameterize* 1)
|
|
|
|
|
(receive 2)
|
|
|
|
|
(require-extension 0)
|
|
|
|
|
(syntax-case 2)
|
|
|
|
|
(test-approximate 1)
|
|
|
|
|
(test-assert 1)
|
|
|
|
|
(test-eq 1)
|
|
|
|
|
(test-equal 1)
|
|
|
|
|
(test-eqv 1)
|
|
|
|
|
(test-group-with-cleanup 1)
|
|
|
|
|
(test-runner-on-bad-count! 1)
|
|
|
|
|
(test-runner-on-bad-end-name! 1)
|
|
|
|
|
(test-runner-on-final! 1)
|
|
|
|
|
(test-runner-on-group-begin! 1)
|
|
|
|
|
(test-runner-on-group-end! 1)
|
|
|
|
|
(test-runner-on-test-begin! 1)
|
|
|
|
|
(test-runner-on-test-end! 1)
|
|
|
|
|
(test-with-runner 1)
|
|
|
|
|
(unless 1)
|
|
|
|
|
(when 1)
|
|
|
|
|
(while 1)
|
|
|
|
|
(with-exception-handler 1)
|
|
|
|
|
(with-syntax 1))
|
|
|
|
|
|
|
|
|
|
|
2020-03-31 06:12:01 +02:00
|
|
|
|
(defun main ()
|
|
|
|
|
(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))
|
2020-08-18 15:13:12 +02:00
|
|
|
|
(if (re-search-forward (concat "^(define\\(\\|-public\\) +"
|
2020-03-31 06:12:01 +02:00
|
|
|
|
package-name)
|
|
|
|
|
nil t)
|
|
|
|
|
(let ((indent-tabs-mode nil))
|
|
|
|
|
(beginning-of-defun)
|
2021-06-02 14:26:28 +02:00
|
|
|
|
(mark-sexp)
|
|
|
|
|
(untabify (point) (mark))
|
2020-03-31 06:12:01 +02:00
|
|
|
|
(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))
|
2021-06-02 14:26:28 +02:00
|
|
|
|
(untabify (point-min) (point-max))
|
2020-03-31 06:12:01 +02:00
|
|
|
|
(indent-region (point-min) (point-max))
|
|
|
|
|
(save-buffer)
|
|
|
|
|
(message "Done!")))
|
|
|
|
|
(x
|
|
|
|
|
(error "Usage: indent-code.el FILE [PACKAGE]"))))
|
2017-01-12 14:56:52 +01:00
|
|
|
|
|
2017-01-13 18:47:15 +01:00
|
|
|
|
;;; indent-code.el ends here
|