2017-01-12 14:56:52 +01:00
|
|
|
#!@EMACS@ --script
|
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>
|
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:
|
|
|
|
|
|
|
|
;; 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)
|
2017-01-13 18:47:15 +01:00
|
|
|
;; Indent the definition of PACKAGE-NAME in FILE-NAME.
|
2017-01-12 14:56:52 +01:00
|
|
|
(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)))
|
2017-01-13 18:47:15 +01:00
|
|
|
(`(,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!")))
|
2017-01-12 14:56:52 +01:00
|
|
|
(x
|
2017-01-13 18:47:15 +01:00
|
|
|
(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
|