initial import into CVS
[elisp/initz.git] / lisp / initz-util.el
1 ;;; initz-util.el --- Utilities.
2
3 ;; Copyright (C) 2002 OHASHI Akira <bg66@koka-in.org>
4
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: startup, init
7
8 ;; This file is part of Initz.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25
26 ;;; Commentary:
27 ;;
28
29 ;;; Code:
30
31 (require 'initz-vars)
32 (require 'initz-globals)
33 (eval-when-compile (require 'cl))
34
35 (defun initz-add-to-load-list (modules)
36   "Add MODULES to `initz-load-list-internal'."
37   (let ((modules (if (listp modules) modules (list modules))))
38     (mapc
39      (function (lambda (module)
40                  (add-to-list 'initz-load-list-internal module)))
41      modules)))
42
43 (defun initz-add-to-ignore-list (modules)
44   "Add MODULES to `initz-ignore-list-internal'."
45   (let ((modules (if (listp modules) modules (list modules))))
46     (mapc
47      (function (lambda (module)
48                  (add-to-list 'initz-ignore-list-internal module)))
49      modules)))
50
51 (defun initz-remove-from-load-list (modules)
52   "Remove MODULES from `initz-load-list-internal'."
53   (let ((modules (if (listp modules) modules (list modules))))
54     (mapc
55      (function (lambda (module)
56             (setq initz-load-list-internal
57                   (delete module initz-load-list-internal))))
58      modules)))
59
60 (defun initz-remove-from-ignore-list (modules)
61   "Remove MODULES from `initz-ignore-list-internal'."
62   (let ((modules (if (listp modules) modules (list modules))))
63     (mapc
64      (function (lambda (module)
65             (setq initz-ignore-list-internal
66                   (delete module initz-ignore-list-internal))))
67      modules)))
68
69 (defun initz-set-load-list (modules)
70   "Set MODULES to `initz-load-list-internal'."
71   (let ((modules (if (listp modules) modules (list modules))))
72     (setq initz-load-list-internal modules)))
73
74 (defun initz-set-ignore-list (modules)
75   "Set MODULES to `initz-ignore-list-internal'."
76   (let ((modules (if (listp modules) modules (list modules))))
77     (setq initz-ignore-list-internal modules)))
78
79 (defun initz-add-to-load-path (paths)
80   "Add PATHS to `load-path' recursively."
81   (let ((paths (if (listp paths) paths (list paths))))
82     (mapc
83      (function (lambda (path)
84                  (when (file-directory-p path)
85                    (add-to-list 'load-path path)
86                    (initz-add-to-load-path
87                     ;; Without `.' and `..'.
88                     (directory-files
89                      path t "^\\([^.].+\\|\\.[^.].+\\|\\.\\..+\\)$")))))
90      paths)))
91
92 (defun initz-features ()
93   "Return the Initz features."
94   (delq nil
95         (mapcar
96          (function (lambda (feature)
97                      (let ((initz-feature (initz-get-module-name
98                                            (concat (symbol-name feature)
99                                                    ".el"))))
100                        (unless (string= initz-feature initz-null-string)
101                          (intern initz-feature)))))
102          features)))
103
104 ;;; Internal functions.
105 (defun initz-get-base-name (init-file)
106   "Return base name of the INIT-FILE."
107   (file-name-sans-extension
108    (file-name-nondirectory init-file)))
109
110 (defun initz-get-module-name (init-file)
111   "Return module name of the INIT-FILE."
112   (let ((base-name (initz-get-base-name init-file)))
113     (cond
114      ((string= base-name initz-prefix) initz-prefix)
115      ((string-match (concat
116                      (regexp-quote (concat initz-prefix
117                                            initz-separator-string))
118                      "\\(" initz-module-regexp "\\)")
119                     base-name)
120       (match-string 1 base-name))
121      (t initz-null-string))))
122
123 (provide 'initz-util)
124
125 ;;; initz-util.el ends here