1 ;; emod-utils.el --- Lisp utils for emodules -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2008 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: SXEmacs Development Team <sxemacs-devel@sxemacs.org>
7 ;; Created: <2008-05-01>
8 ;; Homepage: https://www.sxemacs.org/
9 ;; Keywords: util, module, emodule, dumped
11 ;; This file is part of SXEmacs.
13 ;; Redistribution and use in source and binary forms, with or without
14 ;; modification, are permitted provided that the following conditions
17 ;; 1. Redistributions of source code must retain the above copyright
18 ;; notice, this list of conditions and the following disclaimer.
20 ;; 2. Redistributions in binary form must reproduce the above copyright
21 ;; notice, this list of conditions and the following disclaimer in the
22 ;; documentation and/or other materials provided with the distribution.
24 ;; 3. Neither the name of the author nor the names of any contributors
25 ;; may be used to endorse or promote products derived from this
26 ;; software without specific prior written permission.
28 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
29 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ;; Here are a number of utils for interacting with emodules, such
43 ;; as finding them, loading them. That sort of thing.
45 ;; This file is dumped with SXEmacs.
52 (defvar emodule-completions nil
53 "List of emodules for use in completion with `load-module'.")
55 (defvar load-module-history nil
56 "History for `load-module'.")
58 (defun emodule-completions (&optional path)
59 "Return a list of emodules.
61 It searches through `module-load-path' by default, or PATH if that
62 optional argument is set.
64 PATH can be either a list of path strings, or it can be a colon
65 delimited path string."
66 (let ((dirs (or (if (stringp path)
67 (split-string-by-char path ?:)
72 (replace-in-string e "\\." ""))
76 :result-type #'concat module-extensions))
79 (let ((files (directory-files-recur (car dirs) nil types 'list t 0)))
80 (when (and files (> (length files) 0))
84 #'file-name-sans-extension files
85 :result-type #'list))))
86 (setq dirs (cdr dirs))))
87 (remove-duplicates (remove nil completions) :test #'string-equal)))
89 (defun locate-module (emod)
90 "Similar to `locate-library', but for emodules."
92 (list (completing-read "Locate Emodule: "
93 (mapfam #'list (or emodule-completions
94 (emodule-completions)))
95 nil nil nil load-module-history)))
96 (unless emodule-completions
97 (setq emodule-completions (emodule-completions)))
98 (let* ((emod (file-name-sans-extension emod))
99 (location (locate-file emod module-load-path
102 (message "%s is: %s" emod location)
105 (defun load-module (emod)
106 "Similar to `load-library', but for emodules."
108 (list (completing-read "Load emodule: "
109 (mapfam #'list (or emodule-completions
110 (emodule-completions)))
111 nil nil nil load-module-history)))
112 (unless emodule-completions
113 (setq emodule-completions (emodule-completions)))
114 (if (string-equal emod "")
115 (error 'invalid-argument emod)
116 (and-fboundp #'load-module-file
118 (or (locate-module emod)
121 (defun list-modules ()
122 "Return a list of loaded emodules, display in echo area when interactive."
124 (and-fboundp #'list-loaded-modules
125 (let ((emods (list-loaded-modules)))
127 (message "Loaded emodules: %s"
128 (mapfam nil emods :separator " " :result-type #'concat))
131 (provide 'emod-utils)
132 ;;; emod-utils.el ends here