1;; @author Couchbase <info@couchbase.com>
2;; @copyright 2015 Couchbase, Inc.
3;;
4;; Licensed under the Apache License, Version 2.0 (the "License");
5;; you may not use this file except in compliance with the License.
6;; You may obtain a copy of the License at
7;;
8;;      http://www.apache.org/licenses/LICENSE-2.0
9;;
10;; Unless required by applicable law or agreed to in writing, software
11;; distributed under the License is distributed on an "AS IS" BASIS,
12;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13;; See the License for the specific language governing permissions and
14;; limitations under the License.
15(setq-default indent-tabs-mode nil)
16
17(defvar erlang-dirs '("/usr/local/lib/erlang" "/usr/lib/erlang"))
18(defvar erlang-root-dir nil)
19
20(dolist (dir erlang-dirs)
21  (when (file-accessible-directory-p dir)
22    (setq erlang-root-dir dir)))
23
24(unless erlang-root-dir
25  (error "Couldn't find erlang installation. Searched in %s" erlang-dirs))
26
27(defconst erlang-lib-dir
28  (concat (file-name-as-directory erlang-root-dir) "lib"))
29(defconst erlang-tools-dir
30  (and (file-accessible-directory-p erlang-lib-dir)
31       (concat (file-name-as-directory erlang-lib-dir)
32               (car (directory-files erlang-lib-dir nil "^tools-.*")))))
33(defconst erlang-emacs-dir
34  (concat (file-name-as-directory erlang-tools-dir) "emacs"))
35
36(defun do-indent (path)
37  (princ (format "Indending %s\n" path))
38
39  (find-file path)
40  (erlang-mode)
41  (indent-region (point-min) (point-max))
42  (save-buffer)
43  (kill-buffer))
44
45(defun get-paths (l)
46  (cdr (cdr (cdr l))))
47
48(when (file-accessible-directory-p erlang-emacs-dir)
49  (add-to-list 'load-path erlang-emacs-dir)
50  (require 'erlang)
51  (dolist (path (get-paths command-line-args))
52    (do-indent path)))
53